Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Fix duplicate '/' in fspfs_lookup & fspfs_create_directory #159

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 20 additions & 7 deletions lib/fs/fspfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,17 @@ static result_t fspfs_lookup(void *data, trn_inode_t *out, const char *name, siz
new_inode->fs = inode->fs;

strncpy(new_inode->path, base_path, base_path_len);
new_inode->path[base_path_len] = '/';
strncpy(new_inode->path + base_path_len + 1, name, name_len);
new_inode->path[base_path_len + 1 + name_len] = '\0';
new_inode->path_len = l;

int extra_slash = 0;
if (base_path_len == 0 || new_inode->path[base_path_len - 1] != '/') {
new_inode->path[base_path_len] = '/';
Copy link
Member

Choose a reason for hiding this comment

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

base_path_len++ and remove extra_slash variable?

extra_slash = 1;
}

strncpy(new_inode->path + base_path_len + extra_slash, name, name_len);
new_inode->path[base_path_len + extra_slash + name_len] = '\0';
new_inode->path_len = base_path_len + name_len + extra_slash;


if ((r = ifilesystem_get_entry_type(inode->fs, &type, new_inode->path)) != RESULT_OK)
goto fail;
Expand Down Expand Up @@ -112,9 +119,15 @@ static result_t fspfs_create_directory(void *data, const char *name) {
base_path_len = inode->path_len;

strncpy(full_path, base_path, base_path_len);
full_path[base_path_len] = '/';
strncpy(full_path + base_path_len + 1, name, name_len);
full_path[base_path_len + 1 + name_len] = '\0';

int extra_slash = 0;
if (base_path_len == 0 || full_path[base_path_len - 1] != '/') {
full_path[base_path_len] = '/';
extra_slash = 1;
}
Copy link
Member

Choose a reason for hiding this comment

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

Same thing here


strncpy(full_path + base_path_len + extra_slash, name, name_len);
full_path[base_path_len + extra_slash + name_len] = '\0';

return ifilesystem_create_directory(inode->fs, full_path);
}
Expand Down