feat(remote): add file cache for remote
This commit is contained in:
parent
dbe55ab7c0
commit
1eb7a078aa
3 changed files with 24 additions and 0 deletions
|
|
@ -1,6 +1,10 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
## Cache functions
|
## Cache functions
|
||||||
|
get_filecache() {
|
||||||
|
echo "$cachepath/$(filehash).tar.gpg"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
clear_cache() {
|
clear_cache() {
|
||||||
rm "$cachepath"/*
|
rm "$cachepath"/*
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,9 @@ ZPASS_UNK_OP_CALL=${ZPASS_UNK_OP_CALL-copy}
|
||||||
ZPASS_RAND_LEN=${ZPASS_RAND_LEN-20}
|
ZPASS_RAND_LEN=${ZPASS_RAND_LEN-20}
|
||||||
ZPASS_RAND_SET=${ZPASS_RAND_SET-'a-zA-Z0-9\!-.'}
|
ZPASS_RAND_SET=${ZPASS_RAND_SET-'a-zA-Z0-9\!-.'}
|
||||||
|
|
||||||
|
RES_OPTIONS=${RES_OPTIONS-'retrans:1 retry:1 timeout:1 attempts:1'}
|
||||||
|
export RES_OPTIONS
|
||||||
|
|
||||||
# datapath resolution
|
# datapath resolution
|
||||||
# remove tildes
|
# remove tildes
|
||||||
datapath="${datapath#\~/}"
|
datapath="${datapath#\~/}"
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,11 @@ upload() {
|
||||||
put "$2" "$3"
|
put "$2" "$3"
|
||||||
EOF
|
EOF
|
||||||
esac
|
esac
|
||||||
|
[ $? -eq 0 ] || {
|
||||||
|
echo "ERROR: failed to upload" >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
cp "$2" "$(get_filecache)"
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1 = protocol, $2 = remote file , $3 = local file
|
# $1 = protocol, $2 = remote file , $3 = local file
|
||||||
|
|
@ -50,6 +55,18 @@ get "$2" "$3"
|
||||||
EOF
|
EOF
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
if [ $? -eq 0 ] ; then
|
||||||
|
# could download no problem
|
||||||
|
cached_file=$(get_filecache)
|
||||||
|
# copy only if different
|
||||||
|
diff "$3" "$cached_file" >/dev/null 2>&1 || cp "$3" "$cached_file"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
# could not download: try cache
|
||||||
|
[ -f "$3" ] || return $?
|
||||||
|
echo "WARN: failed to download archive, using cache" >&2
|
||||||
|
cp "$(get_filecache)" "$3"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1 = protocol
|
# $1 = protocol
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue