Ignore:
Timestamp:
1/4/2011 2:42:32 AM (4 years ago)
Author:
lowjoel
Message:

Prevent recursive folder definitions when users use Secure Move to move a folder to be a subfolder of the source directory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser/Eraser.Util/Shell.cs

    r2112 r2282  
    142142 
    143143        /// <summary> 
     144        /// Verifies if the path given is rooted at the given absolute path. 
     145        /// </summary> 
     146        /// <param name="absolutePath">The root path.</param> 
     147        /// <param name="path">The path to verify.</param> 
     148        /// <returns>True if the path provided is a subfolder/sub-file of the provided root path.</returns> 
     149        public static bool IsRootedAt(FileSystemInfo absolutePath, string path) 
     150        { 
     151            //Convert the path in question to an absolute path 
     152            if (!Path.IsPathRooted(path)) 
     153                path = Path.GetFullPath(path); 
     154 
     155            //Split the directory path to its component folders 
     156            string[] absoluteDirectories = absolutePath.FullName.Split( 
     157                Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); 
     158            string[] relativeDirectories = path.Split( 
     159                Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); 
     160 
     161            //Compare element by element; if the absolute path compares till the end, the 
     162            //provided path is a subdirectory 
     163            for (int i = 0; i < absoluteDirectories.Length; ++i) 
     164                if (absoluteDirectories[i] != relativeDirectories[i]) 
     165                    return false; 
     166 
     167            return true; 
     168        } 
     169 
     170        /// <summary> 
    144171        /// A List of known folder IDs in the shell namespace. 
    145172        /// </summary> 
Note: See TracChangeset for help on using the changeset viewer.