-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapply.sh
More file actions
executable file
·82 lines (72 loc) · 1.5 KB
/
apply.sh
File metadata and controls
executable file
·82 lines (72 loc) · 1.5 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
#!/bin/sh
# Watch ./apply_test.sh
usage(){
echo >&2 'apply.sh old new [timefile] <log'
echo >&2 'see also replica/applylog in https://9p.io/magic/man2html/8/replica'
exit 64
}
case $# in
[23]) old=${1?} new=${2?} timefile=$3;;
*) usage
esac
exec awk -v 'old='"$old" -v 'new='"$new" -v 'timefile='"$timefile" '
BEGIN {
Time=1; Gen=2; Verb=3; Path=4; Spath=5; Mode=6; Uid=7; Gid=8; Mtime=9; Len=10
loadtime()
} $Time < time {
next
} $Time == time && $Gen <= gen {
next
} $Verb~/[acdm]/ {
print $Verb, $Path, $Spath, $Mode, $Uid, $Gid, $Mtime, $Len
} $Spath == "-" {
$Spath = $Path
} $Verb~/a/ && $Mode~/d/ {
mkdir(new "/" $Path)
} $Verb~/[ac]/ && $Mode!~/d/ {
cp(old "/" $Spath, new "/" $Path)
} $Verb~/[acm]/ {
chmod(new "/" $Path, $Mode)
} $Verb~/d/ && $Mode~/d/ {
rmdir(new "/" $Path)
} $Verb~/d/ && $Mode!~/d/ {
rm(new "/" $Path)
} !errors {
time = $Time; gen = $Gen
} END {
savetime()
}
function mkdir(path) {
x("mkdir -p " path)
}
function rm(path) {
x("rm -f " path)
}
function rmdir(path) {
x("rmdir " path)
}
function cp(old, new) {
x("test ! -e " old " || cp " old " " new " || test ! -e " old)
}
function chmod(path, mode) {
sub("d", "", mode)
x("test ! -e " path " || chmod " mode " " path)
}
function loadtime() {
if(timefile != "" && getline <timefile > 0){
time = int($1)
gen = int($2)
}
}
function savetime() {
if(timefile != "")
x("echo " time " " gen " >" timefile)
}
function x(s) {
# DBG: system("echo + \"" s "\" >&2")
if(system(s) != 0) {
errors++
exit(1)
}
}
' # <log