From fb934d62fdfa29fb31266979c1a806696506fdb3 Mon Sep 17 00:00:00 2001 From: Kenneth Pouncey Date: Wed, 5 Aug 2020 06:53:49 +0200 Subject: [PATCH 1/4] Fix error being overridden incorrectly on FS.Rename --- src/library_fs.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/library_fs.js b/src/library_fs.js index 3f8e3a8401ba7..1849d3ea9269a 100644 --- a/src/library_fs.js +++ b/src/library_fs.js @@ -726,6 +726,9 @@ FS.staticInit();` + lookup = FS.lookupPath(new_path, { parent: true }); new_dir = lookup.node; } catch (e) { + // do not override failing error + if (e instanceof FS.ErrnoError) + throw e; throw new FS.ErrnoError({{{ cDefine('EBUSY') }}}); } if (!old_dir || !new_dir) throw new FS.ErrnoError({{{ cDefine('ENOENT') }}}); From 7d3dae0f95316ff53a9189abb1cf513e43428065 Mon Sep 17 00:00:00 2001 From: Kenneth Pouncey Date: Tue, 18 Aug 2020 10:02:09 +0200 Subject: [PATCH 2/4] Remove try catch around directory path lookup as per review comments. - The error will percolate up and not be overridden with 'EBUSY' --- src/library_fs.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/library_fs.js b/src/library_fs.js index 1849d3ea9269a..7b78bf96b7b20 100644 --- a/src/library_fs.js +++ b/src/library_fs.js @@ -720,17 +720,13 @@ FS.staticInit();` + var new_name = PATH.basename(new_path); // parents must exist var lookup, old_dir, new_dir; - try { - lookup = FS.lookupPath(old_path, { parent: true }); - old_dir = lookup.node; - lookup = FS.lookupPath(new_path, { parent: true }); - new_dir = lookup.node; - } catch (e) { - // do not override failing error - if (e instanceof FS.ErrnoError) - throw e; - throw new FS.ErrnoError({{{ cDefine('EBUSY') }}}); - } + + // let the errors from non existant directories percolate up + lookup = FS.lookupPath(old_path, { parent: true }); + old_dir = lookup.node; + lookup = FS.lookupPath(new_path, { parent: true }); + new_dir = lookup.node; + if (!old_dir || !new_dir) throw new FS.ErrnoError({{{ cDefine('ENOENT') }}}); // need to be part of the same mount if (old_dir.mount !== new_dir.mount) { From 772383c399d76eca444b5f96e3b2bfbe07732e19 Mon Sep 17 00:00:00 2001 From: Kenneth Pouncey Date: Tue, 18 Aug 2020 16:18:22 +0200 Subject: [PATCH 3/4] Add test to test_rename.c. - Return ENONT instead of EBUSY as was previously overridden to do. --- tests/stdio/test_rename.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/stdio/test_rename.c b/tests/stdio/test_rename.c index bc75e1a3723bf..947bc0d657090 100644 --- a/tests/stdio/test_rename.c +++ b/tests/stdio/test_rename.c @@ -113,6 +113,10 @@ void test() { err = access("dir/subdir3/subdir3_1/subdir1 renamed", F_OK); assert(!err); + err = rename("dir/hicsuntdracones/empty", "dir/hicsuntdracones/renamed"); + assert(err == -1); + assert(errno == ENOENT); + puts("success"); } From 86c4ab5bfc751b615da9129b43004852fb5da55d Mon Sep 17 00:00:00 2001 From: Kenneth Pouncey Date: Tue, 18 Aug 2020 16:21:45 +0200 Subject: [PATCH 4/4] Add to authors --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index a9e4003e3347a..11ce28512fee7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -498,3 +498,4 @@ a license to everyone to use it as detailed in LICENSE.) * Jia Yuan Lo * Antoine du Hamel * Alexander Köplinger (copyright owned by Microsoft, Inc.) +* Kenneth Pouncey (copyright owned by Microsoft, Inc.)