PCFilename.st
branchjv
changeset 18107 d46c13a0795b
parent 18077 5844a3bcdd52
parent 15822 3fc626394707
child 18120 e3a375d5f6a8
--- a/PCFilename.st	Wed Nov 20 15:12:13 2013 +0000
+++ b/PCFilename.st	Mon Nov 25 10:37:44 2013 +0000
@@ -362,15 +362,35 @@
 renameTo:newName
     "rename the file - the argument must be convertable to a String.
      Raise an error if not successful.
-     Redefined to delete any existing target-file first."
+     Redefined to delete any existing target-file first.
+     Also take care of possible locks by antivirus scanners, that go away after some time."
+
+    |retryCtr newFilename|
 
-    newName asFilename exists ifTrue:[
-        (self pathName sameAs:newName asFilename pathName) ifFalse:[
-            newName asFilename delete
+    newFilename := newName asFilename.
+    newFilename exists ifTrue:[
+        (self pathName sameAs:newFilename pathName) ifFalse:[
+            newFilename delete
         ].
     ].
 
-    ^ super renameTo:newName
+    "try 5 times if file has just been written to and is locked by a virus scanner"        
+    retryCtr := 5.
+    OperatingSystem accessDeniedErrorSignal handle:[:ex|
+        retryCtr := retryCtr - 1.
+        retryCtr > 0 ifTrue:[
+            ('stx: Error cought while renaming %1 to %2 - maybe temporary locked by virus scanner, still trying: %3'
+                                bindWith:self pathName
+                                with:newFilename pathName
+                                with:ex description) infoPrintCR.
+        ] ifFalse:[
+            ex reject 
+        ].
+        Delay waitForMilliseconds:200.
+        ex restart.
+    ] do:[
+        ^ super renameTo:newName
+    ].
 
     "
      '\tmp\foo' asFilename renameTo:'\tmp\bar'
@@ -887,14 +907,14 @@
 !PCFilename class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/PCFilename.st,v 1.60 2013-07-16 17:51:30 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/PCFilename.st,v 1.61 2013-11-21 15:03:39 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/PCFilename.st,v 1.60 2013-07-16 17:51:30 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/PCFilename.st,v 1.61 2013-11-21 15:03:39 stefan Exp $'
 !
 
 version_SVN
-    ^ '$Id: PCFilename.st,v 1.60 2013-07-16 17:51:30 cg Exp $'
+    ^ '$Id: PCFilename.st,v 1.61 2013-11-21 15:03:39 stefan Exp $'
 ! !