|
@@ -50,6 +50,8 @@ module.exports = ResourceWriter =
|
|
|
should_delete = false
|
|
should_delete = false
|
|
|
if path == "output.pdf" or path == "output.dvi" or path == "output.log"
|
|
if path == "output.pdf" or path == "output.dvi" or path == "output.log"
|
|
|
should_delete = true
|
|
should_delete = true
|
|
|
|
|
+ if path == "output.tex" # created by TikzManager if present in output files
|
|
|
|
|
+ should_delete = true
|
|
|
if should_delete
|
|
if should_delete
|
|
|
jobs.push (callback) -> ResourceWriter._deleteFileIfNotDirectory Path.join(basePath, path), callback
|
|
jobs.push (callback) -> ResourceWriter._deleteFileIfNotDirectory Path.join(basePath, path), callback
|
|
|
|
|
|
|
@@ -73,19 +75,22 @@ module.exports = ResourceWriter =
|
|
|
callback()
|
|
callback()
|
|
|
|
|
|
|
|
_writeResourceToDisk: (project_id, resource, basePath, callback = (error) ->) ->
|
|
_writeResourceToDisk: (project_id, resource, basePath, callback = (error) ->) ->
|
|
|
- path = Path.normalize(Path.join(basePath, resource.path))
|
|
|
|
|
- if (path.slice(0, basePath.length) != basePath)
|
|
|
|
|
- return callback new Error("resource path is outside root directory")
|
|
|
|
|
-
|
|
|
|
|
- mkdirp Path.dirname(path), (error) ->
|
|
|
|
|
|
|
+ ResourceWriter.checkPath basePath, resource.path, (error, path) ->
|
|
|
return callback(error) if error?
|
|
return callback(error) if error?
|
|
|
- # TODO: Don't overwrite file if it hasn't been modified
|
|
|
|
|
- if resource.url?
|
|
|
|
|
- UrlCache.downloadUrlToFile project_id, resource.url, path, resource.modified, (err)->
|
|
|
|
|
- if err?
|
|
|
|
|
- logger.err err:err, project_id:project_id, path:path, resource_url:resource.url, modified:resource.modified, "error downloading file for resources"
|
|
|
|
|
- callback() #try and continue compiling even if http resource can not be downloaded at this time
|
|
|
|
|
- else
|
|
|
|
|
- fs.writeFile path, resource.content, callback
|
|
|
|
|
|
|
+ mkdirp Path.dirname(path), (error) ->
|
|
|
|
|
+ return callback(error) if error?
|
|
|
|
|
+ # TODO: Don't overwrite file if it hasn't been modified
|
|
|
|
|
+ if resource.url?
|
|
|
|
|
+ UrlCache.downloadUrlToFile project_id, resource.url, path, resource.modified, (err)->
|
|
|
|
|
+ if err?
|
|
|
|
|
+ logger.err err:err, project_id:project_id, path:path, resource_url:resource.url, modified:resource.modified, "error downloading file for resources"
|
|
|
|
|
+ callback() #try and continue compiling even if http resource can not be downloaded at this time
|
|
|
|
|
+ else
|
|
|
|
|
+ fs.writeFile path, resource.content, callback
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ checkPath: (basePath, resourcePath, callback) ->
|
|
|
|
|
+ path = Path.normalize(Path.join(basePath, resourcePath))
|
|
|
|
|
+ if (path.slice(0, basePath.length + 1) != basePath + "/")
|
|
|
|
|
+ return callback new Error("resource path is outside root directory")
|
|
|
|
|
+ else
|
|
|
|
|
+ return callback(null, path)
|