From 1b8a5a7866f340a92714d1b85ebb45def8d2ea29 Mon Sep 17 00:00:00 2001 From: Christian Capeans Date: Thu, 27 Apr 2023 14:06:30 +0200 Subject: [PATCH 1/5] Improve error when assets backup folder cannot be created --- .../src/strapi/providers/local-destination/index.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts b/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts index f8a5dc0e50..081697d4d2 100644 --- a/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts +++ b/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts @@ -156,10 +156,14 @@ 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.'); + } return new Writable({ objectMode: true, From fff1cd39332b42d8d92b949b7ea1d5fbffdbf009 Mon Sep 17 00:00:00 2001 From: Christian Capeans Date: Thu, 27 Apr 2023 22:07:19 +0200 Subject: [PATCH 2/5] Avoid creating the backup folder if assets are not transfered --- packages/core/data-transfer/src/engine/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/core/data-transfer/src/engine/index.ts b/packages/core/data-transfer/src/engine/index.ts index 4ab7aaf028..261c3e3915 100644 --- a/packages/core/data-transfer/src/engine/index.ts +++ b/packages/core/data-transfer/src/engine/index.ts @@ -727,6 +727,9 @@ class TransferEngine< async transferAssets(): Promise { const stage: TransferStage = 'assets'; + if (this.shouldSkipStage(stage)) { + return; + } const source = await this.sourceProvider.createAssetsReadStream?.(); const destination = await this.destinationProvider.createAssetsWriteStream?.(); From 1b52da5cd7c29e8904b15d672521c3bad62ccfd2 Mon Sep 17 00:00:00 2001 From: Christian Capeans Date: Fri, 28 Apr 2023 13:19:14 +0200 Subject: [PATCH 3/5] Improve error message --- .../src/strapi/providers/local-destination/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts b/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts index 081697d4d2..3d49cc85f5 100644 --- a/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts +++ b/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts @@ -162,7 +162,9 @@ class LocalStrapiDestinationProvider implements IDestinationProvider { // 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.'); + throw new ProviderTransferError( + 'The backup folder for the assets could not be created inside the public directory.' + ); } return new Writable({ From 890169a17f1d5f1d2f98dc7cde3f0f9f4fdc3f73 Mon Sep 17 00:00:00 2001 From: Christian Capeans Date: Fri, 28 Apr 2023 14:54:53 +0200 Subject: [PATCH 4/5] Improve error message --- .../src/strapi/providers/local-destination/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts b/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts index 3d49cc85f5..7d8e56d070 100644 --- a/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts +++ b/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts @@ -163,7 +163,7 @@ class LocalStrapiDestinationProvider implements IDestinationProvider { 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 directory.' + 'The backup folder for the assets could not be created inside the public folder. Please, ensure Strapi has write permissions on the public directory' ); } From a8924d2ce6e746852865cbb4bddff49021873076 Mon Sep 17 00:00:00 2001 From: Christian Capeans Date: Fri, 28 Apr 2023 14:59:50 +0200 Subject: [PATCH 5/5] Remove unnecessary comma --- .../src/strapi/providers/local-destination/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts b/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts index 7d8e56d070..a5555dc3aa 100644 --- a/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts +++ b/packages/core/data-transfer/src/strapi/providers/local-destination/index.ts @@ -163,7 +163,7 @@ class LocalStrapiDestinationProvider implements IDestinationProvider { 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' + 'The backup folder for the assets could not be created inside the public folder. Please ensure Strapi has write permissions on the public directory' ); }