Skip to content

Commit

Permalink
Fixed the '_move' method in the 'PhysicalFileSystem' class
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Oct 1, 2017
1 parent a91227b commit 656d0f6
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 10 deletions.
47 changes: 38 additions & 9 deletions lib/manager/v2/instances/PhysicalFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,49 @@ var PhysicalFileSystem = (function (_super) {
var _this = this;
var realPathFrom = this.getRealPath(pathFrom).realPath;
var realPathTo = this.getRealPath(pathTo).realPath;
fs.rename(realPathFrom, realPathTo, function (e) {
if (!e) {
var rename = function (overwritten) {
fs.rename(realPathFrom, realPathTo, function (e) {
if (e)
return callback(e);
_this.resources[realPathTo] = _this.resources[realPathFrom];
delete _this.resources[realPathFrom];
callback(null, true);
callback(null, overwritten);
});
};
fs.access(realPathTo, function (e) {
if (e) {
rename(false);
}
else {
fs.stat(realPathTo, function (er) {
if (!er)
e = Errors_1.Errors.ResourceAlreadyExists;
else
e = Errors_1.Errors.ResourceNotFound;
callback(e, false);
if (!ctx.overwrite)
return callback(Errors_1.Errors.ResourceAlreadyExists);
_this.delete(ctx.context, pathTo, function (e) {
if (e)
return callback(e);
rename(true);
});
}
});
/*
fs.rename(realPathFrom, realPathTo, (e) => {
if(!e)
{
this.resources[realPathTo] = this.resources[realPathFrom];
delete this.resources[realPathFrom];
callback(null, true);
}
else
{
fs.stat(realPathTo, (er) => {
if(!er)
e = Errors.ResourceAlreadyExists;
else
e = Errors.ResourceNotFound;
callback(e, false);
})
}
})*/
};
PhysicalFileSystem.prototype._size = function (path, ctx, callback) {
var realPath = this.getRealPath(path).realPath;
Expand Down Expand Up @@ -221,6 +248,8 @@ var PhysicalFileSystem = (function (_super) {
};
PhysicalFileSystem.prototype._type = function (path, ctx, callback) {
var realPath = this.getRealPath(path).realPath;
if (realPath.indexOf('.url') !== -1)
return callback(Errors_1.Errors.ResourceNotFound);
fs.stat(realPath, function (e, stat) {
if (e)
return callback(Errors_1.Errors.ResourceNotFound);
Expand Down
36 changes: 35 additions & 1 deletion src/manager/v2/instances/PhysicalFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,37 @@ export class PhysicalFileSystem extends FileSystem
{
const { realPath: realPathFrom } = this.getRealPath(pathFrom);
const { realPath: realPathTo } = this.getRealPath(pathTo);

const rename = (overwritten) => {
fs.rename(realPathFrom, realPathTo, (e) => {
if(e)
return callback(e);

this.resources[realPathTo] = this.resources[realPathFrom];
delete this.resources[realPathFrom];
callback(null, overwritten);
});
};

fs.access(realPathTo, (e) => {
if(e)
{ // destination doesn't exist
rename(false);
}
else
{ // destination exists
if(!ctx.overwrite)
return callback(Errors.ResourceAlreadyExists);

this.delete(ctx.context, pathTo, (e) => {
if(e)
return callback(e);
rename(true);
});
}
})

/*
fs.rename(realPathFrom, realPathTo, (e) => {
if(!e)
Expand All @@ -230,7 +261,7 @@ export class PhysicalFileSystem extends FileSystem
callback(e, false);
})
}
})
})*/
}

protected _size(path : Path, ctx : SizeInfo, callback : ReturnCallback<number>) : void
Expand Down Expand Up @@ -306,6 +337,9 @@ export class PhysicalFileSystem extends FileSystem
{
const { realPath } = this.getRealPath(path);

if(realPath.indexOf('.url') !== -1)
return callback(Errors.ResourceNotFound);

fs.stat(realPath, (e, stat) => {
if(e)
return callback(Errors.ResourceNotFound);
Expand Down

0 comments on commit 656d0f6

Please sign in to comment.