Skip to content

Commit 8a090f1

Browse files
joschJPEWdev
authored andcommitted
tests/test_bmap_helpers.py: avoid build failure from disorderfs
When running under disorderfs --shuffle-dirents=yes, the following Python code fails: with TemporaryDirectory(prefix="testdir_", dir=".") as directory: fobj = tempfile.NamedTemporaryFile( "r", delete=False, dir=directory ) Traceback (most recent call last): File "/tmp/disorder/test.py", line 4, in <module> with TemporaryDirectory(prefix="testdir_", dir=".") as directory: File "/usr/lib/python3.11/tempfile.py", line 1052, in __exit__ self.cleanup() File "/usr/lib/python3.11/tempfile.py", line 1056, in cleanup self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors) File "/usr/lib/python3.11/tempfile.py", line 1038, in _rmtree _rmtree(name, onerror=onerror) File "/usr/lib/python3.11/shutil.py", line 738, in rmtree onerror(os.rmdir, path, sys.exc_info()) File "/usr/lib/python3.11/shutil.py", line 736, in rmtree os.rmdir(path, dir_fd=dir_fd) OSError: [Errno 39] Directory not empty: './testdir_6jhyg1o6' From investigating this, the reason that the test fails when using `disorderfs` is that, by default, FUSE overlay filesystems (of which `disorderfs` is an instance) don't immediately delete open files completely from the directory they are in; instead they're renamed to a temporary dotfile name, as documented here: http://libfuse.github.io/doxygen/structfuse__config.html#af32ff56fa1131da899756cc352718101 That causes the test to fail, because Python's `TemporaryDirectory` context-handler quite reasonably thinks that it has removed all the files in the directory, and therefore attempts a delete-only-if-empty operation. This currently fails under `disorderfs`, because the `fobj` file is open for reading, and therefore isn't entirely deleted, but only renamed. Closing the file is a simple fix for this. Note also: the `disorderfs` command-line can accept an `-o hard_remove` option to enable FUSE `hard_remove` option, causing deletes to apply directly to the underlying filesystem. I've filed a request/suggestion at https://bugs.debian.org/1093768 to enable it by default in `disorderfs` -- but doing so apparently causes other, potentially more disruptive, side-effects, so there's no guarantee that that behaviour will become the default. Thanks: James Addison <[email protected]>
1 parent 8deed2f commit 8a090f1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tests/test_bmap_helpers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ def test_get_file_system_type_symlink(self):
6464
"""Check a file system type is returned when used with a symlink"""
6565

6666
with TemporaryDirectory(prefix="testdir_", dir=".") as directory:
67-
fobj = tempfile.NamedTemporaryFile(
67+
with tempfile.NamedTemporaryFile(
6868
"r", prefix="testfile_", delete=False, dir=directory, suffix=".img"
69-
)
70-
lnk = os.path.join(directory, "test_symlink")
71-
os.symlink(fobj.name, lnk)
72-
fstype = BmapHelpers.get_file_system_type(lnk)
73-
self.assertTrue(fstype)
69+
) as fobj:
70+
lnk = os.path.join(directory, "test_symlink")
71+
os.symlink(fobj.name, lnk)
72+
fstype = BmapHelpers.get_file_system_type(lnk)
73+
self.assertTrue(fstype)
7474

7575
def test_is_zfs_configuration_compatible_enabled(self):
7676
"""Check compatibility check is true when zfs param is set correctly"""

0 commit comments

Comments
 (0)