Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
| 4 | */ |
| 5 | #include "libbb.h" |
| 6 | #include "bb_archive.h" |
| 7 | |
Denys Vlasenko | a84db18 | 2018-02-20 15:57:45 +0100 | [diff] [blame] | 8 | void FAST_FUNC create_or_remember_symlink(llist_t **symlink_placeholders, |
| 9 | const char *target, |
| 10 | const char *linkname) |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 11 | { |
Denys Vlasenko | a84db18 | 2018-02-20 15:57:45 +0100 | [diff] [blame] | 12 | if (target[0] == '/' || strstr(target, "..")) { |
| 13 | llist_add_to(symlink_placeholders, |
| 14 | xasprintf("%s%c%s", linkname, '\0', target) |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 15 | ); |
Denys Vlasenko | a84db18 | 2018-02-20 15:57:45 +0100 | [diff] [blame] | 16 | return; |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 17 | } |
Denys Vlasenko | a84db18 | 2018-02-20 15:57:45 +0100 | [diff] [blame] | 18 | if (symlink(target, linkname) != 0) { |
| 19 | /* shared message */ |
| 20 | bb_perror_msg_and_die("can't create %slink '%s' to '%s'", |
| 21 | "sym", linkname, target |
| 22 | ); |
| 23 | } |
| 24 | } |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 25 | |
Denys Vlasenko | a84db18 | 2018-02-20 15:57:45 +0100 | [diff] [blame] | 26 | void FAST_FUNC create_symlinks_from_list(llist_t *list) |
| 27 | { |
| 28 | while (list) { |
| 29 | char *target; |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 30 | |
Denys Vlasenko | a84db18 | 2018-02-20 15:57:45 +0100 | [diff] [blame] | 31 | target = list->data + strlen(list->data) + 1; |
| 32 | if (symlink(target, list->data)) { |
| 33 | /* shared message */ |
| 34 | bb_error_msg_and_die("can't create %slink '%s' to '%s'", |
| 35 | "sym", |
| 36 | list->data, target |
| 37 | ); |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 38 | } |
Denys Vlasenko | a84db18 | 2018-02-20 15:57:45 +0100 | [diff] [blame] | 39 | list = list->link; |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 40 | } |
| 41 | } |