10
10
11
11
# Initialization
12
12
TOLERANCE=0.5
13
+ PRUNE_HISTORY_FILENAME=" .prune"
13
14
14
15
# prune usage
15
16
display_prune_usage () {
@@ -101,13 +102,11 @@ if [[ ! -f "$SOURCE" ]]; then
101
102
fi
102
103
103
104
# Execute prune command
104
- verbose " Launch prune in $SOURCE ."
105
-
106
- pruneCount=1
107
- similarCount=0
108
-
109
105
if [[ ! $COMMIT ]]; then
110
- verbose " Start to find similar images."
106
+ pruneCount=1
107
+ similarCount=0
108
+ verbose " Start to find similar images in $SOURCE ."
109
+
111
110
find " $SOURCE " -maxdepth $MAXDEPTH -type f -print0 | sort -z | while IFS= read -r -d ' ' f; do
112
111
if [[ -f $f ]]; then
113
112
debug " $f "
@@ -120,29 +119,36 @@ if [[ ! $COMMIT ]]; then
120
119
previousFilenameWithExt=$( basename " $previousImage " )
121
120
debug " $f "
122
121
difference=$( compare -quiet -metric NCC " $previousImage " " $f " null: 2>&1 )
122
+
123
123
re=" ^[0-9]\.{0,1}[0-9]*$"
124
124
if [[ $difference =~ $re ]]; then
125
125
debug " $difference >= $TOLERANCE "
126
126
isDifferent=$( echo " $difference >= $TOLERANCE " | bc -l)
127
+
127
128
if [[ $isDifferent == 1 ]]; then
128
129
verbose " '$previousImage ' seems similar to '$f ' ($difference )."
129
130
stillSimilar=1
130
- similarCount=$(( $similarCount + 1 ))
131
131
pruneDir=" $TARGET /$pruneCount "
132
132
debug " pruneDir = $pruneDir "
133
+
133
134
mkdir -p " $pruneDir "
134
- if [[ ! -f " $pruneDir /$previousFilenameWithExt " ]]; then
135
- ln -s " $previousImage " " $pruneDir /$previousFilenameWithExt " ;
135
+ if [[ ! -f " $pruneDir /$previousFilenameWithExt " ]]; then
136
+ if [[ $similarCount == 0 ]]; then
137
+ ln -s " $previousImage " " $pruneDir /$previousFilenameWithExt " ;
138
+ echo " $previousImage " >> " $pruneDir /$PRUNE_HISTORY_FILENAME "
139
+ fi
136
140
fi
137
141
ln -s " $f " " $pruneDir /$filenameWithExt "
138
- echo " $f " >> " $pruneDir /.prune"
142
+ echo " $f " >> " $pruneDir /$PRUNE_HISTORY_FILENAME "
143
+
144
+ similarCount=$(( $similarCount + 1 ))
139
145
verbose " Add image '$f ' to prune directory '$pruneDir '."
140
146
else
141
147
debug " '$previousImage ' seems different to '$f ' ($difference )."
142
148
143
149
if [[ $stillSimilar > 0 ]]; then
144
150
similarCount=$(( $similarCount + 1 ))
145
- mv " $pruneDir " " $pruneDir_ $similarCount "
151
+ mv " $pruneDir " " $pruneDir ( $similarCount ) "
146
152
pruneCount=$(( $pruneCount + 1 )) ;
147
153
fi
148
154
stillSimilar=0
@@ -160,4 +166,19 @@ if [[ ! $COMMIT ]]; then
160
166
else
161
167
verbose " Start to commit prune selections."
162
168
169
+ find " $SOURCE " -type f -print0 -name " $PRUNE_HISTORY_FILENAME " | sort -z | while IFS= read -r -d ' ' f; do
170
+ pruneDir=$( dirname " ${f} " )
171
+ debug " Reading prune file file '$f ' to find deleted files."
172
+ while read p; do
173
+ debug " p = $p "
174
+ filenameWithExt=$( basename " $p " )
175
+ linked=" $pruneDir /$filenameWithExt "
176
+ debug " Check if link '$linked ' still exists."
177
+ if [[ ! -f " $linked " ]]; then
178
+ debug " '$linked ' has been deleted, so delete the original file '$p '."
179
+ rm -f " $p "
180
+ verbose " '$p ' has been pruned (deleted)."
181
+ fi
182
+ done < " $f "
183
+ done
163
184
fi
0 commit comments