[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [chutney/master] Support non-existing absolute paths for the data directory
commit 09dc71a8aae5245757a5988c97b8c4824bebbc3b
Author: Steven Engler <sengler@xxxxxxxxxxxx>
Date: Wed Jan 22 00:50:10 2020 -0500
Support non-existing absolute paths for the data directory
If the user provides an absolute path for the data directory with
'CHUTNEY_DATA_DIR' or '--net-dir', it should not be overwritten in
the case that the directory does not exist. Chutney will
automatically create this directory.
---
lib/chutney/TorNet.py | 6 +++++-
tools/bootstrap-network.sh | 25 +++++++++++++++++--------
tools/hsaddress.sh | 25 +++++++++++++++++--------
tools/warnings.sh | 25 +++++++++++++++++--------
4 files changed, 56 insertions(+), 25 deletions(-)
diff --git a/lib/chutney/TorNet.py b/lib/chutney/TorNet.py
index ea3b320..66e19d2 100644
--- a/lib/chutney/TorNet.py
+++ b/lib/chutney/TorNet.py
@@ -131,9 +131,13 @@ def get_absolute_chutney_path():
return os.path.abspath(relative_chutney_path)
def get_absolute_net_path():
+ data_dir = os.environ.get('CHUTNEY_DATA_DIR', 'net')
+ if os.path.isabs(data_dir):
+ # if we are given an absolute path, we should use it
+ return data_dir
# use the chutney path as the default
absolute_chutney_path = get_absolute_chutney_path()
- relative_net_path = os.environ.get('CHUTNEY_DATA_DIR', 'net')
+ relative_net_path = data_dir
# but what is it relative to?
# let's check if it's in CHUTNEY_PATH first, to preserve
# backwards-compatible behaviour
diff --git a/tools/bootstrap-network.sh b/tools/bootstrap-network.sh
index 34db0f3..7cfc55e 100755
--- a/tools/bootstrap-network.sh
+++ b/tools/bootstrap-network.sh
@@ -26,14 +26,23 @@ if [ -d "$PWD/$CHUTNEY_PATH" ] && [ -x "$PWD/$CHUTNEY_PATH/chutney" ]; then
fi
# Get a working net path
-if [ ! -d "$CHUTNEY_DATA_DIR" ]; then
- # looks like a broken path: use the chutney path as a base
- export CHUTNEY_DATA_DIR="$CHUTNEY_PATH/net"
-fi
-if [ -d "$PWD/$CHUTNEY_DATA_DIR" ]; then
- # looks like a relative path: make chutney path absolute
- export CHUTNEY_DATA_DIR="$PWD/$CHUTNEY_DATA_DIR"
-fi
+case "$CHUTNEY_DATA_DIR" in
+ /*)
+ # if an absolute path, then leave as-is
+ # chutney will make this directory automatically if needed
+ ;;
+ *)
+ # if a relative path
+ if [ ! -d "$CHUTNEY_DATA_DIR" ]; then
+ # looks like a broken path: use the chutney path as a base
+ export CHUTNEY_DATA_DIR="$CHUTNEY_PATH/net"
+ fi
+ if [ -d "$PWD/$CHUTNEY_DATA_DIR" ]; then
+ # looks like a relative path: make chutney path absolute
+ export CHUTNEY_DATA_DIR="$PWD/$CHUTNEY_DATA_DIR"
+ fi
+ ;;
+esac
CHUTNEY="$CHUTNEY_PATH/chutney"
myname=$(basename "$0")
diff --git a/tools/hsaddress.sh b/tools/hsaddress.sh
index bc1d123..b975f0a 100755
--- a/tools/hsaddress.sh
+++ b/tools/hsaddress.sh
@@ -19,14 +19,23 @@ if [ -d "$PWD/$CHUTNEY_PATH" ] && [ -x "$PWD/$CHUTNEY_PATH/chutney" ]; then
fi
# Get a working net path
-if [ ! -d "$CHUTNEY_DATA_DIR" ]; then
- # looks like a broken path: use the chutney path as a base
- export CHUTNEY_DATA_DIR="$CHUTNEY_PATH/net"
-fi
-if [ -d "$PWD/$CHUTNEY_DATA_DIR" ]; then
- # looks like a relative path: make chutney path absolute
- export CHUTNEY_DATA_DIR="$PWD/$CHUTNEY_DATA_DIR"
-fi
+case "$CHUTNEY_DATA_DIR" in
+ /*)
+ # if an absolute path, then leave as-is
+ # chutney will make this directory automatically if needed
+ ;;
+ *)
+ # if a relative path
+ if [ ! -d "$CHUTNEY_DATA_DIR" ]; then
+ # looks like a broken path: use the chutney path as a base
+ export CHUTNEY_DATA_DIR="$CHUTNEY_PATH/net"
+ fi
+ if [ -d "$PWD/$CHUTNEY_DATA_DIR" ]; then
+ # looks like a relative path: make chutney path absolute
+ export CHUTNEY_DATA_DIR="$PWD/$CHUTNEY_DATA_DIR"
+ fi
+ ;;
+esac
NAME=$(basename "$0")
DEST="$CHUTNEY_DATA_DIR/nodes"
diff --git a/tools/warnings.sh b/tools/warnings.sh
index b8c263d..79a135c 100755
--- a/tools/warnings.sh
+++ b/tools/warnings.sh
@@ -23,14 +23,23 @@ if [ -d "$PWD/$CHUTNEY_PATH" ] && [ -x "$PWD/$CHUTNEY_PATH/chutney" ]; then
fi
# Get a working net path
-if [ ! -d "$CHUTNEY_DATA_DIR" ]; then
- # looks like a broken path: use the chutney path as a base
- export CHUTNEY_DATA_DIR="$CHUTNEY_PATH/net"
-fi
-if [ -d "$PWD/$CHUTNEY_DATA_DIR" ]; then
- # looks like a relative path: make chutney path absolute
- export CHUTNEY_DATA_DIR="$PWD/$CHUTNEY_DATA_DIR"
-fi
+case "$CHUTNEY_DATA_DIR" in
+ /*)
+ # if an absolute path, then leave as-is
+ # chutney will make this directory automatically if needed
+ ;;
+ *)
+ # if a relative path
+ if [ ! -d "$CHUTNEY_DATA_DIR" ]; then
+ # looks like a broken path: use the chutney path as a base
+ export CHUTNEY_DATA_DIR="$CHUTNEY_PATH/net"
+ fi
+ if [ -d "$PWD/$CHUTNEY_DATA_DIR" ]; then
+ # looks like a relative path: make chutney path absolute
+ export CHUTNEY_DATA_DIR="$PWD/$CHUTNEY_DATA_DIR"
+ fi
+ ;;
+esac
show_warnings() {
# Work out the file and filter settings
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits