Skip to content

Commit 4e6a568

Browse files
committed
Simplify
1 parent 0a76c59 commit 4e6a568

File tree

12 files changed

+24
-50
lines changed

12 files changed

+24
-50
lines changed

src/lib/libsigs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ sigs = {
411411
_wasmfs_node_insert_directory__sig: 'ipi',
412412
_wasmfs_node_insert_file__sig: 'ipi',
413413
_wasmfs_node_open__sig: 'ipp',
414+
_wasmfs_node_path_get_root__sig: 'ippi',
414415
_wasmfs_node_read__sig: 'iipiip',
415416
_wasmfs_node_readdir__sig: 'ipp',
416417
_wasmfs_node_readlink__sig: 'ippi',

src/lib/libwasmfs_node.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,9 @@ addToLibrary({
224224
});
225225
},
226226

227-
_wasmfs_node_path_is_abs__deps: ['$nodePath'],
228-
_wasmfs_node_path_is_abs: (path_p) => {
229-
return nodePath.isAbsolute(UTF8ToString(path_p));
230-
},
231-
232227
_wasmfs_node_path_get_root__deps: ['$nodePath'],
233-
_wasmfs_node_path_get_root: (abs_path_p, target_p, bufsize) => {
234-
return stringToUTF8(nodePath.parse(UTF8ToString(abs_path_p)).root, target_p, bufsize);
228+
_wasmfs_node_path_get_root: (path_p, target_p, bufsize) => {
229+
return stringToUTF8(nodePath.parse(UTF8ToString(path_p)).root, target_p, bufsize);
235230
},
236231

237232
});

system/lib/wasmfs/backend.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ class Backend {
2121
virtual std::shared_ptr<Directory> createDirectory(mode_t mode) = 0;
2222
virtual std::shared_ptr<Symlink> createSymlink(std::string target) = 0;
2323

24-
virtual bool isAbsolutePath(std::string_view path) = 0;
25-
virtual std::string getRootPath(std::string_view abs_path) = 0;
24+
virtual std::string getRootPath(std::string_view path) = 0;
2625

2726
virtual ~Backend() = default;
2827
};

system/lib/wasmfs/backends/ignore_case_backend.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,8 @@ class IgnoreCaseBackend : public Backend {
226226
return virtualize(backend->createSymlink(target), this);
227227
}
228228

229-
bool isAbsolutePath(std::string_view path) override {
230-
return path.front() == '/';
231-
}
232-
233-
std::string getRootPath(std::string_view abs_path) override {
234-
return "/";
229+
std::string getRootPath(std::string_view path) override {
230+
return path.front() == '/' ? "/" : "";
235231
}
236232
};
237233

system/lib/wasmfs/backends/memory_backend.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,8 @@ class MemoryBackend : public Backend {
104104
std::shared_ptr<Symlink> createSymlink(std::string target) override {
105105
return std::make_shared<MemorySymlink>(target, this);
106106
}
107-
bool isAbsolutePath(std::string_view path) override {
108-
return path.front() == '/';
109-
}
110-
std::string getRootPath(std::string_view abs_path) override {
111-
return "/";
107+
std::string getRootPath(std::string_view path) override {
108+
return path.front() == '/' ? "/" : "";
112109
}
113110
};
114111

system/lib/wasmfs/backends/node_backend.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,10 @@ class NodeBackend : public Backend {
297297
WASMFS_UNREACHABLE("TODO: implement NodeBackend::createSymlink");
298298
}
299299

300-
bool isAbsolutePath(std::string_view path) override {
301-
return _wasmfs_node_path_is_abs(std::string(path).c_str());
302-
}
303-
304-
std::string getRootPath(std::string_view abs_path) override {
300+
std::string getRootPath(std::string_view path) override {
305301
char buf[PATH_MAX];
306-
auto path = std::string(abs_path);
307-
if (_wasmfs_node_path_get_root(path.c_str(), buf, PATH_MAX) < 0) {
302+
auto pathStr = std::string(path);
303+
if (_wasmfs_node_path_get_root(pathStr.c_str(), buf, PATH_MAX) < 0) {
308304
WASMFS_UNREACHABLE("getRootPath cannot fail");
309305
}
310306
return std::string(buf);

system/lib/wasmfs/backends/node_backend.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ int _wasmfs_node_read(
5252
int _wasmfs_node_write(
5353
int fd, const void* buf, uint32_t len, uint32_t pos, uint32_t* nwritten);
5454

55-
int _wasmfs_node_path_is_abs(const char* path);
56-
int _wasmfs_node_path_get_root(const char* abs_path, const char *buf, int bufsize);
55+
int _wasmfs_node_path_get_root(const char* path, const char *buf, int bufsize);
5756

5857
} // extern "C"

system/lib/wasmfs/backends/opfs_backend.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,8 @@ class OPFSBackend : public Backend {
394394
return nullptr;
395395
}
396396

397-
bool isAbsolutePath(std::string_view path) override {
398-
return path.front() == '/';
399-
}
400-
401-
std::string getRootPath(std::string_view abs_path) override {
402-
return "/";
397+
std::string getRootPath(std::string_view path) override {
398+
return path.front() == '/' ? "/" : "";
403399
}
404400
};
405401

system/lib/wasmfs/js_impl_backend.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,8 @@ class JSImplBackend : public Backend {
120120
std::shared_ptr<Symlink> createSymlink(std::string target) override {
121121
return std::make_shared<MemorySymlink>(target, this);
122122
}
123-
bool isAbsolutePath(std::string_view path) override {
124-
return path.front() == '/';
125-
}
126-
std::string getRootPath(std::string_view abs_path) override {
127-
return "/";
123+
std::string getRootPath(std::string_view path) override {
124+
return path.front() == '/' ? "/" : "";
128125
}
129126
};
130127

system/lib/wasmfs/paths.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ ParsedParent doParseParent(std::string_view path,
6969
return {-ENOENT};
7070
}
7171

72-
auto currBackend = curr->getBackend();
72+
auto rootPath = curr->getBackend()->getRootPath(path);
7373

7474
// Handle absolute paths.
75-
if (currBackend->isAbsolutePath(path)) {
75+
if (!rootPath.empty()) {
7676
curr = wasmFS.getRootDirectory();
77-
path.remove_prefix(currBackend->getRootPath(path).size());
77+
path.remove_prefix(rootPath.size());
7878
}
7979

8080
// Ignore trailing '/'.

0 commit comments

Comments
 (0)