[tor-commits] [guardfraction/master] Use a tempdir for storing the consensus as databaser.py cannot read from stdin

asn at torproject.org asn at torproject.org
Tue Feb 24 13:45:03 UTC 2015


commit bc61d7bf5e0164cb36b4e073f99b0f1d8de202fe
Author: Peter Palfrader <peter at palfrader.org>
Date:   Wed Feb 4 16:46:23 2015 +0100

    Use a tempdir for storing the consensus as databaser.py cannot read from stdin
---
 guardfraction_cron.sh |   17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/guardfraction_cron.sh b/guardfraction_cron.sh
index eb72ca8..da90247 100755
--- a/guardfraction_cron.sh
+++ b/guardfraction_cron.sh
@@ -19,9 +19,6 @@ DAYS_WORTH=90
 # Where the guardfraction output file should be placed.
 GUARDFRACTION_OUTPUT_FILE="$STATE_DIR/guardfraction.output"
 
-# Where the newest consensus should be placed.
-NEWEST_CONSENSUS_DIR="$STATE_DIR/newest_consensus/"
-
 # Use flock to avoid parallel runs of the script
 exec 9< "$STATE_DIR"
 if ! flock -n -e 9; then
@@ -29,13 +26,11 @@ if ! flock -n -e 9; then
         exit 1
 fi
 
-# Create dir structure if it doesn't exist
-mkdir -p "$NEWEST_CONSENSUS_DIR"
+tmpdir=`mktemp -d "/tmp/guardfraction-XXXXXX"`
+trap "rm -rf '$tmpdir'" EXIT
 
 # Download latest consensus.
-# XXX Replace this with a cp from DataDirectory or something.
-# XXX cp "$DATA_DIRECTORY/cached-microdesc-consensus" "$NEWEST_CONSENSUS_DIR/consensus_`date +"%Y%m%d-%H%M%S"`"
-torify wget -q http://128.31.0.39:9131/tor/status-vote/current/consensus -O "$NEWEST_CONSENSUS_DIR/consensus_$(date +"%Y%m%d-%H%M%S")"
+torify wget -q http://128.31.0.39:9131/tor/status-vote/current/consensus -O "$tmpdir/consensus"
 
 # Bail on error
 if [ "$?" != 0 ]
@@ -50,7 +45,7 @@ cd "$GUARDFRACTION_SRC"
 
 # Import latest consensus to our database.
 # (suppress any output because of cron job)
-python databaser.py --db-file="$STATE_DIR/guardfraction.db" "$NEWEST_CONSENSUS_DIR"
+python databaser.py --db-file="$STATE_DIR/guardfraction.db" "$tmpdir"
 
 # Bail on error
 if [ "$?" != 0 ]
@@ -61,10 +56,6 @@ fi
 
 # echo "[*] Imported!"
 
-# Move latest consensus to old consensuses dir
-# XXX Do we even want to keep the old consensus around?
-rm "$NEWEST_CONSENSUS_DIR"/*
-
 # Calculate guardfraction
 python guardfraction.py --db-file="$STATE_DIR/guardfraction.db" --output="$GUARDFRACTION_OUTPUT_FILE" "$DAYS_WORTH"
 





More information about the tor-commits mailing list