Skip to content

Commit

Permalink
Fixed the delete method in the 'PhysicalFileSystem' class
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Aug 3, 2017
1 parent 961f1e7 commit da9abf0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
22 changes: 20 additions & 2 deletions lib/manager/v2/instances/PhysicalFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,26 @@ var PhysicalFileSystem = (function (_super) {
this.type(ctx.context, path, function (e, type) {
if (e)
return callback(Errors_1.Errors.ResourceNotFound);
if (type.isDirectory)
fs.rmdir(realPath, callback);
console.log(path.toString());
if (type.isDirectory) {
if (ctx.depth === 0)
return fs.rmdir(realPath, callback);
_this.readDir(ctx.context, path, function (e, files) {
var nb = files.length + 1;
var done = function (e) {
if (nb < 0)
return;
if (e) {
nb = -1;
return callback(e);
}
if (--nb === 0)
fs.rmdir(realPath, callback);
};
files.forEach(function (file) { return _this.delete(ctx.context, path.getChildPath(file), ctx.depth === -1 ? -1 : ctx.depth - 1, function (e) { return done(e); }); });
done();
});
}
else
fs.unlink(realPath, callback);
});
Expand Down
26 changes: 25 additions & 1 deletion src/manager/v2/instances/PhysicalFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,33 @@ export class PhysicalFileSystem extends FileSystem
this.type(ctx.context, path, (e, type) => {
if(e)
return callback(Errors.ResourceNotFound);
console.log(path.toString());

if(type.isDirectory)
fs.rmdir(realPath, callback);
{
if(ctx.depth === 0)
return fs.rmdir(realPath, callback);

this.readDir(ctx.context, path, (e, files) => {
let nb = files.length + 1;
const done = (e ?: Error) => {
if(nb < 0)
return;

if(e)
{
nb = -1;
return callback(e);
}

if(--nb === 0)
fs.rmdir(realPath, callback);
}

files.forEach((file) => this.delete(ctx.context, path.getChildPath(file), ctx.depth === -1 ? -1 : ctx.depth - 1, (e) => done(e)));
done();
})
}
else
fs.unlink(realPath, callback);
})
Expand Down

0 comments on commit da9abf0

Please sign in to comment.