Skip to content

fix: deleteFolder in packageUpload uses fs.unlink instead of fs.rm#120

Open
tarone-saloni wants to merge 2 commits intometacall:masterfrom
tarone-saloni:fixIssue199
Open

fix: deleteFolder in packageUpload uses fs.unlink instead of fs.rm#120
tarone-saloni wants to merge 2 commits intometacall:masterfrom
tarone-saloni:fixIssue199

Conversation

@tarone-saloni
Copy link
Copy Markdown
Contributor

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.

  • fs.unlink(resource.path, error => {
  • fs.rm(resource.path, { recursive: true, force: true }, error => {
    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

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.

fix: deleteFolder in packageUpload uses fs.unlink instead of fs.rm

1 participant