blob: 8dcafeaa1b2ef99466a2288272ed7678b8027f28 [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
Denys Vlasenkoa84db182018-02-20 15:57:45 +01008void FAST_FUNC create_or_remember_symlink(llist_t **symlink_placeholders,
9 const char *target,
10 const char *linkname)
Denys Vlasenkobc9bbeb2017-08-10 11:52:42 +020011{
Denys Vlasenkoa84db182018-02-20 15:57:45 +010012 if (target[0] == '/' || strstr(target, "..")) {
13 llist_add_to(symlink_placeholders,
14 xasprintf("%s%c%s", linkname, '\0', target)
Denys Vlasenkobc9bbeb2017-08-10 11:52:42 +020015 );
Denys Vlasenkoa84db182018-02-20 15:57:45 +010016 return;
Denys Vlasenkobc9bbeb2017-08-10 11:52:42 +020017 }
Denys Vlasenkoa84db182018-02-20 15:57:45 +010018 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 Vlasenkobc9bbeb2017-08-10 11:52:42 +020025
Denys Vlasenkoa84db182018-02-20 15:57:45 +010026void FAST_FUNC create_symlinks_from_list(llist_t *list)
27{
28 while (list) {
29 char *target;
Denys Vlasenkobc9bbeb2017-08-10 11:52:42 +020030
Denys Vlasenkoa84db182018-02-20 15:57:45 +010031 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 Vlasenkobc9bbeb2017-08-10 11:52:42 +020038 }
Denys Vlasenkoa84db182018-02-20 15:57:45 +010039 list = list->link;
Denys Vlasenkobc9bbeb2017-08-10 11:52:42 +020040 }
41}