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 | |
Harald van Dijk | 8c24af9 | 2018-05-22 17:34:31 +0200 | [diff] [blame^] | 8 | void FAST_FUNC create_or_remember_link(llist_t **link_placeholders, |
Denys Vlasenko | a84db18 | 2018-02-20 15:57:45 +0100 | [diff] [blame] | 9 | const char *target, |
Harald van Dijk | 8c24af9 | 2018-05-22 17:34:31 +0200 | [diff] [blame^] | 10 | const char *linkname, |
| 11 | int hard_link) |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 12 | { |
Harald van Dijk | 8c24af9 | 2018-05-22 17:34:31 +0200 | [diff] [blame^] | 13 | if (hard_link || target[0] == '/' || strstr(target, "..")) { |
| 14 | llist_add_to_end(link_placeholders, |
| 15 | xasprintf("%c%s%c%s", hard_link, linkname, '\0', target) |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 16 | ); |
Denys Vlasenko | a84db18 | 2018-02-20 15:57:45 +0100 | [diff] [blame] | 17 | return; |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 18 | } |
Denys Vlasenko | a84db18 | 2018-02-20 15:57:45 +0100 | [diff] [blame] | 19 | if (symlink(target, linkname) != 0) { |
| 20 | /* shared message */ |
| 21 | bb_perror_msg_and_die("can't create %slink '%s' to '%s'", |
| 22 | "sym", linkname, target |
| 23 | ); |
| 24 | } |
| 25 | } |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 26 | |
Harald van Dijk | 8c24af9 | 2018-05-22 17:34:31 +0200 | [diff] [blame^] | 27 | void FAST_FUNC create_links_from_list(llist_t *list) |
Denys Vlasenko | a84db18 | 2018-02-20 15:57:45 +0100 | [diff] [blame] | 28 | { |
| 29 | while (list) { |
| 30 | char *target; |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 31 | |
Harald van Dijk | 8c24af9 | 2018-05-22 17:34:31 +0200 | [diff] [blame^] | 32 | target = list->data + 1 + strlen(list->data + 1) + 1; |
| 33 | if ((*list->data ? link : symlink) (target, list->data + 1)) { |
Denys Vlasenko | a84db18 | 2018-02-20 15:57:45 +0100 | [diff] [blame] | 34 | /* shared message */ |
| 35 | bb_error_msg_and_die("can't create %slink '%s' to '%s'", |
Harald van Dijk | 8c24af9 | 2018-05-22 17:34:31 +0200 | [diff] [blame^] | 36 | *list->data ? "hard" : "sym", |
| 37 | list->data + 1, target |
Denys Vlasenko | a84db18 | 2018-02-20 15:57:45 +0100 | [diff] [blame] | 38 | ); |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 39 | } |
Denys Vlasenko | a84db18 | 2018-02-20 15:57:45 +0100 | [diff] [blame] | 40 | list = list->link; |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame] | 41 | } |
| 42 | } |