Skip to content

Commit

Permalink
Fix #484
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Argueta committed Jul 29, 2021
1 parent 12cd2f4 commit c51b035
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

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


## [2.4.13] - 2021-03-27
Expand Down
3 changes: 2 additions & 1 deletion fs/error_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ 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
error_args = getattr(exc_value, "args", (None,))
if error_args and error_args[0] == 32: # pragma: no cover
fserror = errors.ResourceLocked
reraise(fserror, fserror(self._path, exc=exc_value), traceback)

Expand Down
11 changes: 11 additions & 0 deletions tests/test_error_tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import unicode_literals

import errno
import sys
import unittest

import fs.errors
Expand All @@ -23,3 +24,13 @@ def test_convert_enametoolong(self):
raise exception
self.assertEqual(ctx.exception.exc, exception)
self.assertEqual(ctx.exception.path, "/tmp/test")

@unittest.skipIf(sys.platform != "win32", "requires Windows")
def test_convert_resourcelocked_windows(self):
exception = OSError(32, "resource locked")
with self.assertRaises(fs.errors.ResourceLocked) as ctx:
with convert_os_errors("stat", "/tmp/test"):
raise exception

self.assertEqual(ctx.exception.exc, exception)
self.assertEqual(ctx.exception.path, "/tmp/test")

0 comments on commit c51b035

Please sign in to comment.