Skip to content

Commit c51b035

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

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Diff for: 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

Diff for: 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

Diff for: tests/test_error_tools.py

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import unicode_literals
22

33
import errno
4+
import sys
45
import unittest
56

67
import fs.errors
@@ -23,3 +24,13 @@ def test_convert_enametoolong(self):
2324
raise exception
2425
self.assertEqual(ctx.exception.exc, exception)
2526
self.assertEqual(ctx.exception.path, "/tmp/test")
27+
28+
@unittest.skipIf(sys.platform != "win32", "requires Windows")
29+
def test_convert_resourcelocked_windows(self):
30+
exception = OSError(32, "resource locked")
31+
with self.assertRaises(fs.errors.ResourceLocked) as ctx:
32+
with convert_os_errors("stat", "/tmp/test"):
33+
raise exception
34+
35+
self.assertEqual(ctx.exception.exc, exception)
36+
self.assertEqual(ctx.exception.path, "/tmp/test")

0 commit comments

Comments
 (0)