File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 1616from ...base .context import context
1717from ...common .compat import PY2 , on_win , text_type , ensure_binary
1818
19+ if on_win :
20+ import win32file
21+ import pywintypes
22+
23+
1924log = getLogger (__name__ )
2025
2126
@@ -104,7 +109,21 @@ def move_path_to_trash(path, preclean=True):
104109def backoff_unlink (file_or_symlink_path , max_tries = MAX_TRIES ):
105110 def _unlink (path ):
106111 make_writable (path )
107- unlink (path )
112+ try :
113+ unlink (path )
114+ except (IOError , OSError ) as e :
115+ if on_win and e .errno == 13 :
116+ try :
117+ win32file .MoveFileEx (file_or_symlink_path , None ,
118+ win32file .MOVEFILE_DELAY_UNTIL_REBOOT )
119+ log .info ("Windows thinks file %s is in use. We have scheduled it for "
120+ "removal at next reboot." % file_or_symlink_path )
121+ except pywintypes .error :
122+ log .info ("Windows thinks file %s is in use. We can't schedule it for removal"
123+ " because this is not an admin prompt (thanks Windows.)" %
124+ file_or_symlink_path )
125+ else :
126+ raise
108127
109128 try :
110129 exp_backoff_fn (lambda f : lexists (f ) and _unlink (f ), file_or_symlink_path ,
You can’t perform that action at this time.
0 commit comments