|
|
@@ -24,8 +24,23 @@ module.exports = ResourceWriter =
|
|
|
return callback(error) if error?
|
|
|
ResourceWriter.storeSyncState request.syncState, basePath, callback
|
|
|
|
|
|
+ # The sync state is an identifier which must match for an
|
|
|
+ # incremental update to be allowed.
|
|
|
+ #
|
|
|
+ # The initial value is passed in and stored on a full
|
|
|
+ # compile.
|
|
|
+ #
|
|
|
+ # Subsequent incremental compiles must come with the same value - if
|
|
|
+ # not they will be rejected with a 409 Conflict response.
|
|
|
+ #
|
|
|
+ # An incremental compile can only update existing files with new
|
|
|
+ # content. The sync state identifier must change if any docs or
|
|
|
+ # files are moved, added, deleted or renamed.
|
|
|
+
|
|
|
+ SYNC_STATE_FILE: ".project-sync-state"
|
|
|
+
|
|
|
storeSyncState: (state, basePath, callback) ->
|
|
|
- stateFile = Path.join(basePath, ".resource-sync-state")
|
|
|
+ stateFile = Path.join(basePath, @SYNC_STATE_FILE)
|
|
|
if not state? # remove the file if no state passed in
|
|
|
logger.log state:state, basePath:basePath, "clearing sync state"
|
|
|
fs.unlink stateFile, (err) ->
|
|
|
@@ -38,10 +53,13 @@ module.exports = ResourceWriter =
|
|
|
fs.writeFile stateFile, state, {encoding: 'ascii'}, callback
|
|
|
|
|
|
checkSyncState: (state, basePath, callback) ->
|
|
|
- stateFile = Path.join(basePath, ".resource-sync-state")
|
|
|
+ stateFile = Path.join(basePath, @SYNC_STATE_FILE)
|
|
|
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)
|
|
|
+ if err? and err.code isnt 'ENOENT'
|
|
|
+ return callback(err)
|
|
|
+ else
|
|
|
+ # return true if state matches, false otherwise (including file not existing)
|
|
|
+ callback(null, if state is oldState then true else false)
|
|
|
|
|
|
saveIncrementalResourcesToDisk: (project_id, resources, basePath, callback = (error) ->) ->
|
|
|
@_createDirectory basePath, (error) =>
|