2017-08-10 15:22:42 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
|
|
|
*/
|
|
|
|
#include "libbb.h"
|
|
|
|
#include "bb_archive.h"
|
|
|
|
|
2018-05-22 21:04:31 +05:30
|
|
|
void FAST_FUNC create_or_remember_link(llist_t **link_placeholders,
|
2018-02-20 20:27:45 +05:30
|
|
|
const char *target,
|
2018-05-22 21:04:31 +05:30
|
|
|
const char *linkname,
|
|
|
|
int hard_link)
|
2017-08-10 15:22:42 +05:30
|
|
|
{
|
2018-05-22 21:04:31 +05:30
|
|
|
if (hard_link || target[0] == '/' || strstr(target, "..")) {
|
|
|
|
llist_add_to_end(link_placeholders,
|
|
|
|
xasprintf("%c%s%c%s", hard_link, linkname, '\0', target)
|
2018-02-20 20:27:45 +05:30
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (symlink(target, linkname) != 0) {
|
|
|
|
/* shared message */
|
|
|
|
bb_perror_msg_and_die("can't create %slink '%s' to '%s'",
|
|
|
|
"sym", linkname, target
|
2017-08-10 15:22:42 +05:30
|
|
|
);
|
|
|
|
}
|
2018-02-20 20:27:45 +05:30
|
|
|
}
|
2017-08-10 15:22:42 +05:30
|
|
|
|
2018-05-22 21:04:31 +05:30
|
|
|
void FAST_FUNC create_links_from_list(llist_t *list)
|
2018-02-20 20:27:45 +05:30
|
|
|
{
|
|
|
|
while (list) {
|
|
|
|
char *target;
|
2017-08-10 15:22:42 +05:30
|
|
|
|
2018-05-22 21:04:31 +05:30
|
|
|
target = list->data + 1 + strlen(list->data + 1) + 1;
|
|
|
|
if ((*list->data ? link : symlink) (target, list->data + 1)) {
|
2018-02-20 20:27:45 +05:30
|
|
|
/* shared message */
|
|
|
|
bb_error_msg_and_die("can't create %slink '%s' to '%s'",
|
2018-05-22 21:04:31 +05:30
|
|
|
*list->data ? "hard" : "sym",
|
|
|
|
list->data + 1, target
|
2018-02-20 20:27:45 +05:30
|
|
|
);
|
2017-08-10 15:22:42 +05:30
|
|
|
}
|
2018-02-20 20:27:45 +05:30
|
|
|
list = list->link;
|
2017-08-10 15:22:42 +05:30
|
|
|
}
|
|
|
|
}
|