Skip to content

Commit

Permalink
[wip]allow, write, and expect relative paths in Path key, in some cases
Browse files Browse the repository at this point in the history
(fixes #299)
  • Loading branch information
andy5995 committed Apr 8, 2021
1 parent 2d053f7 commit 4023813
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 23 deletions.
40 changes: 18 additions & 22 deletions src/config_rmw.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,6 @@ print_config (FILE *stream)
fputs ("# force_required\n", stream);
}


/*!
* If a string begins with 'c', returns a pointer to the first occurrence
* in the string after 'c'
*/
#ifndef TEST_LIB
static
#endif
char *
del_char_shift_left (const char c, char *src_str)
{
if (*src_str != c)
return src_str;

while (*src_str == c)
src_str++;

return src_str;
}


/*
* replace part of a string, adapted from code by Gazl
* https://www.linuxquestions.org/questions/showthread.php?&p=5794938#post5794938
Expand Down Expand Up @@ -337,9 +316,26 @@ parse_line_waste (st_waste * waste_curr, const char * line_ptr,
* Really, if we get to this point, lstat shouldn't have any problem,
* checking return values is good practice so we'll do it.
*/
struct stat st;
struct stat st, mp_st;
if (!lstat (waste_curr->parent, &st))
{
waste_curr->dev_num = st.st_dev;
waste_curr->mount_point = calloc (1, strlen (dirname (waste_curr->parent)) + 1);
strcpy (waste_curr->mount_point, dirname (waste_curr->parent));
if (!lstat (waste_curr->mount_point, &mp_st))
{
if (mp_st.st_dev == waste_curr->dev_num || strcmp ("/", waste_curr->mount_point) != 0)
{
waste_curr->at_toplevel = false;
free (waste_curr->mount_point);
waste_curr->mount_point = NULL;
}
else
waste_curr->at_toplevel = true;
}
else
msg_err_lstat(waste_curr->parent, __func__, __LINE__);
}
else
msg_err_lstat(waste_curr->parent, __func__, __LINE__);

Expand Down
2 changes: 1 addition & 1 deletion src/config_rmw.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* This file is part of rmw<https://remove-to-waste.info/>
*
* Copyright (C) 2012-2019 Andy Alt (andy400-dev@yahoo.com)
* Copyright (C) 2012-2021 Andy Alt (andy400-dev@yahoo.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
10 changes: 10 additions & 0 deletions src/restore_rmw.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ restore (const char *argv, st_time *st_time_var, const rmw_options * cli_user_op
return -1;
}

/*
if (file.dest[0] == '/')
{
del_char_shift_left ('/', file.dest);
char mount_point[LEN_MAX_PATH];
strcpy (mount_point, dirname (file_arg));
strcpy (mount_point, dirname (mount_point));
}
*/

/* Check for duplicate filename
*/
if (exists (file.dest))
Expand Down
17 changes: 17 additions & 0 deletions src/strings_rmw.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,20 @@ bool isdotdir (const char *dir)

return false;
}


/*!
* If a string begins with 'c', returns a pointer to the first occurrence
* in the string after 'c'
*/
char *
del_char_shift_left (const char c, char *src_str)
{
if (*src_str != c)
return src_str;

while (*src_str == c)
src_str++;

return src_str;
}
4 changes: 4 additions & 0 deletions src/strings_rmw.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ int
resolve_path (const char *src, char *abs_path);

bool isdotdir (const char *dir);


char *
del_char_shift_left (const char c, char *src_str);
8 changes: 8 additions & 0 deletions src/trashinfo_rmw.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ struct st_waste
*/
bool removable;

/*
* If a waste folder is at the top level, a relative path will be
* used (per the Freedesktop trash spec). See
https://github.com/theimpossibleastronaut/rmw/issues/299 for more
info */
bool at_toplevel;
char *mount_point;

/** Points to the previous WASTE directory in the linked list
*/
st_waste *prev_node;
Expand Down
2 changes: 2 additions & 0 deletions src/utils_rmw.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ dispose_waste (st_waste *node)
if (node != NULL)
{
dispose_waste (node->next_node);
if (node->mount_point != NULL)
free (node->mount_point);
free (node);
}
return;
Expand Down

0 comments on commit 4023813

Please sign in to comment.