aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library.js4
-rwxr-xr-xtests/runner.py25
2 files changed, 28 insertions, 1 deletions
diff --git a/src/library.js b/src/library.js
index cfe83c6e..aaef2f74 100644
--- a/src/library.js
+++ b/src/library.js
@@ -3453,7 +3453,9 @@ LibraryManager.library = {
} else if (oldObj.isRoot || oldObj.path == FS.currentPath) {
___setErrNo(ERRNO_CODES.EBUSY);
return -1;
- } else if (newObj.path && newObj.path.indexOf(oldObj.path) == 0) {
+ } else if (newObj.parentPath &&
+ newObj.parentPath.indexOf(oldObj.parentPath) == 0 &&
+ newObj.parentPath != oldObj.parentPath) {
___setErrNo(ERRNO_CODES.EINVAL);
return -1;
} else if (newObj.exists && newObj.object.isFolder) {
diff --git a/tests/runner.py b/tests/runner.py
index ead85948..838c150d 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -3402,6 +3402,31 @@ Exiting setjmp function, level: 0, prev_jmp: -1
'''
self.do_run(src, 'z:1*', force_c=True)
+ def test_rename(self):
+ src = '''
+ #include <stdio.h>
+ #include <sys/stat.h>
+ #include <sys/types.h>
+ #include <assert.h>
+
+ int main() {
+ int err;
+ FILE* fid;
+
+ err = mkdir("/foo", 0777);
+ fid = fopen("/foo/bar", "w+");
+ fclose(fid);
+
+ err = rename("/foo/bar", "/foo/bar2");
+ printf("%d\\n", err);
+
+ err = rename("/foo", "/foo/foo");
+ printf("%d\\n", err);
+ return 0;
+ }
+ '''
+ self.do_run(src, '0\n-1\n', force_c=True)
+
def test_alloca_stack(self):
if self.emcc_args is None: return # too slow in other modes