mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Merge pull request #5027 from felixrieseberg/iss4847
Replace fs.exists (deprecated) with fs.stat
This commit is contained in:
commit
61b86bf821
7 changed files with 35 additions and 28 deletions
|
@ -15,9 +15,9 @@ AppDependencies.prototype.install = function installAppDependencies() {
|
|||
self = this;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
fs.exists(path.join(self.appPath, 'package.json'), function (exists) {
|
||||
if (!exists) {
|
||||
// Nothing to do, resolve right away?
|
||||
fs.stat(path.join(self.appPath, 'package.json'), function (err) {
|
||||
if (err) {
|
||||
// File doesn't exist - nothing to do, resolve right away?
|
||||
resolve();
|
||||
} else {
|
||||
// Run npm install in the app directory
|
||||
|
|
|
@ -37,7 +37,8 @@ AppPermissions.prototype.checkPackageContentsExists = function () {
|
|||
|
||||
// Mostly just broken out for stubbing in unit tests
|
||||
return new Promise(function (resolve) {
|
||||
fs.exists(self.packagePath, function (exists) {
|
||||
fs.stat(self.packagePath, function (err) {
|
||||
var exists = !err;
|
||||
resolve(exists);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -227,8 +227,9 @@ ConfigManager.prototype.load = function (configFilePath) {
|
|||
/* Check for config file and copy from config.example.js
|
||||
if one doesn't exist. After that, start the server. */
|
||||
return new Promise(function (resolve, reject) {
|
||||
fs.exists(self._config.paths.config, function (exists) {
|
||||
var pendingConfig;
|
||||
fs.stat(self._config.paths.config, function (err) {
|
||||
var exists = (err) ? false : true,
|
||||
pendingConfig;
|
||||
|
||||
if (!exists) {
|
||||
pendingConfig = self.writeFile();
|
||||
|
@ -250,8 +251,9 @@ ConfigManager.prototype.writeFile = function () {
|
|||
configExamplePath = this._config.paths.configExample;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
fs.exists(configExamplePath, function checkTemplate(templateExists) {
|
||||
var read,
|
||||
fs.stat(configExamplePath, function checkTemplate(err) {
|
||||
var templateExists = (err) ? false : true,
|
||||
read,
|
||||
write,
|
||||
error;
|
||||
|
||||
|
|
|
@ -82,11 +82,14 @@ function builtFilesExist() {
|
|||
'\nhttps://github.com/TryGhost/Ghost#getting-started';
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
fs.exists(fileName, function (exists) {
|
||||
fs.stat(fileName, function (statErr) {
|
||||
var exists = (statErr) ? false : true,
|
||||
err;
|
||||
|
||||
if (exists) {
|
||||
resolve(true);
|
||||
} else {
|
||||
var err = new Error(errorMessage);
|
||||
err = new Error(errorMessage);
|
||||
|
||||
err.help = errorHelp;
|
||||
reject(err);
|
||||
|
|
|
@ -42,7 +42,8 @@ LocalFileStore.prototype.save = function (image, targetDir) {
|
|||
|
||||
LocalFileStore.prototype.exists = function (filename) {
|
||||
return new Promise(function (resolve) {
|
||||
fs.exists(filename, function (exists) {
|
||||
fs.stat(filename, function (err) {
|
||||
var exists = !err;
|
||||
resolve(exists);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -328,7 +328,7 @@ describe('Config', function () {
|
|||
|
||||
it('creates the config file if one does not exist', function (done) {
|
||||
// trick bootstrap into thinking that the config file doesn't exist yet
|
||||
var existsStub = sandbox.stub(fs, 'exists', function (file, cb) { return cb(false); }),
|
||||
var existsStub = sandbox.stub(fs, 'stat', function (file, cb) { return cb(true); }),
|
||||
// ensure that the file creation is a stub, the tests shouldn't really create a file
|
||||
writeFileStub = sandbox.stub(config, 'writeFile').returns(Promise.resolve()),
|
||||
validateStub = sandbox.stub(config, 'validate').returns(Promise.resolve());
|
||||
|
|
|
@ -27,7 +27,7 @@ describe('Local File System Storage', function () {
|
|||
|
||||
sinon.stub(fs, 'mkdirs').yields();
|
||||
sinon.stub(fs, 'copy').yields();
|
||||
sinon.stub(fs, 'exists').yields(false);
|
||||
sinon.stub(fs, 'stat').yields(true);
|
||||
sinon.stub(fs, 'unlink').yields();
|
||||
|
||||
image = {
|
||||
|
@ -45,7 +45,7 @@ describe('Local File System Storage', function () {
|
|||
afterEach(function () {
|
||||
fs.mkdirs.restore();
|
||||
fs.copy.restore();
|
||||
fs.exists.restore();
|
||||
fs.stat.restore();
|
||||
fs.unlink.restore();
|
||||
this.clock.restore();
|
||||
});
|
||||
|
@ -96,13 +96,13 @@ describe('Local File System Storage', function () {
|
|||
it('can upload two different images with the same name without overwriting the first', function (done) {
|
||||
// Sun Sep 08 2013 10:57
|
||||
this.clock = sinon.useFakeTimers(new Date(2013, 8, 8, 10, 57).getTime());
|
||||
fs.exists.withArgs(path.resolve('./content/images/2013/09/IMAGE.jpg')).yields(true);
|
||||
fs.exists.withArgs(path.resolve('./content/images/2013/09/IMAGE-1.jpg')).yields(false);
|
||||
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE.jpg')).yields(false);
|
||||
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE-1.jpg')).yields(true);
|
||||
|
||||
// if on windows need to setup with back slashes
|
||||
// doesn't hurt for the test to cope with both
|
||||
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE.jpg')).yields(true);
|
||||
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-1.jpg')).yields(false);
|
||||
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE.jpg')).yields(false);
|
||||
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-1.jpg')).yields(true);
|
||||
|
||||
localFileStore.save(image).then(function (url) {
|
||||
url.should.equal('/content/images/2013/09/IMAGE-1.jpg');
|
||||
|
@ -113,18 +113,18 @@ describe('Local File System Storage', function () {
|
|||
it('can upload five different images with the same name without overwriting the first', function (done) {
|
||||
// Sun Sep 08 2013 10:57
|
||||
this.clock = sinon.useFakeTimers(new Date(2013, 8, 8, 10, 57).getTime());
|
||||
fs.exists.withArgs(path.resolve('./content/images/2013/09/IMAGE.jpg')).yields(true);
|
||||
fs.exists.withArgs(path.resolve('./content/images/2013/09/IMAGE-1.jpg')).yields(true);
|
||||
fs.exists.withArgs(path.resolve('./content/images/2013/09/IMAGE-2.jpg')).yields(true);
|
||||
fs.exists.withArgs(path.resolve('./content/images/2013/09/IMAGE-3.jpg')).yields(true);
|
||||
fs.exists.withArgs(path.resolve('./content/images/2013/09/IMAGE-4.jpg')).yields(false);
|
||||
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE.jpg')).yields(false);
|
||||
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE-1.jpg')).yields(false);
|
||||
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE-2.jpg')).yields(false);
|
||||
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE-3.jpg')).yields(false);
|
||||
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE-4.jpg')).yields(true);
|
||||
|
||||
// windows setup
|
||||
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE.jpg')).yields(true);
|
||||
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-1.jpg')).yields(true);
|
||||
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-2.jpg')).yields(true);
|
||||
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-3.jpg')).yields(true);
|
||||
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-4.jpg')).yields(false);
|
||||
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE.jpg')).yields(false);
|
||||
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-1.jpg')).yields(false);
|
||||
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-2.jpg')).yields(false);
|
||||
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-3.jpg')).yields(false);
|
||||
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-4.jpg')).yields(true);
|
||||
|
||||
localFileStore.save(image).then(function (url) {
|
||||
url.should.equal('/content/images/2013/09/IMAGE-4.jpg');
|
||||
|
|
Loading…
Add table
Reference in a new issue