diff options
author | Mike Krüger <mikkrg@microsoft.com> | 2019-08-09 21:07:39 +0300 |
---|---|---|
committer | Mike Krüger <mikkrg@microsoft.com> | 2019-08-15 10:06:07 +0300 |
commit | dceb64dbbf234a51a731fb350ff54b6226a57183 (patch) | |
tree | 3db13145a68e465af75ac1be84b9b4e09b4b36e8 /main | |
parent | 6c6d3534cf36277f9ecd156dcd55e89211e01763 (diff) |
[Code] Added some changes to AssertCanDeleteDirectory.
+ renamed parameter + docs
+ added some test cases
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);
} }
}
|