From c87873b304450f3f0b1fea2bcf63ba59af51b869 Mon Sep 17 00:00:00 2001 From: clover caruso Date: Tue, 17 Nov 2026 05:15:31 -0800 Subject: [PATCH] Create share folders only when missing and accept the new Copyparty reload reply Copyparty 1.20.26 replies "users, volumes, and volflags have been reloaded", so every share save was reported as unconfirmed and rolled back. New shares now reuse an existing folder instead of failing, and the create-folder checkbox is gone. Assisted-by: claude-opus-5.5 --- dashboard/web/api.contract.ts | 2 +- dashboard/web/pages/Shares.tsx | 10 ++++------ service/copyparty/manage.py | 17 ++++++----------- tools/copyparty-test.py | 12 ++++++++++-- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/dashboard/web/api.contract.ts b/dashboard/web/api.contract.ts index a82e8a50d83b4f637e9f754bd36c919889d2eaac..2ca74c48eebeb5d115b2af373f823de4768dc4b2 100644 --- a/dashboard/web/api.contract.ts +++ b/dashboard/web/api.contract.ts @@ -68,7 +68,7 @@ export type Api = Hono<{}, { $patch: Endpoint }>; $delete: Endpoint; }; - "/shares/links": { $post: Endpoint; }; + "/shares/links": { $post: Endpoint; }; "/shares/links/:key": { $patch: Endpoint; $delete: Endpoint; diff --git a/dashboard/web/pages/Shares.tsx b/dashboard/web/pages/Shares.tsx index 2b009fb42ad1cf600421369705cbc53b21babca3..c0684b46b9144f14e2fd1d35b42267f7820586de 100644 --- a/dashboard/web/pages/Shares.tsx +++ b/dashboard/web/pages/Shares.tsx @@ -31,7 +31,7 @@ function Rights(props: { value: string; onChange: (value: string) => void; link? ; } -function FolderField(props: { value: string; root: string; create?: boolean; onChange: (value: string, existing?: boolean) => void }) { +function FolderField(props: { value: string; root: string; create?: boolean; onChange: (value: string) => void }) { const browse = () => { const [path, setPath] = createSignal(props.create && !props.value.endsWith("/") ? props.value.replace(/\/[^/]+$/, "") || props.root : props.value || props.root); showConfirmDialog({ @@ -49,7 +49,7 @@ function FolderField(props: { value: string; root: string; create?: boolean; onC ; }, - onConfirm: () => props.onChange(macPath(path(), props.root), true), + onConfirm: () => props.onChange(macPath(path(), props.root)), }); }; return
folder}> - { setCustomPath(value); if (existing) setCreateFolder(false); }} /> - create this folder +
selected filesThis share keeps its file selection when its folder changes
diff --git a/service/copyparty/manage.py b/service/copyparty/manage.py index 72a0f2fe80b431a1a31f9831bc6cae974e2b728c..d7efd654e7a52337eeb2051476f60ebbb020d58c 100644 --- a/service/copyparty/manage.py +++ b/service/copyparty/manage.py @@ -24,7 +24,7 @@ ACTIONS = { 'account.create': {'name'}, 'account.update': {'id', 'name'}, 'account.rotate': {'id'}, 'account.delete': {'id'}, 'grant.save': {'id', 'subject', 'path', 'permissions'}, 'grant.delete': {'id'}, - 'link.create': {'name', 'path', 'permissions', 'expires', 'password', 'createFolder'}, + 'link.create': {'name', 'path', 'permissions', 'expires', 'password'}, 'link.update': {'key', 'name', 'path', 'permissions', 'expires', 'password', 'mode'}, 'link.delete': {'key'}, } @@ -285,7 +285,7 @@ class Manager: try: with urllib.request.urlopen(request, timeout=remaining(deadline, 30)) as response: body = response.read(262144) - if response.status != 200 or b'config has been reloaded' not in body: + if response.status != 200 or b'have been reloaded' not in body: raise Error(502, 'Copyparty did not confirm the update. Try again after checking the service.') except (urllib.error.URLError, TimeoutError): raise Error(502, 'Copyparty could not apply the update. Check the service and try again.') from None @@ -441,9 +441,7 @@ class Manager: password = old[1] if old is not None else '' else: password = self.hash(password) - create = action == 'link.create' and payload['createFolder'] is True - if action == 'link.create' and type(payload['createFolder']) is not bool: - raise Error(400, 'Choose an existing folder or create a new one.') + create = action == 'link.create' destination = payload['path'] share_root = self.root / 'Share' if create and (not destination or Path(destination).parent == share_root or str(destination).startswith('/Volumes/clover/Share/')): @@ -461,12 +459,9 @@ class Manager: mode = payload.get('mode', 'retarget') if mode not in {'retarget', 'move'}: raise Error(400, 'Choose whether to move the folder or use another folder.') - if create: - try: - destination.mkdir(mode=0o775) - destination.chmod(0o775) - except FileExistsError: - raise Error(409, 'That folder already exists. Choose it as an existing folder or change its name.') from None + if create and not destination.exists(): + destination.mkdir(mode=0o775) + destination.chmod(0o775) owner = destination.parent.stat() os.chown(destination, owner.st_uid, owner.st_gid) self.undo.append(lambda: destination.rmdir()) diff --git a/tools/copyparty-test.py b/tools/copyparty-test.py index 0266e36583509296400a377d2bf72972cd6a5767..438ae5f5708675b3d38b483845fc451fe551407c 100644 --- a/tools/copyparty-test.py +++ b/tools/copyparty-test.py @@ -174,13 +174,21 @@ class Shares(unittest.TestCase): self.assertEqual(self.call('state')['links'][0]['path'], str(destination)) def test_default_folder_create_and_link_delete_keep_data(self): - result = self.call('link.create', name='Clover - Example', path='', permissions='rw', expires=0, password='', createFolder=True) + result = self.call('link.create', name='Clover - Example', path='', permissions='rw', expires=0, password='') path = self.root / 'Share/Clover - Example' self.assertTrue(path.is_dir()) self.call('link.delete', key=result['links'][0]['key']) self.assertTrue(path.is_dir()) self.assertEqual(self.call('state')['links'], []) + def test_link_create_reuses_existing_folder(self): + path = self.root / 'Share/Clover - Existing' + path.mkdir(parents=True) + (path / 'kept.txt').write_text('disposable') + self.call('link.create', name='Clover - Existing', path='', permissions='r', expires=0, password='') + self.assertEqual(self.call('state')['links'][0]['path'], str(path)) + self.assertTrue((path / 'kept.txt').is_file()) + def test_move_preserves_key_selection_nested_links_and_grants(self): source = self.root / 'source' (source / 'nested').mkdir(parents=True) @@ -259,7 +267,7 @@ class Shares(unittest.TestCase): previous = os.umask(0o077) try: self.call('link.create', name='Clover - Restricted', path=str(self.root / 'Share/Clover - Restricted'), - permissions='r', expires=0, password='', createFolder=True) + permissions='r', expires=0, password='') finally: os.umask(previous) self.assertEqual((self.root / 'Share').stat().st_mode & 0o777, 0o775) -- 2.54.1