4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-02-28 03:47:11 +08:00

fix tar -xzvf symbol link (#8034)

This commit is contained in:
xiao-mang 2023-09-14 11:29:03 +08:00 committed by GitHub
parent 3e3cf91b77
commit 12592458b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1283,7 +1283,7 @@ int dfs_file_symlink(const char *target, const char *linkpath)
{ {
if (dentry->mnt->fs_ops->symlink) if (dentry->mnt->fs_ops->symlink)
{ {
char *path = dfs_normalize_path(NULL, target); char *path = dfs_normalize_path(parent, target);
if (path) if (path)
{ {
char *tmp = dfs_nolink_path(&mnt, path, 0); char *tmp = dfs_nolink_path(&mnt, path, 0);
@ -1297,26 +1297,19 @@ int dfs_file_symlink(const char *target, const char *linkpath)
tmp = path; tmp = path;
} }
if (dfs_file_access(path, O_RDONLY) == 0) ret = rt_strncmp(parent, path, strlen(parent));
if (ret == 0)
{ {
ret = rt_strncmp(parent, path, strlen(parent)); tmp = path + strlen(parent);
if (ret == 0) if (*tmp == '/')
{ {
tmp = path + strlen(parent); tmp ++;
if (*tmp == '/')
{
tmp ++;
}
}
if (dfs_is_mounted(mnt) == 0)
{
ret = mnt->fs_ops->symlink(dentry, tmp, index + 1);
} }
} }
else
if (dfs_is_mounted(mnt) == 0)
{ {
ret = -ENOENT; ret = mnt->fs_ops->symlink(dentry, tmp, index + 1);
} }
rt_free(path); rt_free(path);