From c487b12518c4e6043809de539cbe0fad31f67b9d Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 16 Mar 2023 21:52:24 +0100 Subject: [PATCH] Reverted zip's root file copying fix refs https://github.com/TryGhost/Toolbox/issues/523 - The reverted fix did not take into account the "original path" of the files would be truncated. This path has to be full relative to the root of the zip to later be used during importer url substitution logic. - This reverts commit 831a76505cd95c55d973e6c5c53acf0d8ddb02a8. --- .../core/server/data/importer/import-manager.js | 9 +-------- .../test/unit/server/data/importer/index.test.js | 2 +- .../{images => }/image.JPG | 0 .../test/ImporterContentFileHandler.test.js | 16 ++++------------ 4 files changed, 6 insertions(+), 21 deletions(-) rename ghost/core/test/utils/fixtures/import/zips/zip-uppercase-extensions/{images => }/image.JPG (100%) diff --git a/ghost/core/core/server/data/importer/import-manager.js b/ghost/core/core/server/data/importer/import-manager.js index 6de8825c73..a7b0053564 100644 --- a/ghost/core/core/server/data/importer/import-manager.js +++ b/ghost/core/core/server/data/importer/import-manager.js @@ -301,14 +301,7 @@ class ImportManager { const baseDir = this.getBaseDirectory(zipDirectory); for (const handler of this.handlers) { - let files = []; - if (handler.directories?.length > 0) { - for (const dir of handler.directories) { - files.push(...this.getFilesFromZip(handler, path.join(zipDirectory, (baseDir || ''), dir))); - } - } else { - files.push(...this.getFilesFromZip(handler, zipDirectory)); - } + const files = this.getFilesFromZip(handler, zipDirectory); debug('handler', handler.type, files); diff --git a/ghost/core/test/unit/server/data/importer/index.test.js b/ghost/core/test/unit/server/data/importer/index.test.js index b3e837c819..a95569465a 100644 --- a/ghost/core/test/unit/server/data/importer/index.test.js +++ b/ghost/core/test/unit/server/data/importer/index.test.js @@ -228,7 +228,7 @@ describe('Importer', function () { extractSpy.calledOnce.should.be.true(); validSpy.calledOnce.should.be.true(); baseDirSpy.calledOnce.should.be.true(); - getFileSpy.callCount.should.eql(9); + getFileSpy.callCount.should.eql(6); jsonSpy.calledOnce.should.be.true(); imageSpy.called.should.be.false(); mdSpy.called.should.be.false(); diff --git a/ghost/core/test/utils/fixtures/import/zips/zip-uppercase-extensions/images/image.JPG b/ghost/core/test/utils/fixtures/import/zips/zip-uppercase-extensions/image.JPG similarity index 100% rename from ghost/core/test/utils/fixtures/import/zips/zip-uppercase-extensions/images/image.JPG rename to ghost/core/test/utils/fixtures/import/zips/zip-uppercase-extensions/image.JPG diff --git a/ghost/importer-handler-content-files/test/ImporterContentFileHandler.test.js b/ghost/importer-handler-content-files/test/ImporterContentFileHandler.test.js index d0c842dfd7..aefbe872de 100644 --- a/ghost/importer-handler-content-files/test/ImporterContentFileHandler.test.js +++ b/ghost/importer-handler-content-files/test/ImporterContentFileHandler.test.js @@ -52,24 +52,16 @@ describe('ImporterContentFileHandler', function () { }); const files = [{ - name: 'content/media/video-in-content-media.mp4' - }, { - name: 'media/video-in-media.mp4' + name: 'content/media/1.mp4' }]; const subDir = 'blog'; await contentFileImporter.loadFile(files, subDir); - assert.equal(files.length, 2); - assert.equal(files[0].name, 'video-in-content-media.mp4'); - assert.equal(files[0].originalPath, 'content/media/video-in-content-media.mp4'); + assert.equal(files[0].name, '1.mp4'); + assert.equal(files[0].originalPath, 'content/media/1.mp4'); assert.equal(files[0].targetDir, '/var/www/ghost/content/media'); - assert.equal(files[0].newPath, '//blog/content/media/video-in-content-media.mp4'); - - assert.equal(files[1].name, 'video-in-media.mp4'); - assert.equal(files[1].originalPath, 'media/video-in-media.mp4'); - assert.equal(files[1].targetDir, '/var/www/ghost/content/media'); - assert.equal(files[1].newPath, '//blog/content/media/video-in-media.mp4'); + assert.equal(files[0].newPath, '//blog/content/media/1.mp4'); }); it('loads files and decorates them with newPath with NO subdirectory', async function () {