Skip to content

Commit b9326ba

Browse files
committed
fix tracking of removed files/dirs
1 parent 9cd60dc commit b9326ba

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

index.go

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"os"
77
"path/filepath"
8-
"reflect"
98
"slices"
109
)
1110

@@ -69,10 +68,6 @@ func (i *Index) getIndexFilepath() string {
6968
return filepath.Join(i.path, i.context.IndexFilename)
7069
}
7170

72-
func (i *Index) setMod(value bool) {
73-
i.modified = value
74-
}
75-
7671
func (i *Index) logFilePanic(name string, message string) {
7772
i.context.log(STATUS_PANIC, filepath.Join(i.path, name)+": "+message)
7873
}
@@ -137,14 +132,14 @@ func (i *Index) checkFix(forceUpdateDmg bool) {
137132
for name, b := range i.new {
138133
if a, ok := i.cur[name]; !ok {
139134
i.logFile(STATUS_NEW, name)
140-
i.setMod(true)
135+
i.modified = true
141136
} else {
142137
amod := int64(a.ModTime)
143138
bmod := int64(b.ModTime)
144139
if a.Hash != nil && b.Hash != nil && *a.Hash == *b.Hash {
145140
i.logFile(STATUS_OK, name)
146141
if amod != bmod {
147-
i.setMod(true)
142+
i.modified = true
148143
}
149144
continue
150145
}
@@ -155,37 +150,45 @@ func (i *Index) checkFix(forceUpdateDmg bool) {
155150
// keep DMG entry
156151
i.new[name] = a
157152
} else {
158-
i.setMod(true)
153+
i.modified = true
159154
}
160155
} else if amod < bmod {
161156
i.logFile(STATUS_UPDATE, name)
162-
i.setMod(true)
157+
i.modified = true
163158
} else if amod > bmod {
164159
i.logFile(STATUS_UP_WARN_OLD, name)
165-
i.setMod(true)
160+
i.modified = true
166161
}
167162
}
168163
}
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 {
172169
i.logFile(STATUS_MISSING, name)
173-
i.setMod(true)
174170
}
175171
}
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 {
183183
i.logDir(STATUS_MISSING, name+"/")
184-
i.setMod(true)
185184
}
186185
}
187-
188186
}
187+
if len(i.newDirList) != len(i.curDirList) {
188+
// added
189+
i.modified = true
190+
}
191+
189192
}
190193

191194
func (i *Index) calcFile(name string, a string) (*idxInfo, error) {
@@ -231,7 +234,7 @@ func (i *Index) save() (bool, error) {
231234
if err != nil {
232235
return false, err
233236
}
234-
i.setMod(false)
237+
i.modified = false
235238
return true, nil
236239
} else {
237240
return false, nil
@@ -241,13 +244,11 @@ func (i *Index) save() (bool, error) {
241244
func (i *Index) load() error {
242245
if _, err := os.Stat(i.getIndexFilepath()); err != nil {
243246
if os.IsNotExist(err) {
244-
// todo
245-
i.setMod(true)
246247
return nil
247248
}
248249
return err
249250
}
250-
i.setMod(false)
251+
i.modified = false
251252
file, err := os.ReadFile(i.getIndexFilepath())
252253
if err != nil {
253254
return err
@@ -269,7 +270,7 @@ func (i *Index) load() error {
269270
} else {
270271
}
271272
if data.IdxHash != hashMd5(text) {
272-
i.setMod(true)
273+
i.modified = true
273274
i.logFile(STATUS_ERR_IDX, i.getIndexFilepath())
274275
}
275276
} else {
@@ -286,12 +287,12 @@ func (i *Index) load() error {
286287
}
287288
}
288289
}
290+
291+
// dirs
289292
if data.Dir != nil {
290293
slices.Sort(data.Dir)
291294
i.curDirList = data.Dir
292-
if i.context.TrackDirectories && !reflect.DeepEqual(i.curDirList, i.newDirList) {
293-
i.setMod(true)
294-
}
295295
}
296+
296297
return nil
297298
}

scripts/run_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ func setupMiscFiles() {
115115

116116
genDir(root)
117117

118+
os.MkdirAll(filepath.Join(root, "day/car/empty"), 0755)
119+
118120
rootPeople := filepath.Join(root, "people")
119121
testPeople := filepath.Join(testDir, "people")
120122

0 commit comments

Comments
 (0)