From 9ca369301e53f9e46a929ff4e0e44678208aac42 Mon Sep 17 00:00:00 2001 From: andy5995 Date: Tue, 5 Nov 2024 22:16:42 -0600 Subject: [PATCH] Remove recently added support for symlinks This partially reverts #462 --- src/config_rmw.c | 32 ++++++++++---------------------- src/config_rmw.h | 1 - src/restore.c | 8 -------- src/trashinfo.h | 4 +--- src/utils.c | 17 +++++++++++++++-- src/utils.h | 5 ++++- 6 files changed, 30 insertions(+), 37 deletions(-) diff --git a/src/config_rmw.c b/src/config_rmw.c index 1bd3e46f..26b67075 100644 --- a/src/config_rmw.c +++ b/src/config_rmw.c @@ -234,6 +234,14 @@ parse_line_waste(st_waste *waste_curr, struct Canfigger *node, fatal_malloc(); strcpy(waste_curr->parent, tmp_waste_parent_folder); + if (is_symlink(waste_curr->parent)) + { + print_msg_warn(); + printf(_("symbolic link: %s\n\ + :In the future, rmw will not allow using symbolic links\n\ + :as waste parent folders.\n"), waste_curr->parent); + } + /* and the files... */ waste_curr->files = join_paths(waste_curr->parent, lit_files); waste_curr->len_files = strlen(waste_curr->files); @@ -274,28 +282,8 @@ parse_line_waste(st_waste *waste_curr, struct Canfigger *node, struct stat st, mp_st; if (!lstat(waste_curr->parent, &st)) { - if (S_ISLNK(st.st_mode)) - { - char *res_path = realpath(waste_curr->parent, NULL); - if (res_path != NULL) - { - waste_curr->resolved_symlink = res_path; - if (!lstat(res_path, &st)) - waste_curr->dev_num = st.st_dev; - else - msg_err_lstat(waste_curr->parent, __func__, __LINE__); - } - else - { - perror("realpath"); - exit(EXIT_FAILURE); - } - } - else - { - waste_curr->resolved_symlink = NULL; - waste_curr->dev_num = st.st_dev; - } + waste_curr->dev_num = st.st_dev; + // printf("actual: %ld |major: %d | minor: %d\n", st.st_dev, major(st.st_dev), minor(st.st_dev)); char tmp[PATH_MAX]; strcpy(tmp, waste_curr->parent); diff --git a/src/config_rmw.h b/src/config_rmw.h index 3cb2e8f3..f74a96dc 100644 --- a/src/config_rmw.h +++ b/src/config_rmw.h @@ -35,7 +35,6 @@ typedef struct char uid[10]; st_waste *st_waste_folder_props_head; bool force_required; - bool fake_media_root; int expire_age; } st_config; diff --git a/src/restore.c b/src/restore.c index f5531e7d..7a87efc1 100644 --- a/src/restore.c +++ b/src/restore.c @@ -85,14 +85,6 @@ restore(const char *src, st_time *st_time_var, waste_match = true; break; } - else if (waste_curr->resolved_symlink) - { - if (strcmp(waste_curr->resolved_symlink, waste_parent) == 0) - { - waste_match = true; - break; - } - } waste_curr = waste_curr->next_node; } diff --git a/src/trashinfo.h b/src/trashinfo.h index 125e6027..7e26a933 100644 --- a/src/trashinfo.h +++ b/src/trashinfo.h @@ -1,7 +1,7 @@ /* This file is part of rmw -Copyright (C) 2012-2021 Andy Alt (arch_stanton5995@proton.me) +Copyright (C) 2012-2024 Andy Alt (arch_stanton5995@proton.me) Other authors: https://github.com/theimpossibleastronaut/rmw/blob/master/AUTHORS.md This program is free software: you can redistribute it and/or modify @@ -71,8 +71,6 @@ struct st_waste bool is_btrfs; - char *resolved_symlink; - /** Points to the previous WASTE directory in the linked list */ st_waste *prev_node; diff --git a/src/utils.c b/src/utils.c index 27e1dbf7..0872e14f 100644 --- a/src/utils.c +++ b/src/utils.c @@ -27,6 +27,21 @@ along with this program. If not, see . #include "utils.h" #include "messages.h" +bool +is_symlink(const char *path) +{ + int fd = open(path, O_RDONLY | O_NOFOLLOW); + if (fd != -1) + { + close(fd); + return false; + } + else if (errno == ELOOP) + return true; + + return false; +} + /* * name: rmw_dirname @@ -174,8 +189,6 @@ dispose_waste(st_waste *node) free(node->info); if (node->media_root != NULL) free(node->media_root); - if (node->resolved_symlink != NULL) - free(node->resolved_symlink); free(node); } diff --git a/src/utils.h b/src/utils.h index cdf5434d..5929ca9c 100644 --- a/src/utils.h +++ b/src/utils.h @@ -31,7 +31,8 @@ enum { P_STATE_ERR = -1, P_STATE_ENOENT, - P_STATE_EXISTS + P_STATE_EXISTS, + P_STATE_SYMLINK }; #define join_paths(...) real_join_paths(__VA_ARGS__, NULL) @@ -39,6 +40,8 @@ enum #define LEN_MAX_HUMAN_READABLE_SIZE (sizeof "xxxx.y GiB") #define LEN_MAX_FILE_DETAILS (LEN_MAX_HUMAN_READABLE_SIZE + sizeof "[] (D)" - 1) +bool is_symlink(const char *path); + char *rmw_dirname(char *path); int rmw_mkdir(const char *dir);