Skip to content

Commit

Permalink
Add handling of PermissionError on Windows for an existing directory
Browse files Browse the repository at this point in the history
That is my guess for what is happening in

    ________________________ test_DownloadDirectory_basic _________________________
    dandi\tests\test_download.py:1048: in test_DownloadDirectory_basic
        with DownloadDirectory(tmp_path, digests={}) as dl:
    dandi\download.py:889: in __exit__
        self.writefile.replace(self.filepath)
    C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\pathlib.py:1247: in replace
        self._accessor.replace(self, target)
    E   PermissionError: [WinError 5] Access is denied: 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\pytest-of-runneradmin\\pytest-0\\test_DownloadDirectory_basic0.dandidownload\\file' -> 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\pytest-of-runneradmin\\pytest-0\\test_DownloadDirectory_basic0'
  • Loading branch information
yarikoptic committed Sep 13, 2024
1 parent 6c0bbca commit d7f0f6e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dandi/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pathlib import Path
import random
from shutil import rmtree
import sys
from threading import Lock
import time
from types import TracebackType
Expand Down Expand Up @@ -887,7 +888,12 @@ def __exit__(
if exc_type is None:
try:
self.writefile.replace(self.filepath)
except IsADirectoryError:
except (IsADirectoryError, PermissionError) as exc:
if isinstance(exc, PermissionError):
if not (

Check warning on line 893 in dandi/download.py

View check run for this annotation

Codecov / codecov/patch

dandi/download.py#L893

Added line #L893 was not covered by tests
sys.platform.startswith("win") and self.filepath.is_dir()
):
raise

Check warning on line 896 in dandi/download.py

View check run for this annotation

Codecov / codecov/patch

dandi/download.py#L896

Added line #L896 was not covered by tests
lgr.debug(
"Destination path %s is a directory; removing it and retrying",
self.filepath,
Expand Down

0 comments on commit d7f0f6e

Please sign in to comment.