Changeset 2656
- Timestamp:
- 5/24/2012 4:10:12 AM (12 months ago)
- Location:
- trunk/eraser/Eraser.DefaultPlugins/ErasureTargets
- Files:
-
- 5 edited
-
FileErasureTarget.cs (modified) (1 diff)
-
FileSystemObjectErasureTarget.cs (modified) (3 diffs)
-
FolderErasureTarget.cs (modified) (1 diff)
-
RecycleBinErasureTarget.cs (modified) (1 diff)
-
SecureMoveErasureTarget.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FileErasureTarget.cs
r2606 r2656 76 76 FileInfo fileInfo = new FileInfo(Path); 77 77 78 if (fileInfo.Exists)78 try 79 79 { 80 80 result.AddRange(GetPathADSes(fileInfo)); 81 81 result.Add(new StreamInfo(Path)); 82 } 83 catch (SharingViolationException) 84 { 85 Logger.Log(S._("Could not list the Alternate Data Streams for file {0} " + 86 "because the file is being used by another process. The file will not " + 87 "be erased.", fileInfo.FullName), LogLevel.Error); 88 } 89 catch (FileNotFoundException) 90 { 91 } 92 catch (DirectoryNotFoundException) 93 { 82 94 } 83 95 -
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FileSystemObjectErasureTarget.cs
r2653 r2656 142 142 143 143 /// <summary> 144 /// Adds ADSes of the given file to the list, forcing the open handles to the 145 /// files closed if necessary. 146 /// </summary> 147 /// <param name="file">The file to look for ADSes</param> 144 /// Returns the ADSes of the given file, forcing open handles to the files closed 145 /// if necessary. 146 /// </summary> 147 /// <param name="file">The file to look for ADSes.</param> 148 /// <exception cref="SharingViolationException">Thrown when the file cannot be unlocked 149 /// and enumerated for ADSes.</exception> 148 150 protected static StreamInfo[] GetPathADSes(FileInfo file) 149 151 { 152 int attempts = 1; 153 return GetPathADSes(file, ref attempts); 154 } 155 156 /// <summary> 157 /// Returns the ADSes of the given file, forcing open handles to the files closed 158 /// if necessary. 159 /// </summary> 160 /// <param name="file">The file to look for ADSes.</param> 161 /// <param name="attempts">The number of tries to close open handles. Abort after a 162 /// large number of tries (currently 10 attempts)</param> 163 /// <returns>The list of ADSes the file contains.</returns> 164 private static StreamInfo[] GetPathADSes(FileInfo file, ref int attempts) 165 { 150 166 try 151 167 { … … 154 170 catch (FileNotFoundException) 155 171 { 172 return new StreamInfo[0]; 156 173 } 157 174 catch (SharingViolationException) … … 161 178 throw; 162 179 163 StringBuilder processStr = new StringBuilder(); 164 foreach (OpenHandle handle in OpenHandle.Close(file.FullName)) 165 { 166 try 167 { 168 processStr.AppendFormat( 169 System.Globalization.CultureInfo.InvariantCulture, 170 "{0}, ", handle.Process.MainModule.FileName); 171 } 172 catch (System.ComponentModel.Win32Exception) 173 { 174 processStr.AppendFormat( 175 System.Globalization.CultureInfo.InvariantCulture, 176 "Process ID {0}, ", handle.Process.Id); 177 } 178 } 179 180 if (processStr.Length == 0) 181 return GetPathADSes(file); 180 //Retry closing the file 10 times. If we can't do that, we should abort 181 //since we may not be able to get the process information of processes 182 //running with higher privileges. 183 if (OpenHandle.Close(file.FullName).Count == 0 && attempts < 10) 184 return GetPathADSes(file, ref attempts); 182 185 else 183 186 throw; -
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/FolderErasureTarget.cs
r2654 r2656 166 166 LogLevel.Information); 167 167 } 168 catch (SharingViolationException) 169 { 170 Logger.Log(S._("Could not list the Alternate Data Streams for file {0} " + 171 "because the file is being used by another process. The file will not " + 172 "be erased.", file.FullName), LogLevel.Error); 173 } 168 174 } 169 175 -
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/RecycleBinErasureTarget.cs
r2653 r2656 160 160 LogLevel.Information); 161 161 } 162 catch (SharingViolationException) 163 { 164 Logger.Log(S._("Could not list the Alternate Data Streams for file {0} " + 165 "because the file is being used by another process. The file will not " + 166 "be erased.", fileInfo.FullName), LogLevel.Error); 167 } 162 168 } 163 169 -
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/SecureMoveErasureTarget.cs
r2606 r2656 123 123 foreach (FileInfo info in files) 124 124 { 125 //Add the alternate data streams 126 result.AddRange(GetPathADSes(info)); 127 128 //And the file itself 129 result.Add(new StreamInfo(info.FullName)); 125 try 126 { 127 //Add the alternate data streams 128 result.AddRange(GetPathADSes(info)); 129 130 //And the file itself 131 result.Add(new StreamInfo(info.FullName)); 132 } 133 catch (SharingViolationException) 134 { 135 Logger.Log(S._("Could not list the Alternate Data Streams for file {0} " + 136 "because the file is being used by another process. The file will not " + 137 "be erased.", info.FullName), LogLevel.Error); 138 } 139 catch (FileNotFoundException) 140 { 141 } 142 catch (DirectoryNotFoundException) 143 { 144 } 130 145 } 131 146
Note: See TracChangeset
for help on using the changeset viewer.
