mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
DRY up writing to dump-folder in FileWriter
This commit is contained in:
parent
b5e8ed81b9
commit
8766b5d487
1 changed files with 10 additions and 7 deletions
|
@ -7,13 +7,18 @@ request = require 'request'
|
||||||
|
|
||||||
module.exports = FileWriter =
|
module.exports = FileWriter =
|
||||||
|
|
||||||
writeLinesToDisk: (identifier, lines, callback = (error, fsPath)->) ->
|
_ensureDumpFolderExists: (callback=(error)->) ->
|
||||||
callback = _.once(callback)
|
|
||||||
fsPath = "#{Settings.path.dumpFolder}/#{identifier}_#{uuid.v4()}"
|
|
||||||
fs.mkdir Settings.path.dumpFolder, (error) ->
|
fs.mkdir Settings.path.dumpFolder, (error) ->
|
||||||
if error? and error.code != 'EEXIST'
|
if error? and error.code != 'EEXIST'
|
||||||
# Ignore error about already existing
|
# Ignore error about already existing
|
||||||
return callback(error)
|
return callback(error)
|
||||||
|
callback(null)
|
||||||
|
|
||||||
|
writeLinesToDisk: (identifier, lines, callback = (error, fsPath)->) ->
|
||||||
|
callback = _.once(callback)
|
||||||
|
fsPath = "#{Settings.path.dumpFolder}/#{identifier}_#{uuid.v4()}"
|
||||||
|
FileWriter._ensureDumpFolderExists (error) ->
|
||||||
|
return callback(error) if error?
|
||||||
fs.writeFile fsPath, lines.join('\n'), (error) ->
|
fs.writeFile fsPath, lines.join('\n'), (error) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
callback(null, fsPath)
|
callback(null, fsPath)
|
||||||
|
@ -23,11 +28,9 @@ module.exports = FileWriter =
|
||||||
fsPath = "#{Settings.path.dumpFolder}/#{identifier}_#{uuid.v4()}"
|
fsPath = "#{Settings.path.dumpFolder}/#{identifier}_#{uuid.v4()}"
|
||||||
|
|
||||||
stream.pause()
|
stream.pause()
|
||||||
fs.mkdir Settings.path.dumpFolder, (error) ->
|
FileWriter._ensureDumpFolderExists (error) ->
|
||||||
|
return callback(error) if error?
|
||||||
stream.resume()
|
stream.resume()
|
||||||
if error? and error.code != 'EEXIST'
|
|
||||||
# Ignore error about already existing
|
|
||||||
return callback(error)
|
|
||||||
|
|
||||||
writeStream = fs.createWriteStream(fsPath)
|
writeStream = fs.createWriteStream(fsPath)
|
||||||
stream.pipe(writeStream)
|
stream.pipe(writeStream)
|
||||||
|
|
Loading…
Reference in a new issue