Skip to content

Commit

Permalink
Fixed the persistence (untriggered close event on saving)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Jul 8, 2017
1 parent 3d92611 commit 7e7f86d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/server/v2/webDAVServer/Persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,16 @@ function autoSave(options) {
inputStream = zlib.createGzip();
if (!outputStream)
outputStream = inputStream;
outputStream.pipe(fs.createWriteStream(options.tempTreeFilePath));
var fileStream = fs.createWriteStream(options.tempTreeFilePath);
outputStream.pipe(fileStream);
inputStream.end(JSON.stringify(data), function (e) {
if (e) {
options.onSaveError(e);
next();
return;
}
});
inputStream.on('close', function () {
fileStream.on('close', function () {
fs.unlink(options.treeFilePath, function (e) {
if (e && e.code !== 'ENOENT') {
options.onSaveError(e);
Expand Down
5 changes: 3 additions & 2 deletions src/server/v2/webDAVServer/Persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ export function autoSave(options : IAutoSave)
inputStream = zlib.createGzip();
if(!outputStream)
outputStream = inputStream;
outputStream.pipe(fs.createWriteStream(options.tempTreeFilePath));
const fileStream = fs.createWriteStream(options.tempTreeFilePath);
outputStream.pipe(fileStream);

inputStream.end(JSON.stringify(data), (e) => {
if(e)
Expand All @@ -124,7 +125,7 @@ export function autoSave(options : IAutoSave)
}
});

inputStream.on('close', () => {
fileStream.on('close', () => {
fs.unlink(options.treeFilePath, (e) => {
if(e && e.code !== 'ENOENT') // An error other than ENOENT (no file/folder found)
{
Expand Down

0 comments on commit 7e7f86d

Please sign in to comment.