Ignore:
Timestamp:
7/10/2010 8:36:36 AM (23 months ago)
Author:
lowjoel
Message:

Define proper behaviour when a directory reparse point (symbolic link/junction) is encountered. We should not touch the target of the reparse point, instead, just securely remove the reparse point. This also fixes a crash when a reparse point to the current directory is encountered (i.e. a folder referring to its immediate parent)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FolderErasureTarget.cs

    r2170 r2222  
    176176                0.0f, S._("Removing folders..."))); 
    177177 
    178             //Remove all subfolders which are empty. 
    179             FileSystem fsManager = ManagerLibrary.Instance.FileSystemRegistrar[ 
    180                 VolumeInfo.FromMountPoint(Path)]; 
     178            //Erase all subdirectories which are not reparse points. 
    181179            DirectoryInfo directory = new DirectoryInfo(Path); 
     180            if ((directory.Attributes & FileAttributes.ReparsePoint) == 0) 
    182181                foreach (DirectoryInfo subDir in directory.GetDirectories()) 
    183182                    EraseFolder(subDir, step); 
    184183 
     184            //Does the user want this directory to be erased if there are no more 
     185            //entries within it? 
    185186            if (DeleteIfEmpty) 
    186187            { 
     
    198199                    directory.GetFiles("*", SearchOption.AllDirectories).Length == 0) 
    199200                { 
     201                    FileSystem fsManager = ManagerLibrary.Instance.FileSystemRegistrar[ 
     202                        VolumeInfo.FromMountPoint(Path)]; 
    200203                    fsManager.DeleteFolder(directory); 
    201204                } 
     
    205208        private void EraseFolder(DirectoryInfo info, ProgressManager progress) 
    206209        { 
     210            //Skip all symbolic links and junctions as we want to retain the 
     211            //contents of those directories. 
     212            if ((info.Attributes & FileAttributes.ReparsePoint) != 0) 
     213                return; 
     214 
     215            //Iterate over each directory and erase the subdirectories. 
    207216            foreach (DirectoryInfo subDir in info.GetDirectories()) 
    208217                EraseFolder(subDir, progress); 
     218 
     219            //Public progress updates. 
    209220            OnProgressChanged(this, new ProgressChangedEventArgs(progress, 
    210221                new TaskProgressChangedEventArgs(info.FullName, 0, 0))); 
    211222 
     223            //Ensure that the current directory is empty before deleting. 
    212224            FileSystemInfo[] files = info.GetFileSystemInfos(); 
    213225            if (files.Length == 0) 
Note: See TracChangeset for help on using the changeset viewer.