Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/main_endpoints/util/Printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function cleanUpChunks(dir, id) {
for (let chunk of chunks) {
if (!path.basename(chunk).includes(id)) continue;

await fs.promises.unlink(path.join(dir, chunk), err => {
await fs.promises.unlink(path.join(dir, chunk)).catch(err => {
logger.error(`Failed to delete chunk with id ${id} in ${dir}: ` + err);
});
}
Expand Down Expand Up @@ -43,7 +43,7 @@ async function cleanUpExpiredChunks(dir, expiry) {
const age = Date.now() - stats.mtimeMs;

if (age >= expiry) {
await fs.promises.unlink(path.join(dir, chunk), err => {
await fs.promises.unlink(path.join(dir, chunk)).catch(err => {
logger.warn(`Failed to delete expired chunk in ${dir}: ` + err);
});

Expand Down
2 changes: 2 additions & 0 deletions test/api/Printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ describe('Printer', () => {
const MY_BIRTH_DATE = new Date('December 4, 2005 07:53:00');

it('Should delete expired chunks (5 minutes or older)', async () => {
// Clean up any pre-existing expired chunks from previous runs
await printerUtil.cleanUpExpiredChunks(CHUNK_DIRECTORY, 0);
const dirBefore = await fs.promises.readdir(CHUNK_DIRECTORY);
const numFilesBefore = dirBefore.length;

Expand Down
Loading