Changeset 2653


Ignore:
Timestamp:
5/24/2012 2:57:09 AM (3 years ago)
Author:
lowjoel
Message:

When enumerating folders for erasure, it is possible that in the time we got the listings to the time we got the sizes or when we are trying to find the ADSes the file could have been deleted. In those situations, we'd get a FileNotFoundException? or DirectoryNotFoundException?. Handle those and move on.

Location:
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets
Files:
3 edited

Legend:

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

    r2646 r2653  
    224224            //Retrieve the list of files to erase. 
    225225            List<StreamInfo> paths = GetPaths(); 
    226             long dataTotal = paths.Sum(x => x.Length); 
     226            long dataTotal = paths.Sum(delegate(StreamInfo x) { 
     227                try 
     228                { 
     229                    return x.Length; 
     230                } 
     231                catch (DirectoryNotFoundException) 
     232                { 
     233                    return 0; 
     234                } 
     235                catch (FileNotFoundException) 
     236                { 
     237                    return 0; 
     238                } 
     239            }); 
    227240 
    228241            //Set the event's current target status. 
  • trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FolderErasureTarget.cs

    r2606 r2653  
    147147                    continue; 
    148148 
    149                 //Add the size of the file and its alternate data streams 
    150                 result.AddRange(GetPathADSes(file)); 
    151  
    152                 //And the file itself 
    153                 result.Add(new StreamInfo(file.FullName)); 
     149                try 
     150                { 
     151                    //Add the size of the file and its alternate data streams 
     152                    result.AddRange(GetPathADSes(file)); 
     153 
     154                    //And the file itself 
     155                    result.Add(new StreamInfo(file.FullName)); 
     156                } 
     157                catch (FileNotFoundException) 
     158                { 
     159                    Logger.Log(S._("The file {0} was not erased because it was deleted " + 
     160                        "before it could be erased.", file.FullName), LogLevel.Information); 
     161                } 
     162                catch (DirectoryNotFoundException) 
     163                { 
     164                    Logger.Log(S._("The file {0} was not erased because the containing " + 
     165                        "directory was deleted before it could be erased", file.FullName), 
     166                        LogLevel.Information); 
     167                } 
    154168            } 
    155169 
  • trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/RecycleBinErasureTarget.cs

    r2606 r2653  
    141141                foreach (FileInfo file in GetFiles(directory)) 
    142142                { 
    143                     //Add the ADSes 
    144                     result.AddRange(GetPathADSes(file)); 
     143                    try 
     144                    { 
     145                        //Add the ADSes 
     146                        result.AddRange(GetPathADSes(file)); 
    145147 
    146                     //Then the file itself 
    147                     result.Add(new StreamInfo(file.FullName)); 
     148                        //Then the file itself 
     149                        result.Add(new StreamInfo(file.FullName)); 
     150                    } 
     151                    catch (FileNotFoundException) 
     152                    { 
     153                        Logger.Log(S._("The file {0} was not erased because it was deleted " + 
     154                            "before it could be erased.", file.FullName), LogLevel.Information); 
     155                    } 
     156                    catch (DirectoryNotFoundException) 
     157                    { 
     158                        Logger.Log(S._("The file {0} was not erased because the containing " + 
     159                            "directory was deleted before it could be erased", file.FullName), 
     160                            LogLevel.Information); 
     161                    } 
    148162                } 
    149163 
Note: See TracChangeset for help on using the changeset viewer.