diff --git a/services/clsi/app/coffee/ResourceStateManager.coffee b/services/clsi/app/coffee/ResourceStateManager.coffee index fbd4c67736..19fea47d72 100644 --- a/services/clsi/app/coffee/ResourceStateManager.coffee +++ b/services/clsi/app/coffee/ResourceStateManager.coffee @@ -22,6 +22,7 @@ module.exports = ResourceStateManager = # files are moved, added, deleted or renamed. SYNC_STATE_FILE: ".project-sync-state" + SYNC_STATE_MAX_SIZE: 128*1024 saveProjectState: (state, resources, basePath, callback = (error) ->) -> stateFile = Path.join(basePath, @SYNC_STATE_FILE) @@ -39,8 +40,11 @@ module.exports = ResourceStateManager = checkProjectStateMatches: (state, basePath, callback = (error, resources) ->) -> stateFile = Path.join(basePath, @SYNC_STATE_FILE) - SafeReader.readFile stateFile, 128*1024, 'utf8', (err, result) -> + size = @SYNC_STATE_MAX_SIZE + SafeReader.readFile stateFile, size, 'utf8', (err, result, bytesRead) -> return callback(err) if err? + if bytesRead is size + logger.error file:stateFile, size:size, bytesRead:bytesRead, "project state file truncated" [resourceList..., oldState] = result?.toString()?.split("\n") or [] newState = "stateHash:#{state}" logger.log state:state, oldState: oldState, basePath:basePath, stateMatches: (newState is oldState), "checking sync state" diff --git a/services/clsi/app/coffee/SafeReader.coffee b/services/clsi/app/coffee/SafeReader.coffee index 91bf8a12da..adb96b1645 100644 --- a/services/clsi/app/coffee/SafeReader.coffee +++ b/services/clsi/app/coffee/SafeReader.coffee @@ -12,16 +12,14 @@ module.exports = SafeReader = return callback(err) if err? # safely return always closing the file - callbackWithClose = (err, result) -> + callbackWithClose = (err, result...) -> fs.close fd, (err1) -> return callback(err) if err? return callback(err1) if err1? - callback(null, result) + callback(null, result...) buff = new Buffer(size, 0) # fill with zeros fs.read fd, buff, 0, buff.length, 0, (err, bytesRead, buffer) -> return callbackWithClose(err) if err? result = buffer.toString(encoding, 0, bytesRead) - if bytesRead is size - logger.error file:file, size:size, bytesRead:bytesRead, "file truncated" - callbackWithClose(null, result) + callbackWithClose(null, result, bytesRead) diff --git a/services/clsi/app/coffee/TikzManager.coffee b/services/clsi/app/coffee/TikzManager.coffee index 07f87e3cff..7605b0d277 100644 --- a/services/clsi/app/coffee/TikzManager.coffee +++ b/services/clsi/app/coffee/TikzManager.coffee @@ -30,6 +30,6 @@ module.exports = TikzManager = return callback(error) if error? fs.readFile path, "utf8", (error, content) -> return callback(error) if error? - logger.log compileDir: compileDir, mainFile: mainFile, "copied file to ouput.tex for tikz" + logger.log compileDir: compileDir, mainFile: mainFile, "copied file to output.tex for tikz" # use wx flag to ensure that output file does not already exist fs.writeFile Path.join(compileDir, "output.tex"), content, {flag:'wx'}, callback