improve filename generation and conflict handling#3380
Merged
ComputelessComputer merged 4 commits intomainfrom Jan 26, 2026
Merged
improve filename generation and conflict handling#3380ComputelessComputer merged 4 commits intomainfrom
ComputelessComputer merged 4 commits intomainfrom
Conversation
❌ Deploy Preview for hyprnote failed.
|
✅ Deploy Preview for howto-fix-macos-audio-selection canceled.
|
✅ Deploy Preview for hyprnote-storybook canceled.
|
2fdf623 to
e82b92c
Compare
Refactor file upload mechanism to generate more readable filenames, prevent special characters, and handle potential filename conflicts by appending a numeric suffix when needed.
4c67a67 to
538c2ac
Compare
Comment on lines
+334
to
+348
| for (const filePath of allFiles) { | ||
| const relativePath = filePath.substring(fromPath.length); | ||
| const newFilePath = toPath + relativePath; | ||
|
|
||
| const { error } = await supabase.storage | ||
| .from(BUCKET_NAME) | ||
| .move(filePath, newFilePath); | ||
|
|
||
| if (error) { | ||
| return { | ||
| success: false, | ||
| error: `Failed to move ${filePath}: ${error.message}`, | ||
| }; | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Partial failure leaves folder in inconsistent state
When moving a folder with multiple files, if any file move operation fails, some files will have been moved while others remain in the original location. There's no transaction or rollback mechanism, leaving the folder structure corrupted.
for (const filePath of allFiles) {
const relativePath = filePath.substring(fromPath.length);
const newFilePath = toPath + relativePath;
const { error } = await supabase.storage
.from(BUCKET_NAME)
.move(filePath, newFilePath);
if (error) {
return {
success: false,
error: `Failed to move ${filePath}: ${error.message}`,
};
}
}Implement a rollback mechanism or use a transaction-like approach to move all files atomically, or at least document this limitation to users.
Suggested change
| for (const filePath of allFiles) { | |
| const relativePath = filePath.substring(fromPath.length); | |
| const newFilePath = toPath + relativePath; | |
| const { error } = await supabase.storage | |
| .from(BUCKET_NAME) | |
| .move(filePath, newFilePath); | |
| if (error) { | |
| return { | |
| success: false, | |
| error: `Failed to move ${filePath}: ${error.message}`, | |
| }; | |
| } | |
| } | |
| // First phase: collect all move operations to perform | |
| const moveOperations = allFiles.map(filePath => { | |
| const relativePath = filePath.substring(fromPath.length); | |
| const newFilePath = toPath + relativePath; | |
| return { source: filePath, destination: newFilePath }; | |
| }); | |
| // Second phase: execute all moves | |
| const movedFiles = []; | |
| for (const { source, destination } of moveOperations) { | |
| const { error } = await supabase.storage | |
| .from(BUCKET_NAME) | |
| .move(source, destination); | |
| if (error) { | |
| // Rollback: move all previously moved files back to their original locations | |
| for (const { source: origSrc, destination: origDest } of movedFiles) { | |
| await supabase.storage | |
| .from(BUCKET_NAME) | |
| .move(origDest, origSrc); // Move back (ignoring errors during rollback) | |
| } | |
| return { | |
| success: false, | |
| error: `Failed to move ${source}: ${error.message}. All operations have been rolled back.`, | |
| }; | |
| } | |
| movedFiles.push({ source, destination }); | |
| } |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
This comment came from an experimental review—please leave feedback if it was helpful/unhelpful. Learn more about experimental comments here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactor file upload mechanism to generate more readable filenames, prevent special characters, and handle potential filename conflicts by appending a numeric suffix when needed.
Review & Testing Checklist for Human
CON,NUL,AUXon Windows), zero-width characters, names consisting entirely of dots or spaces — and verify each produces a valid, non-empty filename-1instead of-1and-2)Suggested test plan: Upload files with a variety of names: normal (
report.pdf), special chars (my file (final) [v2].pdf), unicode (レポート.pdf), empty-ish (. .pdf), and duplicates. Verify each stored filename is valid, readable, and unique.Notes
Link to Devin run: https://app.devin.ai/sessions/1b9ae9acc87349e393883ca54ed961c6
Requested by: @ComputelessComputer