Skip to content

Commit da9abf0

Browse files
committed
Fixed the delete method in the 'PhysicalFileSystem' class
1 parent 961f1e7 commit da9abf0

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

lib/manager/v2/instances/PhysicalFileSystem.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,26 @@ var PhysicalFileSystem = (function (_super) {
110110
this.type(ctx.context, path, function (e, type) {
111111
if (e)
112112
return callback(Errors_1.Errors.ResourceNotFound);
113-
if (type.isDirectory)
114-
fs.rmdir(realPath, callback);
113+
console.log(path.toString());
114+
if (type.isDirectory) {
115+
if (ctx.depth === 0)
116+
return fs.rmdir(realPath, callback);
117+
_this.readDir(ctx.context, path, function (e, files) {
118+
var nb = files.length + 1;
119+
var done = function (e) {
120+
if (nb < 0)
121+
return;
122+
if (e) {
123+
nb = -1;
124+
return callback(e);
125+
}
126+
if (--nb === 0)
127+
fs.rmdir(realPath, callback);
128+
};
129+
files.forEach(function (file) { return _this.delete(ctx.context, path.getChildPath(file), ctx.depth === -1 ? -1 : ctx.depth - 1, function (e) { return done(e); }); });
130+
done();
131+
});
132+
}
115133
else
116134
fs.unlink(realPath, callback);
117135
});

src/manager/v2/instances/PhysicalFileSystem.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,33 @@ export class PhysicalFileSystem extends FileSystem
150150
this.type(ctx.context, path, (e, type) => {
151151
if(e)
152152
return callback(Errors.ResourceNotFound);
153+
console.log(path.toString());
153154

154155
if(type.isDirectory)
155-
fs.rmdir(realPath, callback);
156+
{
157+
if(ctx.depth === 0)
158+
return fs.rmdir(realPath, callback);
159+
160+
this.readDir(ctx.context, path, (e, files) => {
161+
let nb = files.length + 1;
162+
const done = (e ?: Error) => {
163+
if(nb < 0)
164+
return;
165+
166+
if(e)
167+
{
168+
nb = -1;
169+
return callback(e);
170+
}
171+
172+
if(--nb === 0)
173+
fs.rmdir(realPath, callback);
174+
}
175+
176+
files.forEach((file) => this.delete(ctx.context, path.getChildPath(file), ctx.depth === -1 ? -1 : ctx.depth - 1, (e) => done(e)));
177+
done();
178+
})
179+
}
156180
else
157181
fs.unlink(realPath, callback);
158182
})

0 commit comments

Comments
 (0)