diff --git a/lib/server/rest/fs/put.js b/lib/server/rest/fs/put.js index c77a0671..146acbdb 100644 --- a/lib/server/rest/fs/put.js +++ b/lib/server/rest/fs/put.js @@ -56,7 +56,7 @@ if (error) func(error); else - patchFile(patch); + patchFile(name, patch, func); }); else error = 'File is to big. ' + @@ -66,39 +66,40 @@ if (error) func(error); }); - - function patchFile(patch) { - fs.readFile(name, 'utf8', read); - - function read(error, data) { - var diffResult; - - if (error) - func(error); - else { - error = Util.tryCatchLog(function() { - diffResult = diff.applyPatch(data, patch); - }); - - if (diffResult && !error) - fs.writeFile(name, diffResult, write); - else { - msg = CloudFunc.formatMsg('patch', baseName, 'fail'); - func(null, msg); - } - } - } - - function write(name, error) { - var msg; - - if (!error) - msg = CloudFunc.formatMsg('patch', baseName); - - func(error, msg); - } - } break; } } + + function patchFile(name, patch, func) { + fs.readFile(name, 'utf8', read); + + function read(error, data) { + var diffResult; + + if (error) + func(error); + else { + error = Util.tryCatchLog(function() { + diffResult = diff.applyPatch(data, patch); + }); + + if (diffResult && !error) + fs.writeFile(name, diffResult, write); + else { + msg = CloudFunc.formatMsg('patch', baseName, 'fail'); + func(null, msg); + } + } + } + + function write(name, error) { + var msg, + baseName = path.basename(name); + + if (!error) + msg = CloudFunc.formatMsg('patch', baseName); + + func(error, msg); + } + } })();