Strip newline from base_url, use wasmfs_create_file instead of open

Also style fixes
This commit is contained in:
Joseph C. Osborn 2025-03-12 15:06:29 -07:00
parent 809e5d78be
commit d4d3aee457
1 changed files with 13 additions and 7 deletions

View File

@ -550,7 +550,10 @@ void platform_emscripten_mount_filesystems(void)
else else
{ {
char *base_url = strdup(line); char *base_url = strdup(line);
base_url[strcspn(base_url, "\r\n")] = '\0'; // drop newline
base_url[len-1] = '\0'; // drop newline
backend_t fetch; backend_t fetch;
len = max_line_len;
// Don't create fetch backend unless manifest actually has entries // Don't create fetch backend unless manifest actually has entries
while (getline(&line, &len, file) != -1) while (getline(&line, &len, file) != -1)
{ {
@ -561,7 +564,7 @@ void platform_emscripten_mount_filesystems(void)
} }
char *realfs_path = strstr(line, " "), *url = line; char *realfs_path = strstr(line, " "), *url = line;
int fd; int fd;
if(len <= 2 || !realfs_path) if (len <= 2 || !realfs_path)
{ {
printf("[FetchFS] Manifest file has invalid line %s\n",line); printf("[FetchFS] Manifest file has invalid line %s\n",line);
continue; continue;
@ -569,14 +572,14 @@ void platform_emscripten_mount_filesystems(void)
*realfs_path = '\0'; *realfs_path = '\0';
realfs_path += 1; realfs_path += 1;
realfs_path[strcspn(realfs_path, "\r\n")] = '\0'; realfs_path[strcspn(realfs_path, "\r\n")] = '\0';
printf("[FetchFS] Fetch %s from URL %s / %s, fetched path %s / %s\n", realfs_path, base_url, url, fetch_base_dir, url);
char fetchfs_path[PATH_MAX]; char fetchfs_path[PATH_MAX];
fill_pathname_join(fetchfs_path, fetch_base_dir, url, sizeof(fetchfs_path)); fill_pathname_join(fetchfs_path, fetch_base_dir, url, sizeof(fetchfs_path));
/* Make the directories for link path */ /* Make the directories for link path */
{ {
char *parent = strdup(realfs_path); char *parent = strdup(realfs_path);
path_parent_dir(parent, strlen(parent)); path_parent_dir(parent, strlen(parent));
if(!path_mkdir(parent)) { if (!path_mkdir(parent))
{
printf("[FetchFS] mkdir error %s %d\n", realfs_path, errno); printf("[FetchFS] mkdir error %s %d\n", realfs_path, errno);
abort(); abort();
} }
@ -586,19 +589,22 @@ void platform_emscripten_mount_filesystems(void)
{ {
char *parent = strdup(fetchfs_path); char *parent = strdup(fetchfs_path);
path_parent_dir(parent, strlen(parent)); path_parent_dir(parent, strlen(parent));
if(!path_mkdir(parent)) { if (!path_mkdir(parent))
{
printf("[FetchFS] mkdir error %s %d\n", fetchfs_path, errno); printf("[FetchFS] mkdir error %s %d\n", fetchfs_path, errno);
abort(); abort();
} }
free(parent); free(parent);
} }
fd = open(fetchfs_path, O_CREAT); fd = wasmfs_create_file(fetchfs_path, 0777, fetch);
if(!fd) { if (!fd)
{
printf("[FetchFS] couldn't create fetch file %s\n", fetchfs_path); printf("[FetchFS] couldn't create fetch file %s\n", fetchfs_path);
abort(); abort();
} }
close(fd); close(fd);
if(symlink(fetchfs_path, realfs_path) != 0) { if (symlink(fetchfs_path, realfs_path) != 0)
{
printf("[FetchFS] couldn't create link %s to fetch file %s (errno %d)\n", realfs_path, fetchfs_path, errno); printf("[FetchFS] couldn't create link %s to fetch file %s (errno %d)\n", realfs_path, fetchfs_path, errno);
abort(); abort();
} }