blob: f8dc8033d24fad73935678fd298106599589990d [file] [log] [blame]
Denys Vlasenkobc9bbeb2017-08-10 11:52:42 +02001/* 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 Dijk8c24af92018-05-22 17:34:31 +02008void FAST_FUNC create_or_remember_link(llist_t **link_placeholders,
Denys Vlasenkoa84db182018-02-20 15:57:45 +01009 const char *target,
Harald van Dijk8c24af92018-05-22 17:34:31 +020010 const char *linkname,
11 int hard_link)
Denys Vlasenkobc9bbeb2017-08-10 11:52:42 +020012{
Harald van Dijk8c24af92018-05-22 17:34:31 +020013 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 Vlasenkobc9bbeb2017-08-10 11:52:42 +020016 );
Denys Vlasenkoa84db182018-02-20 15:57:45 +010017 return;
Denys Vlasenkobc9bbeb2017-08-10 11:52:42 +020018 }
Denys Vlasenkoa84db182018-02-20 15:57:45 +010019 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 Vlasenkobc9bbeb2017-08-10 11:52:42 +020026
Harald van Dijk8c24af92018-05-22 17:34:31 +020027void FAST_FUNC create_links_from_list(llist_t *list)
Denys Vlasenkoa84db182018-02-20 15:57:45 +010028{
29 while (list) {
30 char *target;
Denys Vlasenkobc9bbeb2017-08-10 11:52:42 +020031
Harald van Dijk8c24af92018-05-22 17:34:31 +020032 target = list->data + 1 + strlen(list->data + 1) + 1;
33 if ((*list->data ? link : symlink) (target, list->data + 1)) {
Denys Vlasenkoa84db182018-02-20 15:57:45 +010034 /* shared message */
35 bb_error_msg_and_die("can't create %slink '%s' to '%s'",
Harald van Dijk8c24af92018-05-22 17:34:31 +020036 *list->data ? "hard" : "sym",
37 list->data + 1, target
Denys Vlasenkoa84db182018-02-20 15:57:45 +010038 );
Denys Vlasenkobc9bbeb2017-08-10 11:52:42 +020039 }
Denys Vlasenkoa84db182018-02-20 15:57:45 +010040 list = list->link;
Denys Vlasenkobc9bbeb2017-08-10 11:52:42 +020041 }
42}