mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
clean up the state file if no state passed in
This commit is contained in:
parent
567a89350b
commit
4ebc7e5e4a
1 changed files with 13 additions and 3 deletions
|
@ -25,11 +25,21 @@ module.exports = ResourceWriter =
|
|||
ResourceWriter.storeSyncState request.syncState, basePath, callback
|
||||
|
||||
storeSyncState: (state, basePath, callback) ->
|
||||
logger.log state:state, basePath:basePath, "writing sync state"
|
||||
fs.writeFile Path.join(basePath, ".resource-sync-state"), state, {encoding: 'ascii'}, callback
|
||||
stateFile = Path.join(basePath, ".resource-sync-state")
|
||||
if not state? # remove the file if no state passed in
|
||||
logger.log state:state, basePath:basePath, "clearing sync state"
|
||||
fs.unlink stateFile, (err) ->
|
||||
if err? and err.code isnt 'ENOENT'
|
||||
return callback(err)
|
||||
else
|
||||
return callback()
|
||||
else
|
||||
logger.log state:state, basePath:basePath, "writing sync state"
|
||||
fs.writeFile stateFile, state, {encoding: 'ascii'}, callback
|
||||
|
||||
checkSyncState: (state, basePath, callback) ->
|
||||
fs.readFile Path.join(basePath, ".resource-sync-state"), {encoding:'ascii'}, (err, oldState) ->
|
||||
stateFile = Path.join(basePath, ".resource-sync-state")
|
||||
fs.readFile stateFile, {encoding:'ascii'}, (err, oldState) ->
|
||||
# ignore errors, return true if state matches, false otherwise (including errors)
|
||||
return callback(null, if state is oldState then true else false)
|
||||
|
||||
|
|
Loading…
Reference in a new issue