Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ResourceLocked translation on Windows #484 #491

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Fixed `ResourceLocked` error translation on Windows [#484](https://github.com/PyFilesystem/pyfilesystem2/issues/484).
- Fixed `MemoryFS.move` and `MemoryFS.movedir` not updating the name of moved
resources, causing `MemoryFS.scandir` to use the old name.
([#510](https://github.com/PyFilesystem/pyfilesystem2/pull/510)).
Expand Down
6 changes: 5 additions & 1 deletion fs/error_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ 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
windows_error = getattr(exc_value, "winerror", 0)
exception_args = getattr(exc_value, "args", None) or (0,)
if (
windows_error == 32 or exception_args[0] == errno.EACCES
): # pragma: no cover
fserror = errors.ResourceLocked
reraise(fserror, fserror(self._path, exc=exc_value), traceback)

Expand Down
12 changes: 12 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,14 @@ 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):
dargueta marked this conversation as resolved.
Show resolved Hide resolved
# errno should be ignored on Windows so we pass in a bogus number.
exception = OSError(123456, "resource locked", None, 32)
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")