Skip to content

Commit 500eca5

Browse files
committed
Fixed the 'moveTo' method of the 'PhysicalResource'
1 parent e3fbf7a commit 500eca5

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

lib/resource/physical/PhysicalResource.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,34 @@ var PhysicalResource = (function (_super) {
2424
else
2525
fsManager = new PhysicalFSManager_1.PhysicalFSManager();
2626
_this = _super.call(this, parent, fsManager) || this;
27+
_this.deleteOnMoved = false;
2728
_this.realPath = path.resolve(realPath);
2829
_this.name = path.basename(_this.realPath);
2930
return _this;
3031
}
3132
PhysicalResource.prototype.moveTo = function (parent, newName, overwrite, callback) {
32-
StandardResource_1.StandardResource.standardMoveTo(this, parent, newName, overwrite, callback);
33+
var _this = this;
34+
var pRealPath = parent.realPath;
35+
if (!(parent.fsManager && this.fsManager && parent.fsManager.uid === this.fsManager.uid && pRealPath)) {
36+
StandardResource_1.StandardResource.standardMoveByCopy(this, parent, newName, overwrite, this.deleteOnMoved, callback);
37+
return;
38+
}
39+
var newRealPath = path.join(pRealPath, newName);
40+
fs.rename(this.realPath, newRealPath, function (e) {
41+
if (e) {
42+
callback(e);
43+
return;
44+
}
45+
_this.realPath = newRealPath;
46+
_this.name = path.basename(_this.realPath);
47+
_this.removeFromParent(function (e) {
48+
if (e) {
49+
callback(e);
50+
return;
51+
}
52+
_this.addToParent(parent, callback);
53+
});
54+
});
3355
};
3456
PhysicalResource.prototype.rename = function (newName, callback) {
3557
var _this = this;

src/resource/physical/PhysicalResource.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export abstract class PhysicalResource extends StandardResource
2121

2222
super(parent, fsManager);
2323

24+
this.deleteOnMoved = false;
2425
this.realPath = path.resolve(realPath);
2526
this.name = path.basename(this.realPath);
2627
}
@@ -30,7 +31,34 @@ export abstract class PhysicalResource extends StandardResource
3031
abstract delete(callback : SimpleCallback)
3132
moveTo(parent : IResource, newName : string, overwrite : boolean, callback : SimpleCallback)
3233
{
33-
StandardResource.standardMoveTo(this, parent, newName, overwrite, callback);
34+
const pRealPath = (parent as any).realPath;
35+
if(!(parent.fsManager && this.fsManager && parent.fsManager.uid === this.fsManager.uid && pRealPath))
36+
{
37+
StandardResource.standardMoveByCopy(this, parent, newName, overwrite, this.deleteOnMoved, callback);
38+
return;
39+
}
40+
41+
const newRealPath = path.join(pRealPath, newName);
42+
fs.rename(this.realPath, newRealPath, (e) => {
43+
if(e)
44+
{
45+
callback(e);
46+
return;
47+
}
48+
49+
this.realPath = newRealPath;
50+
this.name = path.basename(this.realPath);
51+
52+
this.removeFromParent((e) => {
53+
if(e)
54+
{
55+
callback(e);
56+
return;
57+
}
58+
59+
this.addToParent(parent, callback);
60+
})
61+
})
3462
}
3563
rename(newName : string, callback : Return2Callback<string, string>)
3664
{

0 commit comments

Comments
 (0)