5
5
"errors"
6
6
"os"
7
7
"path/filepath"
8
- "reflect"
9
8
"slices"
10
9
)
11
10
@@ -69,10 +68,6 @@ func (i *Index) getIndexFilepath() string {
69
68
return filepath .Join (i .path , i .context .IndexFilename )
70
69
}
71
70
72
- func (i * Index ) setMod (value bool ) {
73
- i .modified = value
74
- }
75
-
76
71
func (i * Index ) logFilePanic (name string , message string ) {
77
72
i .context .log (STATUS_PANIC , filepath .Join (i .path , name )+ ": " + message )
78
73
}
@@ -137,14 +132,14 @@ func (i *Index) checkFix(forceUpdateDmg bool) {
137
132
for name , b := range i .new {
138
133
if a , ok := i .cur [name ]; ! ok {
139
134
i .logFile (STATUS_NEW , name )
140
- i .setMod ( true )
135
+ i .modified = true
141
136
} else {
142
137
amod := int64 (a .ModTime )
143
138
bmod := int64 (b .ModTime )
144
139
if a .Hash != nil && b .Hash != nil && * a .Hash == * b .Hash {
145
140
i .logFile (STATUS_OK , name )
146
141
if amod != bmod {
147
- i .setMod ( true )
142
+ i .modified = true
148
143
}
149
144
continue
150
145
}
@@ -155,37 +150,45 @@ func (i *Index) checkFix(forceUpdateDmg bool) {
155
150
// keep DMG entry
156
151
i .new [name ] = a
157
152
} else {
158
- i .setMod ( true )
153
+ i .modified = true
159
154
}
160
155
} else if amod < bmod {
161
156
i .logFile (STATUS_UPDATE , name )
162
- i .setMod ( true )
157
+ i .modified = true
163
158
} else if amod > bmod {
164
159
i .logFile (STATUS_UP_WARN_OLD , name )
165
- i .setMod ( true )
160
+ i .modified = true
166
161
}
167
162
}
168
163
}
169
- if i .context .ShowMissing {
170
- for name := range i .cur {
171
- if _ , ok := i .new [name ]; ! ok {
164
+ // track missing
165
+ for name := range i .cur {
166
+ if _ , ok := i .new [name ]; ! ok {
167
+ i .modified = true
168
+ if i .context .ShowMissing {
172
169
i .logFile (STATUS_MISSING , name )
173
- i .setMod (true )
174
170
}
175
171
}
176
- // dirs
177
- m := make (map [string ]bool )
178
- for _ , n := range i .newDirList {
179
- m [n ] = true
180
- }
181
- for _ , name := range i .curDirList {
182
- if ! m [name ] {
172
+ }
173
+
174
+ // dirs
175
+ m := make (map [string ]bool )
176
+ for _ , n := range i .newDirList {
177
+ m [n ] = true
178
+ }
179
+ for _ , name := range i .curDirList {
180
+ if ! m [name ] {
181
+ i .modified = true
182
+ if i .context .ShowMissing {
183
183
i .logDir (STATUS_MISSING , name + "/" )
184
- i .setMod (true )
185
184
}
186
185
}
187
-
188
186
}
187
+ if len (i .newDirList ) != len (i .curDirList ) {
188
+ // added
189
+ i .modified = true
190
+ }
191
+
189
192
}
190
193
191
194
func (i * Index ) calcFile (name string , a string ) (* idxInfo , error ) {
@@ -231,7 +234,7 @@ func (i *Index) save() (bool, error) {
231
234
if err != nil {
232
235
return false , err
233
236
}
234
- i .setMod ( false )
237
+ i .modified = false
235
238
return true , nil
236
239
} else {
237
240
return false , nil
@@ -241,13 +244,11 @@ func (i *Index) save() (bool, error) {
241
244
func (i * Index ) load () error {
242
245
if _ , err := os .Stat (i .getIndexFilepath ()); err != nil {
243
246
if os .IsNotExist (err ) {
244
- // todo
245
- i .setMod (true )
246
247
return nil
247
248
}
248
249
return err
249
250
}
250
- i .setMod ( false )
251
+ i .modified = false
251
252
file , err := os .ReadFile (i .getIndexFilepath ())
252
253
if err != nil {
253
254
return err
@@ -269,7 +270,7 @@ func (i *Index) load() error {
269
270
} else {
270
271
}
271
272
if data .IdxHash != hashMd5 (text ) {
272
- i .setMod ( true )
273
+ i .modified = true
273
274
i .logFile (STATUS_ERR_IDX , i .getIndexFilepath ())
274
275
}
275
276
} else {
@@ -286,12 +287,12 @@ func (i *Index) load() error {
286
287
}
287
288
}
288
289
}
290
+
291
+ // dirs
289
292
if data .Dir != nil {
290
293
slices .Sort (data .Dir )
291
294
i .curDirList = data .Dir
292
- if i .context .TrackDirectories && ! reflect .DeepEqual (i .curDirList , i .newDirList ) {
293
- i .setMod (true )
294
- }
295
295
}
296
+
296
297
return nil
297
298
}
0 commit comments