Skip to content

Commit f8b73dc

Browse files
committedJul 17, 2014
handle errors in rename better
1 parent b03f00a commit f8b73dc

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
 

‎src/library_fs.js

+1
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ mergeInto(LibraryManager.library, {
676676
} catch (e) {
677677
throw new FS.ErrnoError(ERRNO_CODES.EBUSY);
678678
}
679+
if (!old_dir || !new_dir) throw new FS.ErrnoError(ERRNO_CODES.ENOENT);
679680
// need to be part of the same mount
680681
if (old_dir.mount !== new_dir.mount) {
681682
throw new FS.ErrnoError(ERRNO_CODES.EXDEV);

‎tests/test_other.py

+21
Original file line numberDiff line numberDiff line change
@@ -3050,6 +3050,27 @@ def test_symlink_silly(self):
30503050
self.assertContained(r'''ok''', run_js('a.out.js', args=['123', 'abc']))
30513051
self.assertContained(r'''Failed to symlink paths: abc, ; errno=2''', run_js('a.out.js', args=['abc', '']))
30523052

3053+
def test_rename_silly(self):
3054+
open('src.cpp', 'w').write(r'''
3055+
#include <stdio.h>
3056+
#include <errno.h>
3057+
3058+
int main(int argc, char **argv) {
3059+
if (rename(argv[1], argv[2]) != 0) {
3060+
printf("Failed to rename paths: %s, %s; errno=%d\n", argv[1], argv[2], errno);
3061+
} else {
3062+
printf("ok\n");
3063+
}
3064+
}
3065+
''')
3066+
Popen([PYTHON, EMCC, 'src.cpp']).communicate()
3067+
3068+
# cannot symlink nonexistents
3069+
self.assertContained(r'''Failed to rename paths: , abc; errno=2''', run_js('a.out.js', args=['', 'abc']))
3070+
self.assertContained(r'''Failed to rename paths: , ; errno=2''', run_js('a.out.js', args=['', '']))
3071+
self.assertContained(r'''Failed to rename paths: 123, abc; errno=2''', run_js('a.out.js', args=['123', 'abc']))
3072+
self.assertContained(r'''Failed to rename paths: abc, ; errno=2''', run_js('a.out.js', args=['abc', '']))
3073+
30533074
def test_emversion(self):
30543075
open('src.cpp', 'w').write(r'''
30553076
#include <stdio.h>

0 commit comments

Comments
 (0)
Please sign in to comment.