mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
make backends consistent by deleting temporary files
This commit is contained in:
parent
47bd6edbc9
commit
40ac59090b
2 changed files with 22 additions and 8 deletions
|
@ -13,10 +13,19 @@ module.exports =
|
|||
sendFile: ( location, target, source, callback = (err)->) ->
|
||||
filteredTarget = filterName target
|
||||
logger.log location:location, target:filteredTarget, source:source, "sending file"
|
||||
fs.rename source, "#{location}/#{filteredTarget}", (err) ->
|
||||
if err!=null
|
||||
done = _.once (err) ->
|
||||
if err?
|
||||
logger.err err:err, location:location, target:filteredTarget, source:source, "Error on put of file"
|
||||
callback err
|
||||
callback(err)
|
||||
# actually copy the file (instead of moving it) to maintain consistent behaviour
|
||||
# between the different implementations
|
||||
sourceStream = fs.createReadStream source
|
||||
sourceStream.on 'error', done
|
||||
targetStream = fs.createWriteStream "#{location}/#{filteredTarget}"
|
||||
targetStream.on 'error', done
|
||||
targetStream.on 'finish', () ->
|
||||
done()
|
||||
sourceStream.pipe targetStream
|
||||
|
||||
sendStream: ( location, target, sourceStream, callback = (err)->) ->
|
||||
logger.log location:location, target:target, "sending file stream"
|
||||
|
@ -26,7 +35,10 @@ module.exports =
|
|||
if err?
|
||||
logger.err location:location, target:target, fsPath:fsPath, err:err, "something went wrong writing stream to disk"
|
||||
return callback err
|
||||
@sendFile location, target, fsPath, callback
|
||||
@sendFile location, target, fsPath, (err) ->
|
||||
# delete the temporary file created above and return the original error
|
||||
LocalFileWriter.deleteFile fsPath, () ->
|
||||
callback(err)
|
||||
|
||||
# opts may be {start: Number, end: Number}
|
||||
getFileStream: (location, name, opts, _callback = (err, res)->) ->
|
||||
|
|
|
@ -42,9 +42,8 @@ module.exports =
|
|||
if res.statusCode != 200
|
||||
logger.err bucketName:bucketName, key:key, fsPath:fsPath, "non 200 response from s3 putting file"
|
||||
return callback("non 200 response from s3 on put file")
|
||||
LocalFileWriter.deleteFile fsPath, (err)->
|
||||
logger.log res:res, bucketName:bucketName, key:key, fsPath:fsPath,"file uploaded to s3"
|
||||
callback(err)
|
||||
logger.log res:res, bucketName:bucketName, key:key, fsPath:fsPath,"file uploaded to s3"
|
||||
callback(err)
|
||||
putEventEmiter.on "error", (err)->
|
||||
logger.err err:err, bucketName:bucketName, key:key, fsPath:fsPath, "error emmited on put of file"
|
||||
callback err
|
||||
|
@ -57,7 +56,10 @@ module.exports =
|
|||
if err?
|
||||
logger.err bucketName:bucketName, key:key, fsPath:fsPath, err:err, "something went wrong writing stream to disk"
|
||||
return callback(err)
|
||||
@sendFile bucketName, key, fsPath, callback
|
||||
@sendFile bucketName, key, fsPath, (err) ->
|
||||
# delete the temporary file created above and return the original error
|
||||
LocalFileWriter.deleteFile fsPath, () ->
|
||||
callback(err)
|
||||
|
||||
# opts may be {start: Number, end: Number}
|
||||
getFileStream: (bucketName, key, opts, callback = (err, res)->)->
|
||||
|
|
Loading…
Reference in a new issue