Merge pull request #16553 from strapi/fix/protect-assets-backup

This commit is contained in:
Christian 2023-04-28 17:17:23 +02:00 committed by GitHub
commit af7b42e8d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -727,6 +727,9 @@ class TransferEngine<
async transferAssets(): Promise<void> {
const stage: TransferStage = 'assets';
if (this.shouldSkipStage(stage)) {
return;
}
const source = await this.sourceProvider.createAssetsReadStream?.();
const destination = await this.destinationProvider.createAssetsWriteStream?.();

View File

@ -156,10 +156,16 @@ class LocalStrapiDestinationProvider implements IDestinationProvider {
`uploads_backup_${Date.now()}`
);
await fse.move(assetsDirectory, backupDirectory);
await fse.mkdir(assetsDirectory);
// Create a .gitkeep file to ensure the directory is not empty
await fse.outputFile(path.join(assetsDirectory, '.gitkeep'), '');
try {
await fse.move(assetsDirectory, backupDirectory);
await fse.mkdir(assetsDirectory);
// Create a .gitkeep file to ensure the directory is not empty
await fse.outputFile(path.join(assetsDirectory, '.gitkeep'), '');
} catch (err) {
throw new ProviderTransferError(
'The backup folder for the assets could not be created inside the public folder. Please ensure Strapi has write permissions on the public directory'
);
}
return new Writable({
objectMode: true,