From c51b0352441cdf7683f286009387b9df84adcdd5 Mon Sep 17 00:00:00 2001 From: Diego Argueta Date: Thu, 29 Jul 2021 10:39:52 -0700 Subject: [PATCH 1/5] Fix #484 --- CHANGELOG.md | 1 + fs/error_tools.py | 3 ++- tests/test_error_tools.py | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11d8330d..a23dc9b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/fs/error_tools.py b/fs/error_tools.py index 66d38696..ba516eeb 100644 --- a/fs/error_tools.py +++ b/fs/error_tools.py @@ -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) diff --git a/tests/test_error_tools.py b/tests/test_error_tools.py index 4f6aa324..02def95f 100644 --- a/tests/test_error_tools.py +++ b/tests/test_error_tools.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals import errno +import sys import unittest import fs.errors @@ -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") From f836f2d00faa85b6c1a1679084e91e229e8c4820 Mon Sep 17 00:00:00 2001 From: Diego Argueta Date: Mon, 30 Aug 2021 16:36:48 -0700 Subject: [PATCH 2/5] Update to how Windows error is detected --- fs/error_tools.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/error_tools.py b/fs/error_tools.py index ba516eeb..18bbb068 100644 --- a/fs/error_tools.py +++ b/fs/error_tools.py @@ -84,8 +84,9 @@ def __exit__( _errno = exc_value.errno fserror = os_errors.get(_errno, errors.OperationFailed) if _errno == errno.EACCES and sys.platform == "win32": - error_args = getattr(exc_value, "args", (None,)) - if error_args and error_args[0] == 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) From 02709d8e901b0a59ed87bfcfb07fa2be8b3a265d Mon Sep 17 00:00:00 2001 From: Diego Argueta Date: Wed, 17 Nov 2021 17:41:43 -0800 Subject: [PATCH 3/5] Fix changelog from merge --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e0258a1..0d2085f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### Added + +### Changed + +### Fixed + +- Fixed `ResourceLocked` error translation on Windows [#484](https://github.com/PyFilesystem/pyfilesystem2/issues/484). + ## [2.4.14] - 2021-11-16 From 6f453cb620d10bcaf00b40f1adb4f62bdaf4d236 Mon Sep 17 00:00:00 2001 From: Diego Argueta Date: Thu, 18 Nov 2021 13:15:42 -0800 Subject: [PATCH 4/5] Removed duplicated line in changelog --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d2085f6..9ee1fc2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,6 @@ 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 From c8c83d1ea6c129a9f647f15edbc73378e52146b7 Mon Sep 17 00:00:00 2001 From: Diego Argueta Date: Wed, 15 Dec 2021 18:10:06 -0800 Subject: [PATCH 5/5] Fix call to OSError constructor on Windows test, some lint stuff --- CHANGELOG.md | 2 -- fs/error_tools.py | 4 +++- tests/test_error_tools.py | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89e0dd8d..ab559c7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased -### Added - ### Changed - Support more lenient usernames and group names in FTP servers diff --git a/fs/error_tools.py b/fs/error_tools.py index 18bbb068..d718de55 100644 --- a/fs/error_tools.py +++ b/fs/error_tools.py @@ -86,7 +86,9 @@ def __exit__( if _errno == errno.EACCES and sys.platform == "win32": 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 + 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) diff --git a/tests/test_error_tools.py b/tests/test_error_tools.py index 02def95f..d3d706c5 100644 --- a/tests/test_error_tools.py +++ b/tests/test_error_tools.py @@ -27,7 +27,8 @@ def test_convert_enametoolong(self): @unittest.skipIf(sys.platform != "win32", "requires Windows") def test_convert_resourcelocked_windows(self): - exception = OSError(32, "resource locked") + # 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