Skip to content

Commit

Permalink
revert writing / retrieving public files from tmp dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mike182uk committed Dec 13, 2024
1 parent 496bb44 commit 7960d6b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 48 deletions.
20 changes: 1 addition & 19 deletions ghost/core/core/shared/config/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,6 @@ const isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) {
return this.get('privacy')[privacyFlag] === false;
};

/** @type {string|null} */
let processTmpDirPath = null;

/**
* Get a tmp dir path for the current process
*
* @returns {string} - tmp dir path for the current process
*/
function getProcessTmpDirPath() {
// Memoize the computed path to avoid re-computing it on each call - The
// value should not change during the lifetime of the process.
if (processTmpDirPath === null) {
processTmpDirPath = path.join(os.tmpdir(), `ghost_${crypto.randomUUID()}`);
}

return processTmpDirPath;
}

/**
* @callback getContentPathFn
* @param {string} type - the type of context you want the path for
Expand All @@ -108,7 +90,7 @@ const getContentPath = function getContentPath(type) {
case 'settings':
return path.join(this.get('paths:contentPath'), 'settings/');
case 'public':
return path.join(getProcessTmpDirPath(this), 'public/');
return path.join(this.get('paths:contentPath'), 'public/');
default:
// new Error is allowed here, as we do not want config to depend on @tryghost/error
// @TODO: revisit this decision when @tryghost/error is no longer dependent on all of ghost-ignition
Expand Down
29 changes: 0 additions & 29 deletions ghost/core/test/unit/shared/config/helpers.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const os = require('os');
const should = require('should');

const configUtils = require('../../../utils/configUtils');

const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;

describe('vhost utils', function () {
beforeEach(function () {
configUtils.set('url', 'http://ghost.blog');
Expand Down Expand Up @@ -56,29 +53,3 @@ describe('vhost utils', function () {
});
});
});

describe('getContentPath', function () {
it('should return the correct path for type: public', function () {
const publicPath = configUtils.config.getContentPath('public');

// Path should be in the tmpdir
const tmpdir = os.tmpdir();

publicPath.startsWith(tmpdir).should.be.true();

// Path should end with /public/
publicPath.endsWith('/public/').should.be.true();

// Path should include /ghost_
publicPath.includes('/ghost_').should.be.true();

// Path should contain a uuid at the correct location
const publicPathParts = publicPath.split('/');
const uuidPart = publicPathParts[publicPathParts.length - 3].replace('ghost_', '');

UUID_REGEX.test(uuidPart).should.be.true();

// Path should be memoized
configUtils.config.getContentPath('public').should.eql(publicPath);
});
});

0 comments on commit 7960d6b

Please sign in to comment.