Skip to content

Commit fbf6c98

Browse files
author
Diego Argueta
committed
Fix #484
1 parent 12cd2f4 commit fbf6c98

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2424

2525
- Fixed performance bugs in `fs.copy.copy_dir_if_newer`. Test cases were adapted to catch those bugs in the future.
2626
- Fixed precision bug for timestamps in `fs.OSFS.setinfo`.
27+
- Fixed `ResourceLocked` error translation on Windows [#484](https://github.com/PyFilesystem/pyfilesystem2/issues/484).
2728

2829

2930
## [2.4.13] - 2021-03-27

fs/error_tools.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def __exit__(
8484
_errno = exc_value.errno
8585
fserror = os_errors.get(_errno, errors.OperationFailed)
8686
if _errno == errno.EACCES and sys.platform == "win32":
87-
if getattr(exc_value, "args", None) == 32: # pragma: no cover
87+
error_args = getattr(exc_value, "args", (None,))
88+
if error_args and error_args[0] == 32: # pragma: no cover
8889
fserror = errors.ResourceLocked
8990
reraise(fserror, fserror(self._path, exc=exc_value), traceback)
9091

tests/test_error_tools.py

+16
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
import unittest
55

66
import fs.errors
7+
import fs.error_tools
78
from fs.error_tools import convert_os_errors
89

10+
try:
11+
from unittest import mock
12+
except ImportError:
13+
import mock
14+
915

1016
class TestErrorTools(unittest.TestCase):
1117
def test_convert_enoent(self):
@@ -23,3 +29,13 @@ def test_convert_enametoolong(self):
2329
raise exception
2430
self.assertEqual(ctx.exception.exc, exception)
2531
self.assertEqual(ctx.exception.path, "/tmp/test")
32+
33+
@mock.patch.object(fs.error_tools.sys, "platform", "win32")
34+
def test_convert_resourcelocked_windows(self):
35+
exception = OSError(32, "resource locked")
36+
with self.assertRaises(fs.errors.ResourceLocked) as ctx:
37+
with convert_os_errors("stat", "/tmp/test"):
38+
raise exception
39+
40+
self.assertEqual(ctx.exception.exc, exception)
41+
self.assertEqual(ctx.exception.path, "/tmp/test")

0 commit comments

Comments
 (0)