]> git.xonotic.org Git - xonotic/xonotic.git/commitdiff
fix caching
authorRudolf Polzer <divverent@alientrap.org>
Mon, 21 Jun 2010 14:19:54 +0000 (16:19 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Mon, 21 Jun 2010 14:19:54 +0000 (16:19 +0200)
misc/tools/cached-converter.sh

index f8281f90bbf1d4617d7ce922cedb1b14f973de67..dd4e3b7d9de923140ae7689ccdd02989bd68d0ef 100755 (executable)
@@ -17,29 +17,40 @@ trap 'rm -rf "$tmpdir"' EXIT
 
 cached()
 {
+       flag=$1; shift
        method=$1; shift
        infile1=$1; shift
        infile2=$1; shift
        outfile1=$1; shift
        outfile2=$1; shift
+       if ! $flag; then
+               return 0
+       fi
        options=`echo "$*" | git hash-object --stdin`
        sum=`git hash-object "$infile1"`
        if [ -n "$infile2" ]; then
-       sum=$sum`git hash-object "$infile2"`
+               sum=$sum`git hash-object "$infile2"`
        fi
        mkdir -p "$CACHEDIR/$method-$options"
-       name1="$CACHEDIR/$method/$sum-1.${outfile1##*.}"
-       [ -z "$outfile2" ] || name2="$CACHEDIR/$method/$sum-2.${outfile2##*.}"
-       tempfile1="$name1.new"
-       [ -z "$outfile2" ] || tempfile2="$name2.new"
-       if "$method" "$infile1" "$infile2" "$tempfile1" "$tempfile2" "$@"; then
-       mv "$tempfile1" "$name1"
-       [ -z "$outfile2" ] || mv "$tempfile2" "$name2"
-       ln "$name1" "$outfile1" 2>/dev/null || cp "$name1" "$outfile1"
-       [ -z "$outfile2" ] || ln "$name2" "$outfile2" 2>/dev/null || cp "$name2" "$outfile2"
+       name1="$CACHEDIR/$method-$options/$sum-1.${outfile1##*.}"
+       [ -z "$outfile2" ] || name2="$CACHEDIR/$method-$options/$sum-2.${outfile2##*.}"
+       tempfile1="${name1%/*}/new-${name1##*/}"
+       [ -z "$outfile2" ] || tempfile2="${name2%/*}/new-${name2##*/}"
+       if [ -f "$name1" ]; then
+               echo "$name1 already there, caching"
+               sleep 10
+               ln "$name1" "$outfile1" 2>/dev/null || cp "$name1" "$outfile1"
+               [ -z "$outfile2" ] || ln "$name2" "$outfile2" 2>/dev/null || cp "$name2" "$outfile2"
+       elif "$method" "$infile1" "$infile2" "$tempfile1" "$tempfile2" "$@"; then
+               echo "$name1 not there, making"
+               sleep 10
+               mv "$tempfile1" "$name1"
+               [ -z "$outfile2" ] || mv "$tempfile2" "$name2"
+               ln "$name1" "$outfile1" 2>/dev/null || cp "$name1" "$outfile1"
+               [ -z "$outfile2" ] || ln "$name2" "$outfile2" 2>/dev/null || cp "$name2" "$outfile2"
        else
-       rm -f "$tempfile1"
-       rm -f "$tempfile2"
+               rm -f "$tempfile1"
+               rm -f "$tempfile2"
        exit 1
        fi
 }