Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/library_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ FS.staticInit();
// paths
//
lookupPath(path, opts = {}) {
var trailingSlash = path.endsWith('/');
path = PATH_FS.resolve(path);

if (!path) return { path: '', node: null };
Expand Down Expand Up @@ -233,6 +234,10 @@ FS.staticInit();
}
}

if (trailingSlash && !FS.isDir(current.mode)) {
throw new FS.ErrnoError({{{ cDefs.ENOTDIR }}});
}

return { path: current_path, node: current };
},
getPath(node) {
Expand Down
4 changes: 2 additions & 2 deletions src/library_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ addToLibrary({
return parts;
},
normalize: (path) => {
var isAbsolute = PATH.isAbs(path),
trailingSlash = path.substr(-1) === '/';
var isAbsolute = PATH.isAbs(path);
var trailingSlash = path.endsWith('/');
// Normalize the path
path = PATH.normalizeArray(path.split('/').filter((p) => !!p), !isAbsolute).join('/');
if (!path && !isAbsolute) {
Expand Down
5 changes: 0 additions & 5 deletions system/lib/wasmfs/paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ ParsedParent doParseParent(std::string_view path,
path.remove_prefix(1);
}

// Ignore trailing '/'.
while (!path.empty() && path.back() == '/') {
path.remove_suffix(1);
}

// An empty path here means that the path was equivalent to "/" and does not
// contain a child segment for us to return. The root is its own parent, so we
// can handle this by returning (root, ".").
Expand Down
2 changes: 2 additions & 0 deletions test/other/metadce/test_metadce_files_wasmfs.funcs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ $__wasm_call_ctors
$abort
$char*\20std::__2::copy_n\5babi:nn180100\5d<char\20const*\2c\20unsigned\20long\2c\20char*\2c\200>\28char\20const*\2c\20unsigned\20long\2c\20char*\29
$decltype\28auto\29\20std::__2::__variant_detail::__visitation::__base::__dispatcher<0ul>::__dispatch\5babi:nn180100\5d<std::__2::__variant_detail::__dtor<std::__2::__variant_detail::__traits<std::__2::vector<wasmfs::Directory::Entry\2c\20std::__2::allocator<wasmfs::Directory::Entry>>\2c\20int>\2c\20\28std::__2::__variant_detail::_Trait\291>::__destroy\5babi:nn180100\5d\28\29::'lambda'\28auto&\29&&\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20std::__2::vector<wasmfs::Directory::Entry\2c\20std::__2::allocator<wasmfs::Directory::Entry>>\2c\20int>&>\28auto\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20std::__2::vector<wasmfs::Directory::Entry\2c\20std::__2::allocator<wasmfs::Directory::Entry>>\2c\20int>&\29
$decltype\28auto\29\20std::__2::__variant_detail::__visitation::__base::__dispatcher<0ul\2c\200ul>::__dispatch\5babi:nn180100\5d<void\20std::__2::__variant_detail::__ctor<std::__2::__variant_detail::__traits<long\2c\20std::__2::shared_ptr<wasmfs::File>>>::__generic_construct\5babi:nn180100\5d<std::__2::__variant_detail::__move_constructor<std::__2::__variant_detail::__traits<long\2c\20std::__2::shared_ptr<wasmfs::File>>\2c\20\28std::__2::__variant_detail::_Trait\291>>\28std::__2::__variant_detail::__ctor<std::__2::__variant_detail::__traits<long\2c\20std::__2::shared_ptr<wasmfs::File>>>&\2c\20std::__2::__variant_detail::__move_constructor<std::__2::__variant_detail::__traits<long\2c\20std::__2::shared_ptr<wasmfs::File>>\2c\20\28std::__2::__variant_detail::_Trait\291>&&\29::'lambda'\28std::__2::__variant_detail::__move_constructor<std::__2::__variant_detail::__traits<long\2c\20std::__2::shared_ptr<wasmfs::File>>\2c\20\28std::__2::__variant_detail::_Trait\291>&\2c\20auto&&\29&&\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20long\2c\20std::__2::shared_ptr<wasmfs::File>>&\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20long\2c\20std::__2::shared_ptr<wasmfs::File>>&&>\28std::__2::__variant_detail::__move_constructor<std::__2::__variant_detail::__traits<long\2c\20std::__2::shared_ptr<wasmfs::File>>\2c\20\28std::__2::__variant_detail::_Trait\291>\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20long\2c\20std::__2::shared_ptr<wasmfs::File>>&\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20long\2c\20std::__2::shared_ptr<wasmfs::File>>&&\29
$decltype\28auto\29\20std::__2::__variant_detail::__visitation::__base::__dispatcher<1ul>::__dispatch\5babi:nn180100\5d<std::__2::__variant_detail::__dtor<std::__2::__variant_detail::__traits<long\2c\20std::__2::shared_ptr<wasmfs::File>>\2c\20\28std::__2::__variant_detail::_Trait\291>::__destroy\5babi:nn180100\5d\28\29::'lambda'\28auto&\29&&\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20long\2c\20std::__2::shared_ptr<wasmfs::File>>&>\28auto\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20long\2c\20std::__2::shared_ptr<wasmfs::File>>&\29
$decltype\28auto\29\20std::__2::__variant_detail::__visitation::__base::__dispatcher<1ul\2c\201ul>::__dispatch\5babi:nn180100\5d<void\20std::__2::__variant_detail::__ctor<std::__2::__variant_detail::__traits<long\2c\20std::__2::shared_ptr<wasmfs::File>>>::__generic_construct\5babi:nn180100\5d<std::__2::__variant_detail::__move_constructor<std::__2::__variant_detail::__traits<long\2c\20std::__2::shared_ptr<wasmfs::File>>\2c\20\28std::__2::__variant_detail::_Trait\291>>\28std::__2::__variant_detail::__ctor<std::__2::__variant_detail::__traits<long\2c\20std::__2::shared_ptr<wasmfs::File>>>&\2c\20std::__2::__variant_detail::__move_constructor<std::__2::__variant_detail::__traits<long\2c\20std::__2::shared_ptr<wasmfs::File>>\2c\20\28std::__2::__variant_detail::_Trait\291>&&\29::'lambda'\28std::__2::__variant_detail::__move_constructor<std::__2::__variant_detail::__traits<long\2c\20std::__2::shared_ptr<wasmfs::File>>\2c\20\28std::__2::__variant_detail::_Trait\291>&\2c\20auto&&\29&&\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20long\2c\20std::__2::shared_ptr<wasmfs::File>>&\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20long\2c\20std::__2::shared_ptr<wasmfs::File>>&&>\28std::__2::__variant_detail::__move_constructor<std::__2::__variant_detail::__traits<long\2c\20std::__2::shared_ptr<wasmfs::File>>\2c\20\28std::__2::__variant_detail::_Trait\291>\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20long\2c\20std::__2::shared_ptr<wasmfs::File>>&\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20long\2c\20std::__2::shared_ptr<wasmfs::File>>&&\29
$dummy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WasmFS code is only removed in this PR - why is this growing?

$emscripten_builtin_malloc
$fflush
Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_files_wasmfs.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
50957
51335
2 changes: 2 additions & 0 deletions test/other/test_realpath_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ int main(int argc, char **argv) {
testrealpath("testfile.txt");
testrealpath("Folder/testfile.txt");
testrealpath("testnonexistentfile.txt");
// Filenames with trailing slash should fail.
testrealpath("Folder/testfile.txt/");
// folders
testrealpath("Folder");
testrealpath("/Folder");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
testrealpath("/Folder");
testrealpath("/Folder");
testrealpath("Folder/");

Expand Down
1 change: 1 addition & 0 deletions test/other/test_realpath_2.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Resolved: "testfile.txt" => "/testfile.txt"
Resolved: "Folder/testfile.txt" => "/Folder/testfile.txt"
Resolve failed: "testnonexistentfile.txt"
Resolve failed: "Folder/testfile.txt/"
Resolved: "Folder" => "/Folder"
Resolved: "/Folder" => "/Folder"
Resolved: "./" => "/"
Expand Down
14 changes: 8 additions & 6 deletions test/wasmfs/wasmfs_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
// FIXME: Merge with other existing close and open tests.

int main() {
// Test writing to a file with a trailing slash.
// Opening a file with trailing backslash should fail.
int fd = open("/dev/stdout/", O_WRONLY);

dprintf(fd, "WORKING WITH TRAILING BACKSLASH\n");

// Close open file
close(fd);
assert(fd == -1);
#ifdef WASMFS
assert(errno == ENOTDIR);
#else
assert(errno == ENOENT);
#endif
printf("Errno: %s\n", strerror(errno));

// Test writing to a file with no trailing backslash.
int fd2 = open("/dev/stdout", O_WRONLY);
Expand Down
1 change: 0 additions & 1 deletion test/wasmfs/wasmfs_open.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
WORKING WITH TRAILING BACKSLASH
WORKING WITHOUT TRAILING BACKSLASH
Errno: Bad file descriptor
Errno: Is a directory
Expand Down
10 changes: 7 additions & 3 deletions test/wasmfs/wasmfs_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ int main() {
assert(result == -1);
assert(errno == EBADF);

// Test stat of file with trailing slash should fail.
assert(stat("/dev/stdout/", &invalid) == -1);
assert(errno == ENOTDIR);

// Test opening a file and calling fstat.
struct stat file;
int fd = open("/dev/stdout/", O_WRONLY);
int fd = open("/dev/stdout", O_WRONLY);
assert(fd >= 0);
assert(fstat(fd, &file) != -1);

Expand All @@ -48,7 +52,7 @@ int main() {
close(fd);

// Check to see if the previous inode number matches.
int newfd = open("/dev/stdout/", O_WRONLY);
int newfd = open("/dev/stdout", O_WRONLY);
struct stat newFile;
assert(newfd >= 0);
assert(fstat(newfd, &newFile) != -1);
Expand Down Expand Up @@ -95,7 +99,7 @@ int main() {

// Test calling stat without opening a file.
struct stat statFile;
assert(stat("/dev/stdout/", &statFile) != -1);
assert(stat("/dev/stdout", &statFile) != -1);

assert(statFile.st_size == 0);
assert((statFile.st_mode & S_IFMT) == S_IFCHR);
Expand Down