Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fs/error_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __exit__(
_errno = exc_value.errno
fserror = os_errors.get(_errno, errors.OperationFailed)
if _errno == errno.EACCES and sys.platform == "win32":
if getattr(exc_value, "args", None) == 32: # pragma: no cover
if getattr(exc_value, "winerror", None) == 32: # pragma: no cover
fserror = errors.ResourceLocked
reraise(fserror, fserror(self._path, exc=exc_value), traceback)

Expand Down
15 changes: 15 additions & 0 deletions tests/test_error_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import errno
import unittest
from unittest import mock

import fs.errors
from fs import error_tools
from fs.error_tools import convert_os_errors


Expand All @@ -23,3 +25,16 @@ def test_convert_enametoolong(self):
raise exception
self.assertEqual(ctx.exception.exc, exception)
self.assertEqual(ctx.exception.path, "/tmp/test")

def test_convert_eacces_sharing_violation_on_windows(self):
# On Windows, EACCES with winerror 32 (ERROR_SHARING_VIOLATION)
# means the file is locked by another process, not a plain
# permissions problem.
exception = OSError(errno.EACCES, "file in use")
exception.winerror = 32
with mock.patch.object(error_tools.sys, "platform", "win32"):
with self.assertRaises(fs.errors.ResourceLocked) as ctx:
with convert_os_errors("open", "/tmp/test"):
raise exception
self.assertEqual(ctx.exception.exc, exception)
self.assertEqual(ctx.exception.path, "/tmp/test")