Skip to content

Commit 2f21dbd

Browse files
fix: verify name of webgraph and output directory
Check the name of the webgraph and output directory beforehand to avoid that odd file and directory names cause errors during webgraph processing.
1 parent ee4aa59 commit 2f21dbd

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/script/webgraph_ranking/process_webgraph.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,31 @@ if ! shift 3; then
88
exit 1
99
fi
1010

11+
if ! [[ "$NAME" =~ ^[a-zA-Z0-9_][a-zA-Z0-9_.-]+[a-zA-Z0-9_]$ ]]; then
12+
echo "Graph <name> should only contain [a-zA-Z0-9_.-] and start and end with [a-zA-Z0-9_]."
13+
echo "The graph name '$NAME' might not be safe as a graph base name (without suffix)"
14+
echo "or directory name to place the graph files into. Exiting..."
15+
exit 1
16+
fi
17+
1118
OUTPUTDIR="$NAME"
1219
if [ -n "$1" ]; then
1320
OUTPUTDIR="$1"
1421
shift
22+
case "$OUTPUTDIR" in
23+
*" "* )
24+
echo "The output directory <output_dir> must not contain white space. Exiting..."
25+
exit 1
26+
;;
27+
esac
1528
fi
1629
FULLNAME="$OUTPUTDIR/$NAME"
1730

31+
32+
set -e # fail if creation of output directory fails
33+
1834
if [ -d "$OUTPUTDIR" ]; then
19-
# TODO: OUTPUTDIR must not contain whitespace, '/', etc.
2035
echo "Output directory $OUTPUTDIR/ exists"
21-
# exit 1
2236
else
2337
mkdir "$OUTPUTDIR"
2438
fi

0 commit comments

Comments
 (0)