diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs | 5 | ||||
-rw-r--r-- | main/tests/MonoDevelop.Core.Tests/MonoDevelop.Projects/FileServiceTests.cs | 7 |
2 files changed, 8 insertions, 4 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs index 79b0ed3c5a..d2d1dee90b 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs @@ -191,8 +191,9 @@ namespace MonoDevelop.Core /// </summary> /// <param name="path">The path to be checked.</param> /// <param name="requiredParentDirectory">optional parameter that specifies a required parent of the path.</param> + /// <param name="includingParent">if true, requiredParentDirectory can be deleted.</param> /// <exception cref="InvalidOperationException">Is thrown when the directory can't be safely deleted.</exception> - public static void AssertCanDeleteDirectory (FilePath path, string requiredParentDirectory = null, bool canDeleteParent = true) + public static void AssertCanDeleteDirectory (FilePath path, string requiredParentDirectory = null, bool includingParent = true) { path = path.FullPath.CanonicalPath; if (lockedDirectories.Contains (path)) { @@ -206,7 +207,7 @@ namespace MonoDevelop.Core if (requiredParentDirectory != null) { var parent = ((FilePath)requiredParentDirectory).FullPath.CanonicalPath; - if (!canDeleteParent && parent == path) + if (!includingParent && parent == path) throw new InvalidOperationException ("Can't delete parent path" + path); if (!path.IsChildPathOf (parent) && parent != path) throw new InvalidOperationException (path + " needs to be child of " + requiredParentDirectory); diff --git a/main/tests/MonoDevelop.Core.Tests/MonoDevelop.Projects/FileServiceTests.cs b/main/tests/MonoDevelop.Core.Tests/MonoDevelop.Projects/FileServiceTests.cs index 5d679f7e4b..4235b3c2e7 100644 --- a/main/tests/MonoDevelop.Core.Tests/MonoDevelop.Projects/FileServiceTests.cs +++ b/main/tests/MonoDevelop.Core.Tests/MonoDevelop.Projects/FileServiceTests.cs @@ -194,13 +194,16 @@ namespace MonoDevelop.Projects public void CantDeleteSystemFolders ()
{
FileService.AssertCanDeleteDirectory (Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData));
+ FileService.AssertCanDeleteDirectory (Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments));
+ FileService.AssertCanDeleteDirectory (Environment.GetFolderPath (Environment.SpecialFolder.UserProfile));
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
- public void CantDeleteLogicalDrive ()
+ public void CantDeleteRoot ()
{
- FileService.AssertCanDeleteDirectory (Directory.GetLogicalDrives () [0]);
+ string root = Platform.IsWindows ? "C:" : "/";
+ FileService.AssertCanDeleteDirectory (root);
} }
}
|