dot

packages and services management
Log | Files | Refs | README

commit 9d77f83506aa41223d6c2ce1de643a9ebc252b66
parent 6ae84eff9cbc487b586e2368cb5876f59327dd23
Author: josuah <mail@josuah.net>
Date:   Sat, 31 Dec 2016 02:51:26 +0100

idiot proof: read only .version/{rev,obj}

Diffstat:
M.local/bin/version | 30+++++++++++++-----------------
1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/.local/bin/version b/.local/bin/version @@ -2,7 +2,7 @@ # Simple version control system to store large datasets using hashs # dependencies: -# mkdir find sort xargs md5sum rm test mv comm sed printf tac +# mkdir find sort xargs md5sum rm test mv chmod comm sed printf tac NL=' @@ -20,7 +20,7 @@ opt() usage() { - opt "$1" i 'i[nit]' 'new "./.version/" directory in working directory' + opt "$1" i 'i[nit]' 'new .version directory in working directory' opt "$1" n 'n[ew]' 'new version entry saving all tree content' opt "$1" l 'l[ist] [REV]' 'display full history of revisions or REV' opt "$1" d 'd[diff] [OLD NEW]' 'diff revisions OLD and NEW (or latests)' @@ -64,25 +64,24 @@ new() find . -type f $(exclude .git .version) -print0 | sort -z | xargs -0 md5sum > .version/tmp - hash="$(md5sum .version/tmp)" || die 'could not generate md5sum' + hash="$(md5sum .version/tmp)" || die 'could not generate hash' hash="${hash%% *}" - if - [ -f .version/history ] && - [ "$hash" = "$(sed '$qd' .version/history)" ] - then - rm .version/tmp - die 'already at latest version' - fi + mv -f .version/tmp ".version/rev/$hash" + + [ -f .version/history ] && + [ "$hash" = "$(sed '$qd' .version/history)" ] && + die 'already at latest version' printf '%s\n' "$hash" >> .version/history - mv .version/tmp ".version/rev/$hash" - printf 'saving content in ./.version/obj/\n' + printf 'saving content in .version/obj\n' while read -r hash path do [ ! -f ".version/obj/$hash" ] && cp -f "$path" ".version/obj/$hash" done < ".version/rev/$hash" + + chmod -w .version/obj/* .version/rev/* } @@ -94,8 +93,8 @@ import() find "$1/.version/obj" -type f | while IFS='' read -r path do [ -f "${path#$1/}" ] || cp "$path" "${path#$1/}" done + chmod -w "$1/.version/obj/"* "$1/.version/obj/"* - # find latest common revision for revision in $(tac "$1/.version/history") do common="$(grep "$revision" "$2/.version/history")" && break done @@ -131,14 +130,11 @@ makediff() sort -o .version/tmp2 ".version/rev/$2" { - # -: not present in the next revision comm -32 .version/tmp1 .version/tmp2 | sed 's/^/- /' - - # +: not present in the previous revision comm -31 .version/tmp1 .version/tmp2 | sed 's/^/+ /' } | sort -t "$NL" -k 1.$((32 + 6)) - rm -f .version/tmp[12] + rm -f .version/tmp1 .version/tmp2 }