delete: transaction
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-10-17 13:13:14 +02:00
parent 42583a4a16
commit e6481af3a9
1 changed files with 33 additions and 44 deletions

View File

@ -17,18 +17,11 @@ module.exports = Self => {
});
Self.deleteTrashFiles = async options => {
let tx;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
if (process.env.NODE_ENV == 'test')
throw new UserError(`Action not allowed on the test environment`);
@ -63,15 +56,11 @@ module.exports = Self => {
const dstFolder = path.join(dmsContainer.client.root, pathHash);
try {
await fs.rmdir(dstFolder);
} catch (err) {}
} catch (err) {
continue;
}
await dms.destroy(myOptions);
}
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};