From 392e96b81d8ca4a04e1d6817772b28a2159c7065 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Mon, 2 Oct 2017 15:44:00 +0100 Subject: [PATCH 1/2] move logging from SafeReader into caller prevent unnecessary logging when looking at headers of files where hitting the end of the file is expected. --- services/clsi/app/coffee/ResourceStateManager.coffee | 6 +++++- services/clsi/app/coffee/SafeReader.coffee | 8 +++----- 2 files changed, 8 insertions(+), 6 deletions(-) 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) From 3c937ce2d48e2babab880091f0b767e389258655 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Mon, 2 Oct 2017 15:45:09 +0100 Subject: [PATCH 2/2] fix typo in log message --- services/clsi/app/coffee/TikzManager.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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