From 9f22bb6ba8d3ebbc45cad2fa46f18e161e05250c Mon Sep 17 00:00:00 2001 From: Antoine Delattre Date: Thu, 9 Sep 2021 14:20:42 +0200 Subject: [PATCH 1/4] Change fuse_operations open method flag mask + add test on open --- parsec/core/mountpoint/fuse_operations.py | 2 +- tests/core/mountpoint/test_base.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/parsec/core/mountpoint/fuse_operations.py b/parsec/core/mountpoint/fuse_operations.py index 49d8ddf5992..fdec892385a 100644 --- a/parsec/core/mountpoint/fuse_operations.py +++ b/parsec/core/mountpoint/fuse_operations.py @@ -202,7 +202,7 @@ def create(self, path: FsPath, mode: int): def open(self, path: FsPath, flags: int = 0): # Filter file status and file creation flags - write_mode = flags in (os.O_WRONLY, os.O_RDWR) + write_mode = flags & (os.O_WRONLY | os.O_RDWR) _, fd = self.fs_access.file_open(path, write_mode=write_mode) return fd diff --git a/tests/core/mountpoint/test_base.py b/tests/core/mountpoint/test_base.py index 2cfc7f9887c..f3a03654ee6 100644 --- a/tests/core/mountpoint/test_base.py +++ b/tests/core/mountpoint/test_base.py @@ -396,6 +396,14 @@ async def assert_cannot_write(mountpoint_manager, new_role): with pytest.raises(expected_error) as ctx: await bar_path.unlink() + def sync_open(): + for flag in (os.O_WRONLY, os.O_RDWR): + with pytest.raises(expected_error) as ctx: + os.open(foo_path, flag) + assert ctx.value.errno == expected_errno + + await trio.to_thread.run_sync(sync_open) + async with mountpoint_manager_factory( alice_user_fs, event_bus, base_mountpoint ) as mountpoint_manager: From c2506d8c14b63b5af99ebfc0a483faf1230e7da8 Mon Sep 17 00:00:00 2001 From: Antoine Delattre Date: Thu, 9 Sep 2021 14:40:55 +0200 Subject: [PATCH 2/4] Add newsfragment for #1836 --- newsfragments/1836.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/1836.bugfix.rst diff --git a/newsfragments/1836.bugfix.rst b/newsfragments/1836.bugfix.rst new file mode 100644 index 00000000000..cdf49dd5621 --- /dev/null +++ b/newsfragments/1836.bugfix.rst @@ -0,0 +1 @@ +Fixed a bug where some text editor could still edit files in a workspace as reader From 8c15cb285181b44f8ad8aa8a4c0950f6f2f7f682 Mon Sep 17 00:00:00 2001 From: Antoine Delattre Date: Thu, 9 Sep 2021 16:47:31 +0200 Subject: [PATCH 3/4] Add tests for multiple flags in open and change problematic bitwise comparison --- parsec/core/mountpoint/fuse_operations.py | 2 +- tests/core/mountpoint/test_base.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/parsec/core/mountpoint/fuse_operations.py b/parsec/core/mountpoint/fuse_operations.py index fdec892385a..a90fda979b6 100644 --- a/parsec/core/mountpoint/fuse_operations.py +++ b/parsec/core/mountpoint/fuse_operations.py @@ -202,7 +202,7 @@ def create(self, path: FsPath, mode: int): def open(self, path: FsPath, flags: int = 0): # Filter file status and file creation flags - write_mode = flags & (os.O_WRONLY | os.O_RDWR) + write_mode = (flags % 4) in (os.O_WRONLY, os.O_RDWR) _, fd = self.fs_access.file_open(path, write_mode=write_mode) return fd diff --git a/tests/core/mountpoint/test_base.py b/tests/core/mountpoint/test_base.py index f3a03654ee6..df8bec08401 100644 --- a/tests/core/mountpoint/test_base.py +++ b/tests/core/mountpoint/test_base.py @@ -397,7 +397,12 @@ async def assert_cannot_write(mountpoint_manager, new_role): await bar_path.unlink() def sync_open(): - for flag in (os.O_WRONLY, os.O_RDWR): + for flag in ( + os.O_WRONLY, + os.O_RDWR, + os.O_RDWR | os.O_APPEND, + os.O_WRONLY | os.O_NONBLOCK, + ): with pytest.raises(expected_error) as ctx: os.open(foo_path, flag) assert ctx.value.errno == expected_errno From 1a57a10e88e77368591fae337b943a5e10d997f3 Mon Sep 17 00:00:00 2001 From: Antoine Delattre Date: Thu, 9 Sep 2021 17:43:47 +0200 Subject: [PATCH 4/4] change an open flag which doesn't exist on windows --- tests/core/mountpoint/test_base.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/core/mountpoint/test_base.py b/tests/core/mountpoint/test_base.py index df8bec08401..5a8c3367c89 100644 --- a/tests/core/mountpoint/test_base.py +++ b/tests/core/mountpoint/test_base.py @@ -397,12 +397,7 @@ async def assert_cannot_write(mountpoint_manager, new_role): await bar_path.unlink() def sync_open(): - for flag in ( - os.O_WRONLY, - os.O_RDWR, - os.O_RDWR | os.O_APPEND, - os.O_WRONLY | os.O_NONBLOCK, - ): + for flag in (os.O_WRONLY, os.O_RDWR, os.O_RDWR | os.O_APPEND, os.O_WRONLY | os.O_EXCL): with pytest.raises(expected_error) as ctx: os.open(foo_path, flag) assert ctx.value.errno == expected_errno