don't overwrite database unless it has grown
This commit is contained in:
parent
e56239957b
commit
0e52874c8b
7
meow.sh
7
meow.sh
|
@ -108,6 +108,7 @@ runsearch() { # [database]
|
||||||
local db="${1:-db.txt}"
|
local db="${1:-db.txt}"
|
||||||
local tmp=`mktemp`
|
local tmp=`mktemp`
|
||||||
touch "$db"
|
touch "$db"
|
||||||
|
|
||||||
for q in "${!searchquery[@]}"; do
|
for q in "${!searchquery[@]}"; do
|
||||||
search "${searchquery[$q]}" \
|
search "${searchquery[$q]}" \
|
||||||
| while IFS=$SEP read -r title torrent time; do
|
| while IFS=$SEP read -r title torrent time; do
|
||||||
|
@ -115,7 +116,9 @@ runsearch() { # [database]
|
||||||
echo -E "$time$SEP$tid$SEP$title"
|
echo -E "$time$SEP$tid$SEP$title"
|
||||||
done
|
done
|
||||||
done | sort -n -- "$db" - | uniq > $tmp
|
done | sort -n -- "$db" - | uniq > $tmp
|
||||||
# TODO: don't accidentally overwrite $db with something blank/incomplete
|
|
||||||
# maybe check if filesize has decreased and die if so
|
fs_old="$(du -b "$db" | cut -f1)"
|
||||||
|
fs_new="$(du -b $tmp | cut -f1)"
|
||||||
|
[ "$fs_new" -lt "$fs_old" ] || die "new database is smaller than current!"
|
||||||
mv $tmp "$db"
|
mv $tmp "$db"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user