-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-annex-par2
More file actions
executable file
·95 lines (82 loc) · 2.33 KB
/
git-annex-par2
File metadata and controls
executable file
·95 lines (82 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# set -x
# For simplicity, avoiding parsing json for now, find seems adiquate
# TODO: Should probably move into .git/annex/par2 or something
GIT_DIR="$(git rev-parse --git-dir)"
ANNEX_DIR="$GIT_DIR/annex"
function par2_verify() {
git annex find --format='${hashdirmixed}${key}/${key} ${file}\n' --in=here "$@" | \
while read -r keypath file ; do
if [[ -f "$ANNEX_DIR/objects/$keypath.par2" ]]; then
par2verify -qq -- "$ANNEX_DIR/objects/$keypath.par2"
if [[ $? == 0 ]]; then
echo "$file OK"
else
echo "$file ERROR"
fi
fi
done
}
function par2_ls() {
git annex find --format='${hashdirmixed}${key}/${key} ${file}\n' --in=here "$@" | \
while read -r keypath file ; do
if [[ -f "$ANNEX_DIR/objects/$keypath.par2" ]]; then
echo "$file"
fi
done
}
function par2_drop() {
git annex find --format='${hashdirmixed}${key}\n' --in=here "$@" | \
while read -r keydir; do
if [[ -d "$ANNEX_DIR/objects/$keydir" ]]; then
chmod a+w "$ANNEX_DIR/objects/$keydir"
rm "$ANNEX_DIR/objects/$keydir/"*.par2
chmod a-w "$ANNEX_DIR/objects/$keydir"
fi
done
}
function par2_repair() {
git annex find --format='${hashdirmixed}${key}/${key} ${file}\n' --in=here "$@" | \
while read -r keypath file ; do
if [[ -f "$ANNEX_DIR/objects/$keypath.par2" ]]; then
chmod a+w "$(dirname "$ANNEX_DIR/objects/$keypath")"
par2repair -v -- "$ANNEX_DIR/objects/$keypath"
chmod a-w "$(dirname "$ANNEX_DIR/objects/$keypath")"
fi
done
}
function par2_create() {
# Probably want to have .git/annex/par2 instead...
# mkdir -p "$ANNEX_DIR/par2" || exit 1
git annex find --in=here "$@" | git annex lookupkey --batch | \
git annex examinekey --format='${hashdirmixed}${key}/${key}\n' --batch | \
while read -r keypath; do
if [[ ! -f "$ANNEX_DIR/objects/$keypath.par2" ]]; then
chmod a+w "$(dirname "$ANNEX_DIR/objects/$keypath")"
par2create -v -r5 -n1 "$ANNEX_DIR/objects/$keypath"
chmod a-w "$(dirname "$ANNEX_DIR/objects/$keypath")"
fi
done
}
function usage() {
echo "invalid options"
exit 1
}
if [[ $1 == "ls" ]]; then
shift
par2_ls "$@"
elif [[ $1 == "create" ]]; then
shift
par2_create "$@"
elif [[ $1 == "drop" ]]; then
shift
par2_drop "$@"
elif [[ $1 == "verify" ]]; then
shift
par2_verify "$@"
elif [[ $1 == "repair" ]]; then
shift
par2_repair "$@"
else
usage
fi