diff --git a/packages/core/data-transfer/lib/engine/index.ts b/packages/core/data-transfer/lib/engine/index.ts index f40c7b61fb..a8b4e4d1de 100644 --- a/packages/core/data-transfer/lib/engine/index.ts +++ b/packages/core/data-transfer/lib/engine/index.ts @@ -159,7 +159,7 @@ class TransferEngine< }); } - #emitTransferUpdate(type: 'start' | 'finish' | 'error', payload?: object) { + #emitTransferUpdate(type: 'init' | 'start' | 'finish' | 'error', payload?: object) { this.progress.stream.emit(`transfer::${type}`, payload); } @@ -336,9 +336,8 @@ class TransferEngine< // reset data between transfers this.progress.data = {}; - this.#emitTransferUpdate('start'); - try { + this.#emitTransferUpdate('init'); await this.bootstrap(); await this.init(); @@ -351,6 +350,8 @@ class TransferEngine< ); } + this.#emitTransferUpdate('start'); + await this.beforeTransfer(); // Run the transfer stages diff --git a/packages/core/data-transfer/lib/providers/local-file-source-provider/index.ts b/packages/core/data-transfer/lib/providers/local-file-source-provider/index.ts index 8904817982..ff078043dd 100644 --- a/packages/core/data-transfer/lib/providers/local-file-source-provider/index.ts +++ b/packages/core/data-transfer/lib/providers/local-file-source-provider/index.ts @@ -49,6 +49,8 @@ class LocalFileSourceProvider implements ISourceProvider { options: ILocalFileSourceProviderOptions; + #metadata?: IMetadata; + constructor(options: ILocalFileSourceProviderOptions) { this.options = options; @@ -60,15 +62,16 @@ class LocalFileSourceProvider implements ISourceProvider { } /** - * Pre flight checks regarding the provided options (making sure that the provided path is correct, etc...) + * Pre flight checks regarding the provided options, making sure that the file can be opened (decrypted, decompressed), etc. */ async bootstrap() { const { path: filePath } = this.options.file; + try { - // This is only to show a nicer error, it doesn't ensure the file will still exist when we try to open it later - await fs.access(filePath, fs.constants.R_OK); + // Read the metadata to ensure the file can be parsed + this.#metadata = await this.getMetadata(); } catch (e) { - throw new Error(`Can't access file "${filePath}".`); + throw new Error(`Can't read file "${filePath}".`); } } diff --git a/packages/core/strapi/lib/commands/transfer/export.js b/packages/core/strapi/lib/commands/transfer/export.js index e0c0de6d79..7c3a017063 100644 --- a/packages/core/strapi/lib/commands/transfer/export.js +++ b/packages/core/strapi/lib/commands/transfer/export.js @@ -74,8 +74,6 @@ module.exports = async (opts) => { }, }); - logger.log(`Starting export...`); - const progress = engine.progress.stream; const getTelemetryPayload = (/* payload */) => { @@ -88,6 +86,7 @@ module.exports = async (opts) => { }; progress.on('transfer::start', async () => { + logger.log(`Starting export...`); await strapi.telemetry.send('didDEITSProcessStart', getTelemetryPayload()); }); diff --git a/packages/core/strapi/lib/commands/transfer/import.js b/packages/core/strapi/lib/commands/transfer/import.js index 2140f56ece..4bb3e4a63e 100644 --- a/packages/core/strapi/lib/commands/transfer/import.js +++ b/packages/core/strapi/lib/commands/transfer/import.js @@ -77,9 +77,8 @@ module.exports = async (opts) => { ], }, }; - const engine = createTransferEngine(source, destination, engineOptions); - logger.info('Starting import...'); + const engine = createTransferEngine(source, destination, engineOptions); const progress = engine.progress.stream; const getTelemetryPayload = () => { @@ -92,6 +91,7 @@ module.exports = async (opts) => { }; progress.on('transfer::start', async () => { + logger.info('Starting import...'); await strapiInstance.telemetry.send('didDEITSProcessStart', getTelemetryPayload()); });