fix: deleteFolder in packageUpload uses fs.unlink instead of fs.rm#120
Open
tarone-saloni wants to merge 2 commits intometacall:masterfrom
Open
fix: deleteFolder in packageUpload uses fs.unlink instead of fs.rm#120tarone-saloni wants to merge 2 commits intometacall:masterfrom
tarone-saloni wants to merge 2 commits intometacall:masterfrom
Conversation
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.
Problem
In src/controller/package.ts:170-183, the deleteFolder helper was calling fs.unlink(resource.path, callback) to clean up the application directory on upload failure.
fs.unlink is the POSIX unlink syscall — it operates on a single file inode and cannot remove a directory. On Linux/macOS it fails with EISDIR; on Windows with EPERM. The error was passed to errorHandler, which sent an error response to the client — but the directory itself was never deleted and remained on disk as an orphan. Any subsequent upload attempt with the same resource.id would then hit ensureFolderExists finding the folder already present, causing further failures.
Change
src/controller/package.ts
Replaced fs.unlink with fs.rm(..., { recursive: true, force: true }, callback) in deleteFolder only.
recursive: true — removes the directory and all its contents, matching the behavior already used in src/controller/delete.ts:44 and src/controller/repository.ts:37.
force: true — suppresses errors if the path does not exist (safe no-op, avoids a race condition where the directory was already cleaned up).
fs.rm with a callback is available since Node.js 14.14, which is within this project's supported range.
deleteBlob (lines 155–168) correctly uses fs.unlink since resource.blob is a file path — that was left unchanged.
Fixes #119