authoravatarclover caruso<git@paperclover.net>2026-11-17 05:15:31-08:00
committeravatarclover caruso<git@paperclover.net>2026-11-22 00:44:02-08:00
logc87873b304450f3f0b1fea2bcf63ba59af51b869
tree32f5a64d5373499c700131cfa8ada347c2c6acd1
parenteb8d89d397b222c147975b63bb30fcc8fd959468
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

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

4 files changed, 21 insertions(+), 20 deletions(-)

dashboard/web/api.contract.ts+1-1
...@@ -68,7 +68,7 @@ export type Api = Hono<{}, {...@@ -68,7 +68,7 @@ export type Api = Hono<{}, {
68 $patch: Endpoint<ShareState, { param: { id: string }; json: Omit<FolderGrant, "id"> }>;68 $patch: Endpoint<ShareState, { param: { id: string }; json: Omit<FolderGrant, "id"> }>;
69 $delete: Endpoint<ShareState, { param: { id: string } }>;69 $delete: Endpoint<ShareState, { param: { id: string } }>;
70 };70 };
71 "/shares/links": { $post: Endpoint<ShareState, { json: LinkInput & { createFolder: boolean } }>; };71 "/shares/links": { $post: Endpoint<ShareState, { json: LinkInput }>; };
72 "/shares/links/:key": {72 "/shares/links/:key": {
73 $patch: Endpoint<ShareState, { param: { key: string }; json: LinkInput & { mode: "retarget" | "move" } }>;73 $patch: Endpoint<ShareState, { param: { key: string }; json: LinkInput & { mode: "retarget" | "move" } }>;
74 $delete: Endpoint<ShareState, { param: { key: string } }>;74 $delete: Endpoint<ShareState, { param: { key: string } }>;
dashboard/web/pages/Shares.tsx+4-6
...@@ -31,7 +31,7 @@ function Rights(props: { value: string; onChange: (value: string) => void; link?...@@ -31,7 +31,7 @@ function Rights(props: { value: string; onChange: (value: string) => void; link?
31 </div></fieldset>;31 </div></fieldset>;
32}32}
3333
34function FolderField(props: { value: string; root: string; create?: boolean; onChange: (value: string, existing?: boolean) => void }) {34function FolderField(props: { value: string; root: string; create?: boolean; onChange: (value: string) => void }) {
35 const browse = () => {35 const browse = () => {
36 const [path, setPath] = createSignal(props.create && !props.value.endsWith("/") ? props.value.replace(/\/[^/]+$/, "") || props.root : props.value || props.root);36 const [path, setPath] = createSignal(props.create && !props.value.endsWith("/") ? props.value.replace(/\/[^/]+$/, "") || props.root : props.value || props.root);
37 showConfirmDialog({37 showConfirmDialog({
...@@ -49,7 +49,7 @@ function FolderField(props: { value: string; root: string; create?: boolean; onC...@@ -49,7 +49,7 @@ function FolderField(props: { value: string; root: string; create?: boolean; onC
49 </Loaded>49 </Loaded>
50 </div>;50 </div>;
51 },51 },
52 onConfirm: () => props.onChange(macPath(path(), props.root), true),52 onConfirm: () => props.onChange(macPath(path(), props.root)),
53 });53 });
54 };54 };
55 return <div class="field">folder<div class="share-folder-field">55 return <div class="field">folder<div class="share-folder-field">
...@@ -244,7 +244,6 @@ function LinkForm(props: { original?: SharedLink; fresh: boolean; state: ShareSt...@@ -244,7 +244,6 @@ function LinkForm(props: { original?: SharedLink; fresh: boolean; state: ShareSt
244 const [customPath, setCustomPath] = createSignal("");244 const [customPath, setCustomPath] = createSignal("");
245 const path = () => customPath() || `${macPath(props.state.defaultRoot, props.state.root)}/${name().trim()}`;245 const path = () => customPath() || `${macPath(props.state.defaultRoot, props.state.root)}/${name().trim()}`;
246 const [rights, setRights] = createSignal(props.original?.permissions ?? "r");246 const [rights, setRights] = createSignal(props.original?.permissions ?? "r");
247 const [createFolder, setCreateFolder] = createSignal(true);
248 const [password, setPassword] = createSignal<string | null>(null);247 const [password, setPassword] = createSignal<string | null>(null);
249 const dateValue = (seconds: number) => {248 const dateValue = (seconds: number) => {
250 const date = new Date(seconds * 1000);249 const date = new Date(seconds * 1000);
...@@ -261,7 +260,7 @@ function LinkForm(props: { original?: SharedLink; fresh: boolean; state: ShareSt...@@ -261,7 +260,7 @@ function LinkForm(props: { original?: SharedLink; fresh: boolean; state: ShareSt
261 const json = { name: name().trim(), path: props.original?.path ?? path(), permissions: rights(), expires: expires() ? new Date(expires()).getTime() / 1000 : 0, password: password() };260 const json = { name: name().trim(), path: props.original?.path ?? path(), permissions: rights(), expires: expires() ? new Date(expires()).getTime() / 1000 : 0, password: password() };
262 const result = await parseResponse(props.original261 const result = await parseResponse(props.original
263 ? api.shares.links[":key"].$patch({ param: { key: props.original.key }, json: { ...json, mode: "retarget" } })262 ? api.shares.links[":key"].$patch({ param: { key: props.original.key }, json: { ...json, mode: "retarget" } })
264 : api.shares.links.$post({ json: { ...json, createFolder: createFolder() } }));263 : api.shares.links.$post({ json }));
265 const key = props.original?.key ?? result.links.find((link) => !props.state.links.some((old) => old.key === link.key))?.key;264 const key = props.original?.key ?? result.links.find((link) => !props.state.links.some((old) => old.key === link.key))?.key;
266 if (key) props.saved(result, key);265 if (key) props.saved(result, key);
267 setPassword(null);266 setPassword(null);
...@@ -300,8 +299,7 @@ function LinkForm(props: { original?: SharedLink; fresh: boolean; state: ShareSt...@@ -300,8 +299,7 @@ function LinkForm(props: { original?: SharedLink; fresh: boolean; state: ShareSt
300 <fieldset disabled={pending()}>299 <fieldset disabled={pending()}>
301 <label class="field">name<input class="search" required value={name()} placeholder="Name - Description" autocomplete="off" onInput={(event) => setName(event.currentTarget.value)} /></label>300 <label class="field">name<input class="search" required value={name()} placeholder="Name - Description" autocomplete="off" onInput={(event) => setName(event.currentTarget.value)} /></label>
302 <Show when={props.fresh} fallback={<div class="field">folder<div class="share-current-folder"><span class="share-path">{macPath(props.original!.path, props.state.root)}</span><button type="button" class="button" onClick={changeFolder}>change folder</button></div></div>}>301 <Show when={props.fresh} fallback={<div class="field">folder<div class="share-current-folder"><span class="share-path">{macPath(props.original!.path, props.state.root)}</span><button type="button" class="button" onClick={changeFolder}>change folder</button></div></div>}>
303 <FolderField value={path()} root={props.state.root} create={createFolder()} onChange={(value, existing) => { setCustomPath(value); if (existing) setCreateFolder(false); }} />302 <FolderField value={path()} root={props.state.root} create onChange={setCustomPath} />
304 <Checkbox checked={createFolder()} onChange={setCreateFolder}>create this folder</Checkbox>
305 </Show>303 </Show>
306 <Show when={props.original?.files.length}><div class="field">selected files<ul class="share-selection"><For each={props.original?.files}>{(file) => <li>{file}</li>}</For></ul><span class="hint">This share keeps its file selection when its folder changes</span></div></Show>304 <Show when={props.original?.files.length}><div class="field">selected files<ul class="share-selection"><For each={props.original?.files}>{(file) => <li>{file}</li>}</For></ul><span class="hint">This share keeps its file selection when its folder changes</span></div></Show>
307 <Rights value={rights()} onChange={setRights} link />305 <Rights value={rights()} onChange={setRights} link />
service/copyparty/manage.py+6-11
...@@ -24,7 +24,7 @@ ACTIONS = {...@@ -24,7 +24,7 @@ ACTIONS = {
24 'account.create': {'name'}, 'account.update': {'id', 'name'},24 'account.create': {'name'}, 'account.update': {'id', 'name'},
25 'account.rotate': {'id'}, 'account.delete': {'id'},25 'account.rotate': {'id'}, 'account.delete': {'id'},
26 'grant.save': {'id', 'subject', 'path', 'permissions'}, 'grant.delete': {'id'},26 'grant.save': {'id', 'subject', 'path', 'permissions'}, 'grant.delete': {'id'},
27 'link.create': {'name', 'path', 'permissions', 'expires', 'password', 'createFolder'},27 'link.create': {'name', 'path', 'permissions', 'expires', 'password'},
28 'link.update': {'key', 'name', 'path', 'permissions', 'expires', 'password', 'mode'},28 'link.update': {'key', 'name', 'path', 'permissions', 'expires', 'password', 'mode'},
29 'link.delete': {'key'},29 'link.delete': {'key'},
30}30}
...@@ -285,7 +285,7 @@ class Manager:...@@ -285,7 +285,7 @@ class Manager:
285 try:285 try:
286 with urllib.request.urlopen(request, timeout=remaining(deadline, 30)) as response:286 with urllib.request.urlopen(request, timeout=remaining(deadline, 30)) as response:
287 body = response.read(262144)287 body = response.read(262144)
288 if response.status != 200 or b'config has been reloaded' not in body:288 if response.status != 200 or b'have been reloaded' not in body:
289 raise Error(502, 'Copyparty did not confirm the update. Try again after checking the service.')289 raise Error(502, 'Copyparty did not confirm the update. Try again after checking the service.')
290 except (urllib.error.URLError, TimeoutError):290 except (urllib.error.URLError, TimeoutError):
291 raise Error(502, 'Copyparty could not apply the update. Check the service and try again.') from None291 raise Error(502, 'Copyparty could not apply the update. Check the service and try again.') from None
...@@ -441,9 +441,7 @@ class Manager:...@@ -441,9 +441,7 @@ class Manager:
441 password = old[1] if old is not None else ''441 password = old[1] if old is not None else ''
442 else:442 else:
443 password = self.hash(password)443 password = self.hash(password)
444 create = action == 'link.create' and payload['createFolder'] is True444 create = action == 'link.create'
445 if action == 'link.create' and type(payload['createFolder']) is not bool:
446 raise Error(400, 'Choose an existing folder or create a new one.')
447 destination = payload['path']445 destination = payload['path']
448 share_root = self.root / 'Share'446 share_root = self.root / 'Share'
449 if create and (not destination or Path(destination).parent == share_root or str(destination).startswith('/Volumes/clover/Share/')):447 if create and (not destination or Path(destination).parent == share_root or str(destination).startswith('/Volumes/clover/Share/')):
...@@ -461,12 +459,9 @@ class Manager:...@@ -461,12 +459,9 @@ class Manager:
461 mode = payload.get('mode', 'retarget')459 mode = payload.get('mode', 'retarget')
462 if mode not in {'retarget', 'move'}:460 if mode not in {'retarget', 'move'}:
463 raise Error(400, 'Choose whether to move the folder or use another folder.')461 raise Error(400, 'Choose whether to move the folder or use another folder.')
464 if create:462 if create and not destination.exists():
465 try:463 destination.mkdir(mode=0o775)
466 destination.mkdir(mode=0o775)464 destination.chmod(0o775)
467 destination.chmod(0o775)
468 except FileExistsError:
469 raise Error(409, 'That folder already exists. Choose it as an existing folder or change its name.') from None
470 owner = destination.parent.stat()465 owner = destination.parent.stat()
471 os.chown(destination, owner.st_uid, owner.st_gid)466 os.chown(destination, owner.st_uid, owner.st_gid)
472 self.undo.append(lambda: destination.rmdir())467 self.undo.append(lambda: destination.rmdir())
tools/copyparty-test.py+10-2
...@@ -174,13 +174,21 @@ class Shares(unittest.TestCase):...@@ -174,13 +174,21 @@ class Shares(unittest.TestCase):
174 self.assertEqual(self.call('state')['links'][0]['path'], str(destination))174 self.assertEqual(self.call('state')['links'][0]['path'], str(destination))
175175
176 def test_default_folder_create_and_link_delete_keep_data(self):176 def test_default_folder_create_and_link_delete_keep_data(self):
177 result = self.call('link.create', name='Clover - Example', path='', permissions='rw', expires=0, password='', createFolder=True)177 result = self.call('link.create', name='Clover - Example', path='', permissions='rw', expires=0, password='')
178 path = self.root / 'Share/Clover - Example'178 path = self.root / 'Share/Clover - Example'
179 self.assertTrue(path.is_dir())179 self.assertTrue(path.is_dir())
180 self.call('link.delete', key=result['links'][0]['key'])180 self.call('link.delete', key=result['links'][0]['key'])
181 self.assertTrue(path.is_dir())181 self.assertTrue(path.is_dir())
182 self.assertEqual(self.call('state')['links'], [])182 self.assertEqual(self.call('state')['links'], [])
183183
184 def test_link_create_reuses_existing_folder(self):
185 path = self.root / 'Share/Clover - Existing'
186 path.mkdir(parents=True)
187 (path / 'kept.txt').write_text('disposable')
188 self.call('link.create', name='Clover - Existing', path='', permissions='r', expires=0, password='')
189 self.assertEqual(self.call('state')['links'][0]['path'], str(path))
190 self.assertTrue((path / 'kept.txt').is_file())
191
184 def test_move_preserves_key_selection_nested_links_and_grants(self):192 def test_move_preserves_key_selection_nested_links_and_grants(self):
185 source = self.root / 'source'193 source = self.root / 'source'
186 (source / 'nested').mkdir(parents=True)194 (source / 'nested').mkdir(parents=True)
...@@ -259,7 +267,7 @@ class Shares(unittest.TestCase):...@@ -259,7 +267,7 @@ class Shares(unittest.TestCase):
259 previous = os.umask(0o077)267 previous = os.umask(0o077)
260 try:268 try:
261 self.call('link.create', name='Clover - Restricted', path=str(self.root / 'Share/Clover - Restricted'),269 self.call('link.create', name='Clover - Restricted', path=str(self.root / 'Share/Clover - Restricted'),
262 permissions='r', expires=0, password='', createFolder=True)270 permissions='r', expires=0, password='')
263 finally:271 finally:
264 os.umask(previous)272 os.umask(previous)
265 self.assertEqual((self.root / 'Share').stat().st_mode & 0o777, 0o775)273 self.assertEqual((self.root / 'Share').stat().st_mode & 0o777, 0o775)