aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEinhard Leichtfuß <alguien@respiranto.de>2019-04-04 00:29:44 +0200
committerEinhard Leichtfuß <alguien@respiranto.de>2019-04-04 00:29:44 +0200
commit51f58d7c4c984ec8ccc5ab0a3d31d04cd39d499c (patch)
tree89c3b5fbe4fc78116dab1998897ea2475477a914
parentab0cff3bb36721e982301e14435c0f4c8f313995 (diff)
downloadrsync-backup-51f58d7c4c984ec8ccc5ab0a3d31d04cd39d499c.tar.gz
rsync-backup-51f58d7c4c984ec8ccc5ab0a3d31d04cd39d499c.tar.xz
Fix bug: empty string considered as $PWD
Before, if the program was run with only a source argument, that has no destination associated (e.g. in the configuration file), the destination was accepted as the empty string, which translated to the local directory (due to relative adressing). This was due to the shell option nullglob, which now is unset in any situations where `test -v' is used, which currently is only the case in get_args. It is `test -v' that failed to recognize an undefined variable.
-rw-r--r--TODO3
-rwxr-xr-xrsync-backup13
2 files changed, 9 insertions, 7 deletions
diff --git a/TODO b/TODO
index 9198ac4..caa934b 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,4 @@
# -- BUGS -- #
-- $1 == /path/, where /path is configured behaves strangely.
- `- $1 == /path is fine.
- `- A backup is created in $PWD/
# -- TODO -- #
- For ssh, set up one single connection (maybe configurable?).
diff --git a/rsync-backup b/rsync-backup
index e0ed37a..0a7df33 100755
--- a/rsync-backup
+++ b/rsync-backup
@@ -2,7 +2,7 @@
#
# rsync-backup - a backup script using rsync.
#
-# Copyright 2015 - 2018 Einhard Leichtfuß
+# Copyright 2015 - 2019 Einhard Leichtfuß
#
# This file is part of rsync-backup.
#
@@ -38,7 +38,8 @@ typeset -r DATEFMT='%Y-%m-%d_%H%M%S'
# Shell options:
# nullglob: In case of a non-matching glob, return nothing.
# dotglob: Include dotfiles (except . and ..) in glob matching.
-typeset -r SHOPTS='nullglob dotglob'
+typeset -r SHOPTS='dotglob'
+typeset -r SHOPTS_AFTER_GET_ARGS='nullglob'
# Global program variables.
@@ -108,6 +109,8 @@ function main
# Set $src, $dest_path and $filter_args.
get_args "$@" || return $?
+ shopt -s $SHOPTS_AFTER_GET_ARGS
+
# Verify $src_path exists.
run_function "$src_host" src_check_path '' 'src_path src' || return $?
@@ -144,6 +147,8 @@ function main
#
# $@: command line parameters
#
+# requires the shell option nullglob to be _unset_. (for test -v to work)
+#
function get_args
{
if [ $# -eq 0 ]
@@ -161,7 +166,7 @@ function get_args
if [ $# -gt 1 ]
then
l_dest="$2"
- elif test -v bakpath[$src]
+ elif test -v bakpath[$src] # $# -eq 1
then
l_dest="${bakpath[$src]}"
else
@@ -261,7 +266,7 @@ function resolve_host_path
# $1: host: name
# $2: function to run: name
# $3: other functions to export: [name (. ' ' . name)*]
-# $4: variables to export: [name (. ' ' . name)*]
+# $4: variables to export: [name (. '[@]')? (. ' ' . name (. '[@]')?)*]
# ${@:5}: function arguments: string+
#
function run_function