remove stat test for missing files
This commit is contained in:
@@ -4,7 +4,6 @@ logger = require "logger-sharelatex"
|
|||||||
settings = require("settings-sharelatex")
|
settings = require("settings-sharelatex")
|
||||||
Errors = require "./Errors"
|
Errors = require "./Errors"
|
||||||
SafeReader = require "./SafeReader"
|
SafeReader = require "./SafeReader"
|
||||||
async = require "async"
|
|
||||||
|
|
||||||
module.exports = ResourceStateManager =
|
module.exports = ResourceStateManager =
|
||||||
|
|
||||||
@@ -61,21 +60,9 @@ module.exports = ResourceStateManager =
|
|||||||
seenFile = {}
|
seenFile = {}
|
||||||
for file in allFiles
|
for file in allFiles
|
||||||
seenFile[file] = true
|
seenFile[file] = true
|
||||||
missingFileCandidates = (resource.path for resource in resources when not seenFile[resource.path])
|
missingFiles = (resource.path for resource in resources when not seenFile[resource.path])
|
||||||
# now check if they are really missing
|
if missingFiles?.length > 0
|
||||||
ResourceStateManager._checkMissingFiles missingFileCandidates, basePath, (missingFiles) ->
|
logger.err missingFiles:missingFiles, basePath:basePath, allFiles:allFiles, resources:resources, "missing input files for project"
|
||||||
if missingFiles?.length > 0
|
return callback new Errors.FilesOutOfSyncError("resource files missing in incremental update")
|
||||||
logger.err missingFiles:missingFiles, basePath:basePath, allFiles:allFiles, resources:resources, "missing input files for project"
|
|
||||||
return callback new Errors.FilesOutOfSyncError("resource files missing in incremental update")
|
|
||||||
else
|
|
||||||
callback()
|
|
||||||
|
|
||||||
_checkMissingFiles: (missingFileCandidates, basePath, callback = (missingFiles) ->) ->
|
|
||||||
if missingFileCandidates.length > 0
|
|
||||||
fileDoesNotExist = (file, cb) ->
|
|
||||||
fs.stat Path.join(basePath, file), (err) ->
|
|
||||||
logger.log file:file, err:err, result: err?, "stating potential missing file"
|
|
||||||
cb(err?)
|
|
||||||
async.filterSeries missingFileCandidates, fileDoesNotExist, callback
|
|
||||||
else
|
else
|
||||||
callback([])
|
callback()
|
||||||
|
|||||||
@@ -88,27 +88,12 @@ describe "ResourceStateManager", ->
|
|||||||
it "should call the callback", ->
|
it "should call the callback", ->
|
||||||
@callback.calledWithExactly().should.equal true
|
@callback.calledWithExactly().should.equal true
|
||||||
|
|
||||||
describe "when there is a file missing from the outputFileFinder but present on disk", ->
|
|
||||||
beforeEach ->
|
|
||||||
@allFiles = [ @resources[0].path, @resources[1].path]
|
|
||||||
@fs.stat = sinon.stub().callsArg(1)
|
|
||||||
@ResourceStateManager.checkResourceFiles(@resources, @allFiles, @basePath, @callback)
|
|
||||||
|
|
||||||
it "should stat the file to see if it is present", ->
|
|
||||||
@fs.stat.called.should.equal true
|
|
||||||
|
|
||||||
it "should call the callback", ->
|
|
||||||
@callback.calledWithExactly().should.equal true
|
|
||||||
|
|
||||||
describe "when there is a missing file", ->
|
describe "when there is a missing file", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@allFiles = [ @resources[0].path, @resources[1].path]
|
@allFiles = [ @resources[0].path, @resources[1].path]
|
||||||
@fs.stat = sinon.stub().callsArgWith(1, new Error())
|
@fs.stat = sinon.stub().callsArgWith(1, new Error())
|
||||||
@ResourceStateManager.checkResourceFiles(@resources, @allFiles, @basePath, @callback)
|
@ResourceStateManager.checkResourceFiles(@resources, @allFiles, @basePath, @callback)
|
||||||
|
|
||||||
it "should stat the file to see if it is present", ->
|
|
||||||
@fs.stat.called.should.equal true
|
|
||||||
|
|
||||||
it "should call the callback with an error", ->
|
it "should call the callback with an error", ->
|
||||||
error = new Errors.FilesOutOfSyncError("resource files missing in incremental update")
|
error = new Errors.FilesOutOfSyncError("resource files missing in incremental update")
|
||||||
@callback.calledWith(error).should.equal true
|
@callback.calledWith(error).should.equal true
|
||||||
|
|||||||
Reference in New Issue
Block a user