Skip to content

Commit 41a54ce

Browse files
committed
try scheduling removal at reboot on win. Fall back to warning message
1 parent dd99e4b commit 41a54ce

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

conda/gateways/disk/delete.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
from ...base.context import context
1717
from ...common.compat import PY2, on_win, text_type, ensure_binary
1818

19+
if on_win:
20+
import win32file
21+
import pywintypes
22+
23+
1924
log = getLogger(__name__)
2025

2126

@@ -104,7 +109,21 @@ def move_path_to_trash(path, preclean=True):
104109
def 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,

0 commit comments

Comments
 (0)