Skip to content

Commit

Permalink
symlink: do not append cwd path if arg is absolute (#3579)
Browse files Browse the repository at this point in the history
  • Loading branch information
btovar authored Nov 21, 2023
1 parent aa3f212 commit 871aa94
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions dttools/src/file_link_recursive.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,18 @@ int file_link_recursive(const char *source, const char *target, int allow_symlin
be accidentally relative to the current directory.
*/

char *cwd = path_getcwd();
char *absolute_source = string_format("%s/%s", cwd, source);

int result = symlink(absolute_source, target);

free(absolute_source);
free(cwd);
int result = 0;
if (source[0] == '/') {
result = symlink(source, target);
} else {
char *cwd = path_getcwd();
char *absolute_source = string_format("%s/%s", cwd, source);

result = symlink(absolute_source, target);

free(absolute_source);
free(cwd);
}

if (result == 0)
return 1;
Expand Down

0 comments on commit 871aa94

Please sign in to comment.