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 ed4f807
Show file tree
Hide file tree
Showing 3 changed files with 19 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
16 changes: 16 additions & 0 deletions tests/test_error_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
import unittest

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

try:
from unittest import mock
except ImportError:
import mock


class TestErrorTools(unittest.TestCase):
def test_convert_enoent(self):
Expand All @@ -23,3 +29,13 @@ def test_convert_enametoolong(self):
raise exception
self.assertEqual(ctx.exception.exc, exception)
self.assertEqual(ctx.exception.path, "/tmp/test")

@mock.patch.object(fs.error_tools.sys, "platform", "win32")
def test_convert_resourcelocked_windows(self, _unused):
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 ed4f807

Please sign in to comment.