diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-07-15 21:27:46 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-07-15 21:27:46 -0700 |
commit | bf0f60a46872526a4f632eb1bd07e7f1b4a25af0 (patch) | |
tree | 3d7727e2095b7878809e4f7ddd3765715a75491a /src/library.js | |
parent | 475e72dc5539d9c59fc267927441a502c14a178f (diff) | |
parent | 13b8be215de6213eabb23bd68c34622f00452954 (diff) |
Merge pull request #1388 from inolen/unlink_fixes
misc unlink / rmdir fixes
Diffstat (limited to 'src/library.js')
-rw-r--r-- | src/library.js | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/library.js b/src/library.js index f6da38c1..5aa370a7 100644 --- a/src/library.js +++ b/src/library.js @@ -1867,42 +1867,42 @@ LibraryManager.library = { rmdir: function(path) { // int rmdir(const char *path); // http://pubs.opengroup.org/onlinepubs/000095399/functions/rmdir.html - path = FS.analyzePath(Pointer_stringify(path)); + path = Pointer_stringify(path); + path = FS.analyzePath(path, true); if (!path.parentExists || !path.exists) { ___setErrNo(path.error); return -1; - } else if (!path.object.write || path.isRoot) { + } else if (!path.parentObject.write) { ___setErrNo(ERRNO_CODES.EACCES); return -1; } else if (!path.object.isFolder) { ___setErrNo(ERRNO_CODES.ENOTDIR); return -1; + } else if (path.isRoot || path.path == FS.currentPath) { + ___setErrNo(ERRNO_CODES.EBUSY); + return -1; } else { for (var i in path.object.contents) { ___setErrNo(ERRNO_CODES.ENOTEMPTY); return -1; } - if (path.path == FS.currentPath) { - ___setErrNo(ERRNO_CODES.EBUSY); - return -1; - } else { - delete path.parentObject.contents[path.name]; - return 0; - } + delete path.parentObject.contents[path.name]; + return 0; } }, unlink__deps: ['$FS', '__setErrNo', '$ERRNO_CODES'], unlink: function(path) { // int unlink(const char *path); // http://pubs.opengroup.org/onlinepubs/000095399/functions/unlink.html - path = FS.analyzePath(Pointer_stringify(path)); + path = Pointer_stringify(path); + path = FS.analyzePath(path, true); if (!path.parentExists || !path.exists) { ___setErrNo(path.error); return -1; } else if (path.object.isFolder) { - ___setErrNo(ERRNO_CODES.EISDIR); + ___setErrNo(ERRNO_CODES.EPERM); return -1; - } else if (!path.object.write) { + } else if (!path.parentObject.write) { ___setErrNo(ERRNO_CODES.EACCES); return -1; } else { |