Skip to content

Commit

Permalink
bugfix: write and parse relative paths within trashinfo (fixes #299)
Browse files Browse the repository at this point in the history
* allow script tests to run in parallel (use different dirs)
* add unit test for parse_line_waste()
* get UID for basic test script
* allow, write, and expect relative paths in Path key, in some cases
  • Loading branch information
andy5995 committed Apr 18, 2021
1 parent d883e36 commit 89f84d2
Show file tree
Hide file tree
Showing 33 changed files with 347 additions and 104 deletions.
18 changes: 13 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ matrix:
- os: linux
dist: bionic
compiler: gcc
env: MATRIX_EVAL="CC=gcc-6 && CXX=g++-6"
env:
- MATRIX_EVAL="CC=gcc-6 && CXX=g++-6"
- USE_VALGRIND=true
- os: linux
dist: bionic
compiler: gcc # defaults to version 7 on bionic
Expand All @@ -42,6 +44,7 @@ matrix:
env:
- MATRIX_EVAL="CC=gcc-8 && CXX=g++-8"
- CONFIGURE_OPTS="--enable-release"
- RMW_FAKE_MEDIA_ROOT=true
- os: linux
dist: bionic
compiler: gcc
Expand All @@ -51,7 +54,10 @@ matrix:
- ubuntu-toolchain-r-test
packages:
- g++-9
env: MATRIX_EVAL="CC=gcc-9 && CXX=g++-9"
env:
- MATRIX_EVAL="CC=gcc-9 && CXX=g++-9"
- RMW_FAKE_MEDIA_ROOT=true
- USE_VALGRIND=true
- os: linux
dist: bionic
compiler: gcc
Expand Down Expand Up @@ -98,6 +104,8 @@ matrix:
dist: focal
compiler: clang

# purging test fails on osx
# See https://github.com/theimpossibleastronaut/rmw/issues/283 for details
# osx
- os: osx
osx_image: xcode11.6
Expand All @@ -106,7 +114,7 @@ matrix:
osx_image: xcode12.2
env: XCODE="true"

allow_failures:
# allow_failures:
- os: osx

before_install:
Expand All @@ -116,7 +124,7 @@ before_install:
if [ -n "$MATRIX_EVAL" ] && [ "$TRAVIS_COMPILER" != "clang" ] && [ "$CC" != "gcc-9" ] && [ "$CC" != "gcc-10" ]; then
sudo apt-get install -y $CC;
fi;
if [ "$CC" = "gcc-6" ]; then
if [ "$USE_VALGRIND" = "true" ]; then
sudo apt-get install -y valgrind;
fi;
else
Expand All @@ -132,7 +140,7 @@ script:
- ../configure ${CONFIGURE_OPTS}
- if [ -z "$DISTCHECK_ONLY" ]; then
make &&
make check;
make check -j5;
r=$?;
if test "x$r" != x0; then
cat test/test-suite.log;
Expand Down
13 changes: 13 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
=== rmw ChangeLog ===

2021-04-08

* bugfix: When restoring files from removable media or devices, rmw
will now process relative paths (this primarily affects users who
trash a file with the "move to trash" option from their desktop, and
then later try to restore with rmw. See
https://github.com/theimpossibleastronaut/rmw/issues/299 for more
information).

* Removed deprecated config option (purgeDays)

* Minor updates to tests infrastructure

2021-03-01

* rmw v0.7.06 released
Expand Down
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@
GMSGFMT = @GMSGFMT@
GMSGFMT_015 = @GMSGFMT_015@
GREP = @GREP@
HOME_TEST_DIR = @HOME_TEST_DIR@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
Expand Down
10 changes: 9 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ gt_needs=
ac_subst_vars='am__EXEEXT_FALSE
am__EXEEXT_TRUE
LTLIBOBJS
HOME_TEST_DIR
POSUB
LTLIBINTL
LIBINTL
Expand Down Expand Up @@ -2931,7 +2932,6 @@ else
fi
AM_BACKSLASH='\'
ac_config_headers="$ac_config_headers src/config.h:config.in"
Expand Down Expand Up @@ -9372,6 +9372,14 @@ $as_echo "#define HAVE_DCGETTEXT 1" >>confdefs.h
#AX_VALGRIND_DFLT([sgcheck], [off])
#AX_VALGRIND_CHECK
if test "x$ac_pwd" = x; then
as_fn_error $? "while determining top build directory" "$LINENO" 5
fi
HOME_TEST_DIR=$ac_pwd/test/rmw-tests-home
ac_config_files="$ac_config_files Makefile src/Makefile man/Makefile test/Makefile po/Makefile.in test/VARS"
Expand Down
9 changes: 8 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
AC_PREREQ(2.69)
AC_INIT([rmw], [0.7.07-dev], [https://github.com/theimpossibleastronaut/rmw/issues],,[https://remove-to-waste.info/])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([-Wall subdir-objects foreign no-dependencies])
AM_SILENT_RULES([yes])
AC_PREREQ(2.69)
AC_CONFIG_HEADERS([src/config.h:config.in])

AX_IS_RELEASE([git-directory])
Expand Down Expand Up @@ -89,6 +89,13 @@ fi

AM_GNU_GETTEXT([external], [need-formatstring-macros])
AM_GNU_GETTEXT_VERSION([0.19.8])
#AX_VALGRIND_DFLT([sgcheck], [off])
#AX_VALGRIND_CHECK

if test "x$ac_pwd" = x; then
AC_MSG_ERROR(while determining top build directory)
fi
AC_SUBST(HOME_TEST_DIR, [$ac_pwd/test/rmw-tests-home])

AC_CONFIG_FILES([ Makefile
src/Makefile
Expand Down
15 changes: 15 additions & 0 deletions docs/code-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ layout: default
<li><a href="#testing_purge">Testing the purge feature</a></li>
<li><a href="#profiling">Profiling</a></li>
<li><a href="#create_test">How to Create a Unit Test</a></li>
<li><a href="#env_vars">Influential Environmental Variables</a></li>
</ul>

<h2 id="general_testing">General Testing</h2>
Expand Down Expand Up @@ -81,3 +82,17 @@ then I've added the test to
[test/Makefile.am](https://github.com/theimpossibleastronaut/rmw/commit/edaf560929e8589bac8874b93ae3520962ffab39#diff-7d1a3afeff4f7c00c95d6be6f2847e6e)
and re-ran 'automake'.

<h2 id="env_vars">Influential Environmental Variables</h2>

RMW_FAKE_MEDIA_ROOT (used only for code testing) when rmw-ing files,
relative paths are written to the Path key of a trashinfo file. rmw is
faked into believing that all waste directories are at the top level of
a device or removable medium (see <a
href="https://github.com/theimpossibleastronaut/rmw/issues/299">issue
299</a> for more information). Only accepts "true" as an argument; any
other value will register as "false".

<p class="w3-code">
ex: RMW_FAKE_MEDIA_ROOT=true rmw [file(s) to be removed]
</p>

1 change: 1 addition & 0 deletions man/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@
GMSGFMT = @GMSGFMT@
GMSGFMT_015 = @GMSGFMT_015@
GREP = @GREP@
HOME_TEST_DIR = @HOME_TEST_DIR@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@
GMSGFMT = @GMSGFMT@
GMSGFMT_015 = @GMSGFMT_015@
GREP = @GREP@
HOME_TEST_DIR = @HOME_TEST_DIR@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
Expand Down
52 changes: 44 additions & 8 deletions src/config_rmw.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,13 @@ realize_waste_line (char *str)
* This function is called when the "WASTE" option is encountered in the
* config file. The line is parsed and added to the linked list of WASTE
* folders.
*
* @bug <a href="https://github.com/theimpossibleastronaut/rmw/issues/213">rmw is unable to use the system trash folder on a Mac</a>
*/
static st_waste *
#ifndef TEST_LIB
static
#endif
st_waste *
parse_line_waste (st_waste * waste_curr, const char * line_ptr,
const rmw_options * cli_user_options)
const rmw_options * cli_user_options, bool fake_media_root)
{
bool removable = 0;

Expand Down Expand Up @@ -337,9 +338,37 @@ 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;

/* We're reusing 'tmp' here after every call to dirname()
* An excerpt from the dirname() man page states:
*
* char *dirname(char *path);
*
* Both dirname() and basename() may modify the contents of path, so it may be de‐
* sirable to pass a copy when calling one of these functions.
*/
char tmp[LEN_MAX_PATH];
strcpy (tmp, waste_curr->parent);
char *media_root_ptr = dirname (tmp);
waste_curr->media_root = calloc (1, strlen (media_root_ptr) + 1);
chk_malloc (waste_curr->media_root, __func__, __LINE__);
strcpy (waste_curr->media_root, media_root_ptr);
strcpy (tmp, waste_curr->media_root);
if (!lstat (dirname (tmp), &mp_st))
{
if (mp_st.st_dev == waste_curr->dev_num && !fake_media_root)
{
free (waste_curr->media_root);
waste_curr->media_root = NULL;
}
}
else
msg_err_lstat(waste_curr->parent, __func__, __LINE__);
}
else
msg_err_lstat(waste_curr->parent, __func__, __LINE__);

Expand Down Expand Up @@ -465,8 +494,7 @@ parse_config_file (const rmw_options * cli_user_options, st_config *st_config_da
/**
* assign purge_after the value from config file unless set by --purge
*/
if (strncmp (line_ptr, "purge_after", 11) == 0 ||
strncmp (line_ptr, "purgeDays", 9) == 0)
if (strncmp (line_ptr, "purge_after", 11) == 0)
{
if (cli_user_options->want_purge <= 0)
{
Expand All @@ -493,7 +521,7 @@ parse_config_file (const rmw_options * cli_user_options, st_config *st_config_da
else if (strncmp ("WASTE", line_ptr, 5) == 0)
{
st_waste *st_new_waste_ptr =
parse_line_waste (waste_curr, line_ptr, cli_user_options);
parse_line_waste (waste_curr, line_ptr, cli_user_options, st_config_data->fake_media_root);
if (st_new_waste_ptr != NULL)
waste_curr = st_new_waste_ptr;
else
Expand Down Expand Up @@ -556,6 +584,14 @@ init_config_data (st_config *x)
*/
x->purge_after = DEFAULT_PURGE_AFTER;
x->force_required = 0;

const char *f = getenv ("RMW_FAKE_MEDIA_ROOT");
if (f != NULL)
x->fake_media_root = (strcmp (f, "true") == 0) ? true : false;
else
x->fake_media_root = false;
if (verbose)
printf ("RMW_FAKE_MEDIA_ROOT = %s\n", x->fake_media_root == false ? "false" : "true");
}

void
Expand Down
7 changes: 6 additions & 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 Expand Up @@ -49,6 +49,7 @@ typedef struct {
st_waste *st_waste_folder_props_head;
int purge_after;
bool force_required;
bool fake_media_root;
} st_config;

struct st_vars_to_check {
Expand All @@ -74,6 +75,10 @@ del_char_shift_left (const char c, char *src_str);

void
realize_waste_line (char *str);

st_waste *
parse_line_waste (st_waste * waste_curr, const char * line_ptr,
const rmw_options * cli_user_options, bool fake_media_root);
#endif

#endif
4 changes: 0 additions & 4 deletions src/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@

int verbose = 0;

#ifndef TEST_LIB
const char *HOMEDIR;
#else
const char *HOMEDIR = "/home/andy";
#endif
2 changes: 2 additions & 0 deletions src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
/*! The LEN_MAX_PATH macro is used as a shortcut throughout the program. */
#define LEN_MAX_PATH (PATH_MAX + 1)

#define LEN_MAX_ESCAPED_PATH (PATH_MAX * 3 + 1)

#define EBUF 11

extern int verbose;
Expand Down
2 changes: 1 addition & 1 deletion src/purging_rmw.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static off_t bytes_freed = 0;
static
#endif
int
rmdir_recursive (char *dirname, short unsigned level,
rmdir_recursive (const char *dirname, short unsigned level,
const int force)
{
if (level > RMDIR_MAX_DEPTH)
Expand Down
2 changes: 1 addition & 1 deletion src/purging_rmw.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ short orphan_maint (st_waste * waste_head, st_time * st_time_var,
int *orphan_ctr);
#else
int
rmdir_recursive (char *dirname, short unsigned level,
rmdir_recursive (const char *dirname, short unsigned level,
const int force);
#endif

Expand Down
Loading

0 comments on commit 89f84d2

Please sign in to comment.