Changeset 1467 for trunk/eraser6


Ignore:
Timestamp:
1/5/2010 10:39:29 AM (5 years ago)
Author:
lowjoel
Message:

When deleting files or folders, always limit the number of tries to erase the file, and only retry if it is a sharing violation; all other errors, rethrow.

Location:
trunk/eraser6/Eraser.DefaultPlugins
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser6/Eraser.DefaultPlugins/FileSystems/Windows.cs

    r1457 r1467  
    5656                    ++i; 
    5757                } 
    58                 catch (IOException) 
    59                 { 
    60                     Thread.Sleep(100); 
    61  
    62                     //If after FilenameEraseTries the file is still locked, some program is 
    63                     //definitely using the file; throw an exception. 
    64                     if (tries > FileNameEraseTries) 
    65                         throw new IOException(S._("The file {0} is currently in use and " + 
    66                             "cannot be removed.", info.FullName)); 
     58                catch (IOException e) 
     59                { 
     60                    switch (System.Runtime.InteropServices.Marshal.GetLastWin32Error()) 
     61                    { 
     62                        case 5: //ERROR_ACCESS_DENIED 
     63                            throw new UnauthorizedAccessException(S._("The file {0} could not " + 
     64                                "be erased because the file's permissions prevent access to the file.", 
     65                                info.FullName)); 
     66 
     67                        case 32: //ERROR_SHARING_VIOLATION 
     68                            //Let the process locking the file release the lock 
     69                            Thread.Sleep(100); 
     70 
     71                            //If after FilenameEraseTries the file is still locked, some program is 
     72                            //definitely using the file; throw an exception. 
     73                            if (tries > FileNameEraseTries) 
     74                                throw new IOException(S._("The file {0} is currently in use and " + 
     75                                    "cannot be removed.", info.FullName), e); 
     76                        default: 
     77                            throw; 
     78                    } 
    6779                } 
    6880            } 
     
    8294                    break; 
    8395                } 
    84                 catch (IOException) 
    85                 { 
    86                     if (i > FileNameEraseTries) 
    87                         throw new IOException(S._("The file {0} is currently in use and " + 
    88                             "cannot be removed.", info.FullName)); 
    89                     Thread.Sleep(100); 
     96                catch (IOException e) 
     97                { 
     98                    switch (System.Runtime.InteropServices.Marshal.GetLastWin32Error()) 
     99                    { 
     100                        case 5: //ERROR_ACCESS_DENIED 
     101                            throw new UnauthorizedAccessException(S._("The file {0} could not " + 
     102                                "be erased because the file's permissions prevent access to the file.", 
     103                                info.FullName), e); 
     104 
     105                        case 32: //ERROR_SHARING_VIOLATION 
     106                            //Let the process locking the file release the lock 
     107                            Thread.Sleep(100); 
     108 
     109                            //If after FilenameEraseTries the file is still locked, some program is 
     110                            //definitely using the file; throw an exception. 
     111                            if (i > FileNameEraseTries) 
     112                                throw new IOException(S._("The file {0} is currently in use and " + 
     113                                    "cannot be removed.", info.FullName), e); 
     114                        default: 
     115                            throw; 
     116                    } 
    90117                } 
    91118        } 
     
    104131 
    105132            //Then clean up this folder. 
    106             for (int i = 0; i < FileNameErasePasses; ++i) 
     133            for (int i = 0, tries = 0; i < FileNameErasePasses; ++tries) 
    107134            { 
    108135                //Rename the folder. 
     
    114141                { 
    115142                    info.MoveTo(newPath); 
    116                 } 
    117                 catch (IOException) 
    118                 { 
    119                     Thread.Sleep(100); 
    120                     --i; 
     143                    ++i; 
     144                } 
     145                catch (IOException e) 
     146                { 
     147                    switch (System.Runtime.InteropServices.Marshal.GetLastWin32Error()) 
     148                    { 
     149                        case 5: //ERROR_ACCESS_DENIED 
     150                            throw new UnauthorizedAccessException(S._("The file {0} could not " + 
     151                                "be erased because the file's permissions prevent access to the file.", 
     152                                info.FullName), e); 
     153 
     154                        case 32: //ERROR_SHARING_VIOLATION 
     155                            //Let the process locking the file release the lock 
     156                            Thread.Sleep(100); 
     157 
     158                            //If after FilenameEraseTries the file is still locked, some program is 
     159                            //definitely using the file; throw an exception. 
     160                            if (tries > FileNameEraseTries) 
     161                                throw new IOException(S._("The file {0} is currently in use and " + 
     162                                    "cannot be removed.", info.FullName), e); 
     163                        default: 
     164                            throw; 
     165                    } 
    121166                } 
    122167            } 
  • trunk/eraser6/Eraser.DefaultPlugins/Strings.en.resx

    r1216 r1467  
    151151    <value>An invalid erasure method was selected.</value> 
    152152  </data> 
     153  <data name="The file {0} could not be erased because the file's permissions prevent access to the file." xml:space="preserve"> 
     154    <value>The file {0} could not be erased because the file's permissions prevent access to the file.</value> 
     155  </data> 
    153156  <data name="The file {0} is currently in use and cannot be removed." xml:space="preserve"> 
    154157    <value>The file {0} is currently in use and cannot be removed.</value> 
  • trunk/eraser6/Eraser.DefaultPlugins/Strings.it.resx

    r1346 r1467  
    151151    <value>E' stato selezionato un metodo di pulizia non valido.</value> 
    152152  </data> 
     153  <data name="The file {0} could not be erased because the file's permissions prevent access to the file." xml:space="preserve"> 
     154    <value>(Untranslated)</value> 
     155  </data> 
    153156  <data name="The file {0} is currently in use and cannot be removed." xml:space="preserve"> 
    154157    <value>Il file {0} è attualmente in uso e non può essere rimosso.</value> 
  • trunk/eraser6/Eraser.DefaultPlugins/Strings.nl.resx

    r1216 r1467  
    151151    <value>(Untranslated)</value> 
    152152  </data> 
     153  <data name="The file {0} could not be erased because the file's permissions prevent access to the file." xml:space="preserve"> 
     154    <value>(Untranslated)</value> 
     155  </data> 
    153156  <data name="The file {0} is currently in use and cannot be removed." xml:space="preserve"> 
    154157    <value>(Untranslated)</value> 
  • trunk/eraser6/Eraser.DefaultPlugins/Strings.resx

    r1268 r1467  
    151151    <value>An invalid erasure method was selected.</value> 
    152152  </data> 
     153  <data name="The file {0} could not be erased because the file's permissions prevent access to the file." xml:space="preserve"> 
     154    <value>The file {0} could not be erased because the file's permissions prevent access to the file.</value> 
     155  </data> 
    153156  <data name="The file {0} is currently in use and cannot be removed." xml:space="preserve"> 
    154157    <value>The file {0} is currently in use and cannot be removed.</value> 
Note: See TracChangeset for help on using the changeset viewer.