Skip to content

Delete file and folder from native fs working #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/phoenix/fslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ const fileSystemLib = {
return filerLib.fs.rename(...args);
},
unlink: function (path, cb) {
if(Mounts.isMountPath(path)) {
throw new Errors.EPERM('Mount root directory cannot be deleted.');
} else if(Mounts.isMountSubPath(path)) {
return NativeFS.unlink(path, cb);
}
return filerShell.rm(path, { recursive: true }, cb);
},
showSaveDialog: function () {
Expand Down
25 changes: 24 additions & 1 deletion src/phoenix/fslib_native.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,28 @@ function writeFile (path, data, options, callback) {
});
}

async function _deleteEntry(dirHandle, entryNameToDelete, callback, recursive=true){
try {
await dirHandle.removeEntry(entryNameToDelete, { recursive: recursive });
callback();
} catch (err) {
callback(err);
}
}

async function unlink(path, callback) {
path = window.path.normalize(path);
let dirPath= window.path.dirname(path);
let baseName= window.path.basename(path);
Mounts.getHandleFromPath(dirPath, async (err, dirHandle) => {
if(err){
callback(err);
} else {
_deleteEntry(dirHandle, baseName, callback);
}
});
}

function mountNativeFolder(...args) {
Mounts.mountNativeFolder(...args);
}
Expand All @@ -209,7 +231,8 @@ const NativeFS = {
readdir,
stat,
readFile,
writeFile
writeFile,
unlink
};

export default NativeFS;