Skip to content

90 uploading same file - #95

Open
PreciousOritsedere wants to merge 10 commits into
mainfrom
90-uploading-same-file
Open

PreciousOritsedere wants to merge 10 commits into
mainfrom
90-uploading-same-file

Conversation

@PreciousOritsedere

Copy link
Copy Markdown
Contributor

This PR addresse this issue #90

@vercel

vercel Bot commented Sep 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
solid-file-manager Ready Ready Preview Sep 18, 2026 2:50pm UTC

@github-actions

github-actions Bot commented Sep 17, 2026

Copy link
Copy Markdown

@jeswr jeswr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here is a lot more network heavy than it needs to be. I would rather suggest an approach of:

    1. Check against the container metadata (which you should already have cached) for conflicting names. Use this to trigger the dialogue if there are.
    1. For keepBoth cases, and cases where a conflict was not discovered from the container metadata - use the writeFile rather than overwriteFile method. This will throw if a conflict does appear. If writeFile does throw then keep iterating looking for a new file name that does not conflict with one listed in the container metadata - once we new non-conflicting name is found try writeFile again. Repeat until writeFile succeeds; or fails with an error code unrelated to naming conflicts.

Comment thread app/lib/helpers/uploadUtils.ts Outdated
let keepBothUrl = "";
let displayName = "";

for (let attempt = 1; attempt < 100; attempt++) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100 is an arbitrary limit - just use a while loop so there is no arbitrary cap

Comment thread app/lib/helpers/uploadUtils.ts Outdated
displayName = `${base} (${attempt})${ext}`;
const candidateName = sanitizeFilename(displayName);
keepBothUrl = buildFileTargetUrl(currentContainerUrl, candidateName);
const exists = await resourceExists(keepBothUrl, fetchFn);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not need to do a network request here - as you have already fetched the parent which lists the identifiers of all the child resources - use that data instead.

Comment thread app/lib/helpers/uploadUtils.ts Outdated
Comment on lines +98 to +100
if (attempt === 99) {
throw new Error("Unable to generate a unique name for the upload");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove - 100 limit is arbitrary

Comment thread app/lib/helpers/uploadUtils.ts Outdated
Comment on lines +103 to +106
await overwriteFile(keepBothUrl as UrlString, file, {
contentType: file.type || "application/octet-stream",
fetch: fetchFn,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overwriteFile should NOT be used for a keepBoth operation - use putFile instead.

Under race conditions it is possible that another resource of the same name has been put in the Pod at this point. If that happens we want this function to error - and for you to go back to the while loop above to keep trying to find an unused file name.

@PreciousOritsedere

PreciousOritsedere commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

@jeswr I have addressed your review with these commits:

solid-client doesn’t expose a create-only write (only overwriteFile, which replaces if the name exists), so i had to create the putFile helper function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uploading same file twice

2 participants