Skip to content

Commit 2e3f26f

Browse files
committed
Revert "Emit unmodified change events for directories"
This reverts commit ba10e49. Signed-off-by: Derek McGowan <[email protected]>
1 parent 0f1f8f6 commit 2e3f26f

2 files changed

Lines changed: 7 additions & 140 deletions

File tree

fs/diff.go

Lines changed: 6 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,8 @@ func doubleWalkDiff(ctx context.Context, changeFn ChangeFunc, a, b string) (err
222222
c1 = make(chan *currentPath)
223223
c2 = make(chan *currentPath)
224224

225-
f1, f2 *currentPath
226-
rmdir string
227-
lastEmittedDir = string(filepath.Separator)
228-
parents []os.FileInfo
225+
f1, f2 *currentPath
226+
rmdir string
229227
)
230228
g.Go(func() error {
231229
defer close(c1)
@@ -260,10 +258,7 @@ func doubleWalkDiff(ctx context.Context, changeFn ChangeFunc, a, b string) (err
260258
continue
261259
}
262260

263-
var (
264-
f os.FileInfo
265-
emit = true
266-
)
261+
var f os.FileInfo
267262
k, p := pathChange(f1, f2)
268263
switch k {
269264
case ChangeKindAdd:
@@ -299,83 +294,17 @@ func doubleWalkDiff(ctx context.Context, changeFn ChangeFunc, a, b string) (err
299294
f2 = nil
300295
if same {
301296
if !isLinked(f) {
302-
emit = false
297+
continue
303298
}
304299
k = ChangeKindUnmodified
305300
}
306301
}
307-
if emit {
308-
emittedDir, emitParents := commonParents(lastEmittedDir, p, parents)
309-
for _, pf := range emitParents {
310-
p := filepath.Join(emittedDir, pf.Name())
311-
if err := changeFn(ChangeKindUnmodified, p, pf, nil); err != nil {
312-
return err
313-
}
314-
emittedDir = p
315-
}
316-
317-
if err := changeFn(k, p, f, nil); err != nil {
318-
return err
319-
}
320-
321-
if f != nil && f.IsDir() {
322-
lastEmittedDir = p
323-
} else {
324-
lastEmittedDir = emittedDir
325-
}
326-
327-
parents = parents[:0]
328-
} else if f.IsDir() {
329-
lastEmittedDir, parents = commonParents(lastEmittedDir, p, parents)
330-
parents = append(parents, f)
302+
if err := changeFn(k, p, f, nil); err != nil {
303+
return err
331304
}
332305
}
333306
return nil
334307
})
335308

336309
return g.Wait()
337310
}
338-
339-
func commonParents(base, updated string, dirs []os.FileInfo) (string, []os.FileInfo) {
340-
if basePrefix := makePrefix(base); strings.HasPrefix(updated, basePrefix) {
341-
var (
342-
parents []os.FileInfo
343-
last = base
344-
)
345-
for _, d := range dirs {
346-
next := filepath.Join(last, d.Name())
347-
if strings.HasPrefix(updated, makePrefix(last)) {
348-
parents = append(parents, d)
349-
last = next
350-
} else {
351-
break
352-
}
353-
}
354-
return base, parents
355-
}
356-
357-
baseS := strings.Split(base, string(filepath.Separator))
358-
updatedS := strings.Split(updated, string(filepath.Separator))
359-
commonS := []string{string(filepath.Separator)}
360-
361-
min := len(baseS)
362-
if len(updatedS) < min {
363-
min = len(updatedS)
364-
}
365-
for i := 0; i < min; i++ {
366-
if baseS[i] == updatedS[i] {
367-
commonS = append(commonS, baseS[i])
368-
} else {
369-
break
370-
}
371-
}
372-
373-
return filepath.Join(commonS...), []os.FileInfo{}
374-
}
375-
376-
func makePrefix(d string) string {
377-
if d == "" || d[len(d)-1] != filepath.Separator {
378-
return d + string(filepath.Separator)
379-
}
380-
return d
381-
}

fs/diff_test.go

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ func TestSimpleDiff(t *testing.T) {
4444
fstest.Remove("/etc/unexpected"),
4545
)
4646
diff := []TestChange{
47-
Unchanged("/etc"),
4847
Modify("/etc/hosts"),
4948
Modify("/etc/profile"),
5049
Delete("/etc/unexpected"),
@@ -71,7 +70,6 @@ func TestDirectoryReplace(t *testing.T) {
7170
fstest.CreateFile("/dir1/f2", []byte("Now file"), 0666),
7271
)
7372
diff := []TestChange{
74-
Unchanged("/dir1"),
7573
Add("/dir1/f11"),
7674
Modify("/dir1/f2"),
7775
}
@@ -134,13 +132,10 @@ func TestParentDirectoryPermission(t *testing.T) {
134132
fstest.CreateFile("/dir3/f", []byte("irrelevant"), 0644),
135133
)
136134
diff := []TestChange{
137-
Unchanged("/dir1"),
138135
Add("/dir1/d"),
139136
Add("/dir1/d/f"),
140137
Add("/dir1/f"),
141-
Unchanged("/dir2"),
142138
Add("/dir2/f"),
143-
Unchanged("/dir3"),
144139
Add("/dir3/f"),
145140
}
146141

@@ -189,56 +184,6 @@ func TestUpdateWithSameTime(t *testing.T) {
189184
}
190185
}
191186

192-
func TestUnchangedParent(t *testing.T) {
193-
skipDiffTestOnWindows(t)
194-
l1 := fstest.Apply(
195-
fstest.CreateDir("/dir1", 0755),
196-
fstest.CreateDir("/dir3", 0755),
197-
fstest.CreateDir("/dir3/a", 0755),
198-
fstest.CreateDir("/dir3/a/e", 0755),
199-
fstest.CreateDir("/dir3/z", 0755),
200-
)
201-
l2 := fstest.Apply(
202-
fstest.CreateDir("/dir1/a", 0755),
203-
fstest.CreateFile("/dir1/a/b", []byte("irrelevant"), 0644),
204-
fstest.CreateDir("/dir1/a/e", 0755),
205-
fstest.CreateFile("/dir1/a/e/f", []byte("irrelevant"), 0644),
206-
fstest.CreateFile("/dir1/f", []byte("irrelevant"), 0644),
207-
fstest.CreateDir("/dir2", 0755),
208-
fstest.CreateFile("/dir2/f", []byte("irrelevant"), 0644),
209-
fstest.CreateFile("/dir3/a/b", []byte("irrelevant"), 0644),
210-
fstest.CreateDir("/dir3/a/c", 0755),
211-
fstest.CreateDir("/dir3/a/e/i", 0755),
212-
fstest.CreateFile("/dir3/a/e/i/f", []byte("irrelevant"), 0644),
213-
fstest.CreateFile("/dir3/f", []byte("irrelevant"), 0644),
214-
fstest.CreateFile("/dir3/z/f", []byte("irrelevant"), 0644),
215-
)
216-
diff := []TestChange{
217-
Unchanged("/dir1"),
218-
Add("/dir1/a"),
219-
Add("/dir1/a/b"),
220-
Add("/dir1/a/e"),
221-
Add("/dir1/a/e/f"),
222-
Add("/dir1/f"),
223-
Add("/dir2"),
224-
Add("/dir2/f"),
225-
Unchanged("/dir3"),
226-
Unchanged("/dir3/a"),
227-
Add("/dir3/a/b"),
228-
Add("/dir3/a/c"),
229-
Unchanged("/dir3/a/e"),
230-
Add("/dir3/a/e/i"),
231-
Add("/dir3/a/e/i/f"),
232-
Add("/dir3/f"),
233-
Unchanged("/dir3/z"),
234-
Add("/dir3/z/f"),
235-
}
236-
237-
if err := testDiffWithBase(l1, l2, diff); err != nil {
238-
t.Fatalf("Failed diff with base: %+v", err)
239-
}
240-
}
241-
242187
// buildkit#172
243188
func TestLchtimes(t *testing.T) {
244189
skipDiffTestOnWindows(t)
@@ -402,7 +347,7 @@ func diffString(c1, c2 []TestChange) string {
402347
func changesString(c []TestChange) string {
403348
strs := make([]string, len(c))
404349
for i := range c {
405-
strs[i] = fmt.Sprintf("\t%-10s\t%s", c[i].Kind, c[i].Path)
350+
strs[i] = fmt.Sprintf("\t%s\t%s", c[i].Kind, c[i].Path)
406351
}
407352
return strings.Join(strs, "\n")
408353
}
@@ -427,10 +372,3 @@ func Modify(p string) TestChange {
427372
Path: filepath.FromSlash(p),
428373
}
429374
}
430-
431-
func Unchanged(p string) TestChange {
432-
return TestChange{
433-
Kind: ChangeKindUnmodified,
434-
Path: filepath.FromSlash(p),
435-
}
436-
}

0 commit comments

Comments
 (0)