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<{}, {
6868 $patch: Endpoint<ShareState, { param: { id: string }; json: Omit<FolderGrant, "id"> }>;
6969 $delete: Endpoint<ShareState, { param: { id: string } }>;
7070 };
71 "/shares/links": { $post: Endpoint<ShareState, { json: LinkInput & { createFolder: boolean } }>; };
71 "/shares/links": { $post: Endpoint<ShareState, { json: LinkInput }>; };
7272 "/shares/links/:key": {
7373 $patch: Endpoint<ShareState, { param: { key: string }; json: LinkInput & { mode: "retarget" | "move" } }>;
7474 $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?
3131 </div></fieldset>;
3232}
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 }) {
3535 const browse = () => {
3636 const [path, setPath] = createSignal(props.create && !props.value.endsWith("/") ? props.value.replace(/\/[^/]+$/, "") || props.root : props.value || props.root);
3737 showConfirmDialog({
......@@ -49,7 +49,7 @@ function FolderField(props: { value: string; root: string; create?: boolean; onC
4949 </Loaded>
5050 </div>;
5151 },
52 onConfirm: () => props.onChange(macPath(path(), props.root), true),
52 onConfirm: () => props.onChange(macPath(path(), props.root)),
5353 });
5454 };
5555 return <div class="field">folder<div class="share-folder-field">
......@@ -244,7 +244,6 @@ function LinkForm(props: { original?: SharedLink; fresh: boolean; state: ShareSt
244244 const [customPath, setCustomPath] = createSignal("");
245245 const path = () => customPath() || `${macPath(props.state.defaultRoot, props.state.root)}/${name().trim()}`;
246246 const [rights, setRights] = createSignal(props.original?.permissions ?? "r");
247 const [createFolder, setCreateFolder] = createSignal(true);
248247 const [password, setPassword] = createSignal<string | null>(null);
249248 const dateValue = (seconds: number) => {
250249 const date = new Date(seconds * 1000);
......@@ -261,7 +260,7 @@ function LinkForm(props: { original?: SharedLink; fresh: boolean; state: ShareSt
261260 const json = { name: name().trim(), path: props.original?.path ?? path(), permissions: rights(), expires: expires() ? new Date(expires()).getTime() / 1000 : 0, password: password() };
262261 const result = await parseResponse(props.original
263262 ? 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 }));
265264 const key = props.original?.key ?? result.links.find((link) => !props.state.links.some((old) => old.key === link.key))?.key;
266265 if (key) props.saved(result, key);
267266 setPassword(null);
......@@ -300,8 +299,7 @@ function LinkForm(props: { original?: SharedLink; fresh: boolean; state: ShareSt
300299 <fieldset disabled={pending()}>
301300 <label class="field">name<input class="search" required value={name()} placeholder="Name - Description" autocomplete="off" onInput={(event) => setName(event.currentTarget.value)} /></label>
302301 <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); }} />
304 <Checkbox checked={createFolder()} onChange={setCreateFolder}>create this folder</Checkbox>
302 <FolderField value={path()} root={props.state.root} create onChange={setCustomPath} />
305303 </Show>
306304 <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>
307305 <Rights value={rights()} onChange={setRights} link />
service/copyparty/manage.py+6-11
......@@ -24,7 +24,7 @@ ACTIONS = {
2424 'account.create': {'name'}, 'account.update': {'id', 'name'},
2525 'account.rotate': {'id'}, 'account.delete': {'id'},
2626 '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'},
2828 'link.update': {'key', 'name', 'path', 'permissions', 'expires', 'password', 'mode'},
2929 'link.delete': {'key'},
3030}
......@@ -285,7 +285,7 @@ class Manager:
285285 try:
286286 with urllib.request.urlopen(request, timeout=remaining(deadline, 30)) as response:
287287 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:
289289 raise Error(502, 'Copyparty did not confirm the update. Try again after checking the service.')
290290 except (urllib.error.URLError, TimeoutError):
291291 raise Error(502, 'Copyparty could not apply the update. Check the service and try again.') from None
......@@ -441,9 +441,7 @@ class Manager:
441441 password = old[1] if old is not None else ''
442442 else:
443443 password = self.hash(password)
444 create = action == 'link.create' and payload['createFolder'] is True
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.')
444 create = action == 'link.create'
447445 destination = payload['path']
448446 share_root = self.root / 'Share'
449447 if create and (not destination or Path(destination).parent == share_root or str(destination).startswith('/Volumes/clover/Share/')):
......@@ -461,12 +459,9 @@ class Manager:
461459 mode = payload.get('mode', 'retarget')
462460 if mode not in {'retarget', 'move'}:
463461 raise Error(400, 'Choose whether to move the folder or use another folder.')
464 if create:
465 try:
466 destination.mkdir(mode=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
462 if create and not destination.exists():
463 destination.mkdir(mode=0o775)
464 destination.chmod(0o775)
470465 owner = destination.parent.stat()
471466 os.chown(destination, owner.st_uid, owner.st_gid)
472467 self.undo.append(lambda: destination.rmdir())
tools/copyparty-test.py+10-2
......@@ -174,13 +174,21 @@ class Shares(unittest.TestCase):
174174 self.assertEqual(self.call('state')['links'][0]['path'], str(destination))
175175
176176 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='')
178178 path = self.root / 'Share/Clover - Example'
179179 self.assertTrue(path.is_dir())
180180 self.call('link.delete', key=result['links'][0]['key'])
181181 self.assertTrue(path.is_dir())
182182 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
184192 def test_move_preserves_key_selection_nested_links_and_grants(self):
185193 source = self.root / 'source'
186194 (source / 'nested').mkdir(parents=True)
......@@ -259,7 +267,7 @@ class Shares(unittest.TestCase):
259267 previous = os.umask(0o077)
260268 try:
261269 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='')
263271 finally:
264272 os.umask(previous)
265273 self.assertEqual((self.root / 'Share').stat().st_mode & 0o777, 0o775)