Skip to content

Commit

Permalink
Drag and drop move operations on native project folders working #3
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Oct 20, 2021
1 parent 812a49a commit 34f3b2f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/phoenix/fslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,13 @@ const fileSystemLib = {
}
return filerLib.fs.mkdir(...args);
},
rename: function (...args) {
return filerLib.fs.rename(...args);
rename: function (oldPath, newPath, cb) {
if(Mounts.isMountPath(oldPath) || Mounts.isMountPath(newPath)) {
throw new Errors.EPERM('Mount root directory cannot be deleted.');
} else if(Mounts.isMountSubPath(oldPath) && Mounts.isMountSubPath(newPath)) {
return NativeFS.rename(oldPath, newPath, cb);
}
return filerLib.fs.rename(oldPath, newPath, cb);
},
unlink: function (path, cb) {
if(Mounts.isMountPath(path)) {
Expand Down
15 changes: 14 additions & 1 deletion src/phoenix/fslib_native.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,18 @@ async function copy(src, dst, callback, recursive = true) {
});
}

async function rename(oldPath, newPath, cb) {
copy(oldPath, newPath, err => {
if(err) {
cb(err);
} else {
setTimeout(()=>{
unlink(oldPath, cb);
}, 0);
}
});
}

function mountNativeFolder(...args) {
Mounts.mountNativeFolder(...args);
}
Expand All @@ -345,7 +357,8 @@ const NativeFS = {
readFile,
writeFile,
unlink,
copy
copy,
rename
};

export default NativeFS;

0 comments on commit 34f3b2f

Please sign in to comment.