mirror of
https://github.com/tuna/tunasync-scripts.git
synced 2025-04-20 04:12:42 +00:00
Remove possible race condition; Uniq before compare.
This commit is contained in:
parent
93692652dd
commit
2747dc1080
16
hackage.sh
16
hackage.sh
@ -5,7 +5,7 @@ set -o pipefail
|
|||||||
|
|
||||||
function remove_broken() {
|
function remove_broken() {
|
||||||
interval=$1
|
interval=$1
|
||||||
interval_file="/tmp/hackage_lastcheck"
|
interval_file="${TUNASYNC_WORKING_DIR}/.tunasync_hackage_lastcheck"
|
||||||
now=`date +%s`
|
now=`date +%s`
|
||||||
|
|
||||||
if [[ -f ${interval_file} ]]; then
|
if [[ -f ${interval_file} ]]; then
|
||||||
@ -32,9 +32,9 @@ function must_download() {
|
|||||||
src=$1
|
src=$1
|
||||||
dst=$2
|
dst=$2
|
||||||
while true; do
|
while true; do
|
||||||
echo "downloading: $name"
|
echo "downloading: $dst"
|
||||||
wget "$src" -O "$dst" &>/dev/null
|
wget "$src" -O "$dst" &>/dev/null
|
||||||
tar -tzf package/$name >/dev/null || rm package/$name && break
|
tar -tzf "$dst" >/dev/null || rm "$dst" && break
|
||||||
done
|
done
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -55,10 +55,10 @@ function hackage_mirror() {
|
|||||||
local tmp
|
local tmp
|
||||||
tmp=(package/*)
|
tmp=(package/*)
|
||||||
tmp=(${tmp[@]#package/})
|
tmp=(${tmp[@]#package/})
|
||||||
printf '%s\n' "${tmp[@]%.tar.gz}" > "${local_pklist}"
|
printf '%s\n' "${tmp[@]%.tar.gz}" | sort | uniq > "${local_pklist}"
|
||||||
|
|
||||||
echo "building remote package list"
|
echo "building remote package list"
|
||||||
tar -ztf index.tar.gz | (cut -d/ -f 1,2 2>/dev/null) | sed 's|/|-|' > $remote_pklist
|
tar -ztf index.tar.gz | (cut -d/ -f 1,2 2>/dev/null) | sed 's|/|-|' | sort | uniq > "${remote_pklist}"
|
||||||
|
|
||||||
echo "building download list"
|
echo "building download list"
|
||||||
# substract local list from remote list
|
# substract local list from remote list
|
||||||
@ -78,17 +78,17 @@ function hackage_mirror() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
name="$pk.tar.gz"
|
name="$pk.tar.gz"
|
||||||
if [ ! -a package/$name ]; then
|
if [ ! -e package/$name ]; then
|
||||||
must_download "${base_url}/package/$pk/$name" "package/$name" &
|
must_download "${base_url}/package/$pk/$name" "package/$name" &
|
||||||
else
|
else
|
||||||
echo "skip existed: $name"
|
echo "skip existed: $name"
|
||||||
fi
|
fi
|
||||||
done < <(comm <(sort $remote_pklist) <(sort $local_pklist) -23)
|
done < <(comm "${remote_pklist}" "${local_pklist}" -23)
|
||||||
|
|
||||||
wait
|
wait
|
||||||
|
|
||||||
# delete redundanty files
|
# delete redundanty files
|
||||||
comm <(sort $remote_pklist) <(sort $local_pklist) -13 | while read pk; do
|
comm "$remote_pklist" "$local_pklist" -13 | while read pk; do
|
||||||
if [[ $pk == "preferred-versions" ]]; then
|
if [[ $pk == "preferred-versions" ]]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user