Skip to content

Commit

Permalink
Resolves no such file error when deleting item (#8239)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Calder authored Jan 11, 2023
1 parent bfc3596 commit ebd7259
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-poets-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': patch
---

Resolves error when deleting an item that has a file or image that is no longer on the filesystem
20 changes: 18 additions & 2 deletions packages/core/src/lib/assets/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ export function localImageAssetsAPI(
await fs.writeFile(path.join(storageConfig.storagePath, `${id}.${extension}`), buffer);
},
async delete(id, extension) {
await fs.unlink(path.join(storageConfig.storagePath, `${id}.${extension}`));
try {
await fs.unlink(path.join(storageConfig.storagePath, `${id}.${extension}`));
} catch (e) {
const error = e as NodeJS.ErrnoException;
// If the file doesn't exist, we don't care
if (error.code !== 'ENOENT') {
throw e;
}
}
},
};
}
Expand Down Expand Up @@ -51,7 +59,15 @@ export function localFileAssetsAPI(storageConfig: StorageConfig & { kind: 'local
}
},
async delete(filename) {
await fs.unlink(path.join(storageConfig.storagePath, filename));
try {
await fs.unlink(path.join(storageConfig.storagePath, filename));
} catch (e) {
const error = e as NodeJS.ErrnoException;
// If the file doesn't exist, we don't care
if (error.code !== 'ENOENT') {
throw e;
}
}
},
};
}

1 comment on commit ebd7259

@vercel
Copy link

@vercel vercel bot commented on ebd7259 Jan 11, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.