Merge pull request #78 from sharelatex/bg-fix-read-logging

fix read logging
This commit is contained in:
Brian Gough 2017-10-02 16:12:12 +01:00 committed by GitHub
commit e2d25f8c53
3 changed files with 9 additions and 7 deletions

View file

@ -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"

View file

@ -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)

View file

@ -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