Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorMike Krüger <mikkrg@microsoft.com>2019-08-09 14:44:29 +0300
committerMike Krüger <mikkrg@microsoft.com>2019-08-15 10:05:22 +0300
commit419b7f56276b5906f116697742d5bddf9ad7e1d6 (patch)
treeef5ba59932e2ee57376bde9cb28caa72da5ad4ed /main
parent71ef59b2f913e1df6ec0217922af7209452f03e2 (diff)
[Core] Use CanonicalPaths in AssertCanDeleteDirectory.
Diffstat (limited to 'main')
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/Repository.cs10
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core/FilePath.cs6
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs27
3 files changed, 24 insertions, 19 deletions
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/Repository.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/Repository.cs
index e6576ae7e5..5bab230158 100644
--- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/Repository.cs
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/Repository.cs
@@ -845,9 +845,13 @@ namespace MonoDevelop.VersionControl
LoggingService.LogError ("Failed to delete directory", e);
metadata.SetFailure ();
if (!keepLocal)
- foreach (var path in localPaths) {
- FileService.AssertCanDeleteDirectory (path, RootPath);
- Directory.Delete (path, true);
+ try {
+ foreach (var path in localPaths) {
+ FileService.AssertCanDeleteDirectory (path, RootPath);
+ Directory.Delete (path, true);
+ }
+ } catch (Exception e2) {
+ LoggingService.LogInternalError (e2);
}
}
}
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FilePath.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FilePath.cs
index d4cc903875..174855dd61 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FilePath.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FilePath.cs
@@ -177,12 +177,14 @@ namespace MonoDevelop.Core
public bool IsChildPathOf (FilePath basePath)
{
bool startsWith = fileName.StartsWith (basePath.fileName, PathComparison);
- if (startsWith && basePath.fileName [basePath.fileName.Length - 1] != Path.DirectorySeparatorChar) {
+
+ if (startsWith && (basePath.fileName [basePath.fileName.Length - 1] != Path.DirectorySeparatorChar ||
+ basePath.fileName [basePath.fileName.Length - 1] != Path.AltDirectorySeparatorChar)) {
// If the last character isn't a path separator character, check whether the string we're searching in
// has more characters than the string we're looking for then check the character.
// Otherwise, if the path lengths are equal, we return false.
if (fileName.Length > basePath.fileName.Length)
- startsWith &= fileName [basePath.fileName.Length] == Path.DirectorySeparatorChar;
+ startsWith &= fileName [basePath.fileName.Length] == Path.DirectorySeparatorChar || fileName [basePath.fileName.Length] == Path.AltDirectorySeparatorChar;
else
startsWith = false;
}
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs
index 2de9baa50e..09dfa29448 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs
@@ -122,12 +122,11 @@ namespace MonoDevelop.Core
static FileService ()
{
lockedDirectories = new HashSet<FilePath> ();
- lockedDirectories.Add ("/");
foreach (var value in Enum.GetValues (typeof (Environment.SpecialFolder))) {
- var path = Environment.GetFolderPath ((Environment.SpecialFolder)value);
+ var path = (FilePath)Environment.GetFolderPath ((Environment.SpecialFolder)value);
if (string.IsNullOrEmpty (path))
continue;
- lockedDirectories.Add (path);
+ lockedDirectories.Add (path.CanonicalPath);
}
}
@@ -195,20 +194,20 @@ namespace MonoDevelop.Core
/// <exception cref="InvalidOperationException">Is thrown when the directory can't be safely deleted.</exception>
public static void AssertCanDeleteDirectory (FilePath path, string requiredParentDirectory = null)
{
- if (lockedDirectories.Contains (path.FullPath)) {
+ path = path.FullPath.CanonicalPath;
+ if (lockedDirectories.Contains (path)) {
throw new InvalidOperationException ("Can't delete directory " + path + ".");
}
+
+ foreach (var drive in Directory.GetLogicalDrives ()) {
+ if (path.Equals (((FilePath)drive).FullPath.CanonicalPath))
+ throw new InvalidOperationException ("Can't delete logical drive " + path + ".");
+ }
+
if (requiredParentDirectory != null) {
- var cur = path;
- FilePath parent = requiredParentDirectory;
- while (true) {
- if (cur.IsEmpty) {
- throw new InvalidOperationException (path + " needs to be child of " + requiredParentDirectory);
- }
- if (cur == parent)
- return;
- cur = cur.ParentDirectory;
- }
+ var parent = ((FilePath)requiredParentDirectory).FullPath.CanonicalPath;
+ if (!parent.IsChildPathOf (path))
+ throw new InvalidOperationException (path + " needs to be child of " + requiredParentDirectory);
}
}