-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5307 from wasmerio/fix/more-fs-fixes
* Fix resolving relative paths in the presence of not-root CWD and non-root base FD * Fix opening files after renaming their parent directory
- Loading branch information
Showing
7 changed files
with
202 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// There used to be an issue where, when moving a file, you could no longer | ||
// open it afterwards. This is a regression test for that issue. | ||
|
||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
#include <unistd.h> | ||
|
||
void error(const char *message) | ||
{ | ||
perror(message); | ||
exit(-1); | ||
} | ||
|
||
int main() | ||
{ | ||
// Create two directories | ||
if (mkdir("test1", S_IRWXU)) | ||
{ | ||
error("mkdir test1"); | ||
} | ||
if (mkdir("test1/inner", S_IRWXU)) | ||
{ | ||
error("mkdir t2"); | ||
} | ||
|
||
FILE *file; | ||
if (!(file = fopen("test1/inner/file", "wt"))) | ||
{ | ||
error("create file"); | ||
} | ||
if (!fwrite("hello\n", 1, 6, file)) | ||
{ | ||
error("write to file"); | ||
} | ||
if (fflush(file)) | ||
{ | ||
error("fflush"); | ||
} | ||
if (fclose(file)) | ||
{ | ||
error("fclose"); | ||
} | ||
|
||
if (rename("test1", "test2")) | ||
{ | ||
error("rename"); | ||
} | ||
|
||
if (!(file = fopen("test2/inner/file", "rt"))) | ||
{ | ||
error("open renamed file"); | ||
} | ||
char buf[7] = {0}; | ||
if (!fread((void *)buf, 1, 7, file)) | ||
{ | ||
error("fread"); | ||
} | ||
if (strcmp(buf, "hello\n")) | ||
{ | ||
printf("Invalid file contents: %s\n", buf); | ||
return -1; | ||
} | ||
|
||
printf("0"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
$WASMER -q run main.wasm --dir . > output | ||
|
||
rm -rf test1 test2 2>/dev/null && printf "0" | diff -u output - 1>/dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
#include <unistd.h> | ||
|
||
void error(const char *message) | ||
{ | ||
perror(message); | ||
exit(-1); | ||
} | ||
|
||
int main() | ||
{ | ||
// Create two directories | ||
if (mkdir("test1", S_IRWXU)) | ||
{ | ||
error("mkdir test1"); | ||
} | ||
if (mkdir("test2", S_IRWXU)) | ||
{ | ||
error("mkdir test2"); | ||
} | ||
|
||
// open the second directory for fstatat | ||
int fd; | ||
if ((fd = open("test2", O_RDONLY | O_DIRECTORY)) < 0) | ||
{ | ||
error("open"); | ||
} | ||
|
||
// chdir into the first directory | ||
if (chdir("/home/test1")) | ||
{ | ||
error("chdir"); | ||
} | ||
|
||
// Now stat the second directory with a relative path. | ||
// CWD should not be taken into account, and the stat | ||
// should succeed. | ||
struct stat st; | ||
if (fstatat(fd, ".", &st, 0)) | ||
{ | ||
error("fstatat"); | ||
} | ||
|
||
if (!S_ISDIR(st.st_mode)) | ||
{ | ||
printf("Expected a directory\n"); | ||
return -1; | ||
} | ||
|
||
printf("0"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
$WASMER -q run main.wasm --dir . > output | ||
|
||
rm -rf test1 test2 2>/dev/null && printf "0" | diff -u output - 1>/dev/null |