From dceb64dbbf234a51a731fb350ff54b6226a57183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Fri, 9 Aug 2019 20:07:39 +0200 Subject: [Code] Added some changes to AssertCanDeleteDirectory. + renamed parameter + docs + added some test cases --- main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs | 5 +++-- .../MonoDevelop.Projects/FileServiceTests.cs | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'main') 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 /// /// The path to be checked. /// optional parameter that specifies a required parent of the path. + /// if true, requiredParentDirectory can be deleted. /// Is thrown when the directory can't be safely deleted. - 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); } } } -- cgit v1.2.3