Skip to content

Commit

Permalink
Remove recently added support for symlinks
Browse files Browse the repository at this point in the history
This partially reverts #462
  • Loading branch information
andy5995 committed Nov 6, 2024
1 parent beaa47f commit 9ca3693
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 37 deletions.
32 changes: 10 additions & 22 deletions src/config_rmw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/config_rmw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 0 additions & 8 deletions src/restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 1 addition & 3 deletions src/trashinfo.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This file is part of rmw<https://theimpossibleastronaut.github.io/rmw-website/>
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
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 15 additions & 2 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ 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)

#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);
Expand Down

0 comments on commit 9ca3693

Please sign in to comment.