author | Tero Marttila <terom@paivola.fi> |
Mon, 09 Mar 2015 21:17:06 +0200 | |
changeset 736 | 75938aa0390b |
parent 718 | f1c352644c2a |
permissions | -rw-r--r-- |
627 | 1 |
# Idempotent refreshable operations |
2 |
||
3 |
apply_GETOPTS='pFn' |
|
4 |
||
5 |
APPLY= |
|
674
a5b712cd0273
lib/pvl: fix -nF to skip apply_check's but still not actually apply_cmd
Tero Marttila <terom@paivola.fi>
parents:
629
diff
changeset
|
6 |
APPLY_FORCE= |
627 | 7 |
APPLY_DIFF= |
8 |
||
9 |
function apply_help { |
|
10 |
cat <<END |
|
11 |
Apply: |
|
12 |
-p show changes |
|
13 |
-F force-updates without checking src mtime |
|
14 |
-n no-op/mock-update; don't actually change/deploy anything; implies -SpC |
|
15 |
END |
|
16 |
} |
|
17 |
||
18 |
function apply_opt { |
|
19 |
local opt=$1 |
|
20 |
local optarg="$2" |
|
21 |
||
22 |
case $opt in |
|
23 |
p) APPLY_DIFF=1 ;; |
|
674
a5b712cd0273
lib/pvl: fix -nF to skip apply_check's but still not actually apply_cmd
Tero Marttila <terom@paivola.fi>
parents:
629
diff
changeset
|
24 |
F) APPLY_FORCE=1 ;; |
627 | 25 |
|
26 |
n) |
|
27 |
APPLY=0 |
|
28 |
APPLY_DIFF=1 |
|
29 |
;; |
|
30 |
*) return 1 |
|
31 |
esac |
|
32 |
} |
|
33 |
||
34 |
. $LIB/pvl/apply/dir.sh |
|
35 |
. $LIB/pvl/apply/link.sh |
|
36 |
. $LIB/pvl/apply/cmd.sh |
|
37 |
. $LIB/pvl/apply/cat.sh |
|
38 |
||
39 |
## Compare the given output file with all given source files: |
|
40 |
# |
|
41 |
# check_update $out ${deps[@]} && do_update $out ... || ... |
|
42 |
# |
|
43 |
# Returns true if the output file needs to be updated. |
|
44 |
function apply_check { |
|
45 |
local update= |
|
46 |
local out="$1" |
|
47 |
||
718
f1c352644c2a
lib/pvl/apply: log_changed in apply_check
Tero Marttila <tero.marttila@aalto.fi>
parents:
714
diff
changeset
|
48 |
log_debug "$out" |
627 | 49 |
|
50 |
if [ ${#@} -eq 1 ]; then |
|
718
f1c352644c2a
lib/pvl/apply: log_changed in apply_check
Tero Marttila <tero.marttila@aalto.fi>
parents:
714
diff
changeset
|
51 |
log_changed " update: empty deps" |
714
e0a651547bd2
lib/pvl/apply: empty deps -> always update
Tero Marttila <tero.marttila@aalto.fi>
parents:
674
diff
changeset
|
52 |
return 2 |
627 | 53 |
|
54 |
elif [ ! -e "$out" ]; then |
|
718
f1c352644c2a
lib/pvl/apply: log_changed in apply_check
Tero Marttila <tero.marttila@aalto.fi>
parents:
714
diff
changeset
|
55 |
log_changed " update: dest missing" |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
56 |
return 2 |
627 | 57 |
|
674
a5b712cd0273
lib/pvl: fix -nF to skip apply_check's but still not actually apply_cmd
Tero Marttila <terom@paivola.fi>
parents:
629
diff
changeset
|
58 |
elif [ "$APPLY_FORCE" = 1 ]; then |
718
f1c352644c2a
lib/pvl/apply: log_changed in apply_check
Tero Marttila <tero.marttila@aalto.fi>
parents:
714
diff
changeset
|
59 |
log_changed " update: forced" |
627 | 60 |
return 2 |
61 |
fi |
|
62 |
||
63 |
# check deps |
|
64 |
for dep in "${@:2}"; do |
|
65 |
# check |
|
66 |
if [ ! -e "$dep" ]; then |
|
718
f1c352644c2a
lib/pvl/apply: log_changed in apply_check
Tero Marttila <tero.marttila@aalto.fi>
parents:
714
diff
changeset
|
67 |
warn "$out: Missing source: $dep" |
627 | 68 |
|
69 |
elif [ "$out" -ot "$dep" ]; then |
|
718
f1c352644c2a
lib/pvl/apply: log_changed in apply_check
Tero Marttila <tero.marttila@aalto.fi>
parents:
714
diff
changeset
|
70 |
log_changed " changed: $dep" |
627 | 71 |
return 1 |
72 |
else |
|
718
f1c352644c2a
lib/pvl/apply: log_changed in apply_check
Tero Marttila <tero.marttila@aalto.fi>
parents:
714
diff
changeset
|
73 |
log_debug " check: $dep" |
627 | 74 |
fi |
75 |
done |
|
76 |
||
718
f1c352644c2a
lib/pvl/apply: log_changed in apply_check
Tero Marttila <tero.marttila@aalto.fi>
parents:
714
diff
changeset
|
77 |
log_debug " up-to-date" |
627 | 78 |
return 0 |
79 |
} |