Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 3a72228

Browse files
committed
Support file deletion again
1 parent a675d5e commit 3a72228

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

internal/sync/eventcache.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type timedEvent struct {
1414
}
1515

1616
type eventCache map[string]timedEvent
17-
17+
DirectoryEventDirectoryEventDirectoryEventsss
1818
func (cache eventCache) Add(ev timedEvent) {
1919
log := flog.New()
2020
log.Prefix = ev.Path() + ": "
@@ -35,34 +35,33 @@ func (cache eventCache) Add(ev timedEvent) {
3535
cache[ev.Path()] = ev
3636
}
3737

38-
// DirectoryEvents returns the list of events that pertain to directories.
39-
// The set of returns events is disjoint with FileEvents.
40-
func (cache eventCache) DirectoryEvents() []timedEvent {
38+
// SequentialEvents returns the list of events that pertain to directories.
39+
// The set of returned events is disjoint with ConcurrentEvents.
40+
func (cache eventCache) SequentialEvents() []timedEvent {
4141
var r []timedEvent
4242
for _, ev := range cache {
4343
info, err := os.Stat(ev.Path())
44-
if err != nil {
45-
continue
46-
}
47-
if !info.IsDir() {
44+
if err == nil && !info.IsDir() {
4845
continue
4946
}
47+
// Include files that have deleted here.
48+
// It's unclear whether they're files or folders.
5049
r = append(r, ev)
5150

5251
}
5352
return r
5453
}
5554

56-
// FileEvents returns the list of events that pertain to files.
57-
// The set of returns events is disjoint with DirectoryEvents.
58-
func (cache eventCache) FileEvents() []timedEvent {
55+
// ConcurrentEvents returns the list of events that are safe to process after SequentialEvents.
56+
// The set of returned events is disjoint with SequentialEvents.
57+
func (cache eventCache) ConcurrentEvents() []timedEvent {
5958
var r []timedEvent
6059
for _, ev := range cache {
6160
info, err := os.Stat(ev.Path())
6261
if err != nil {
6362
continue
6463
}
65-
if info.IsDir() {
64+
if info.IsDir() {
6665
continue
6766
}
6867
r = append(r, ev)

internal/sync/sync.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ func (s Sync) workEventGroup(evs []timedEvent) {
188188
// and then a file is moved to it. AFAIK this dependecy only exists with Directories.
189189
// So, we sequentially process the list of directory Renames and Creates, and then concurrently
190190
// perform all Writes.
191-
for _, ev := range cache.DirectoryEvents() {
191+
for _, ev := range cache.SequentialEvents() {
192192
s.work(ev)
193193
}
194194

195195
var wg sync.WaitGroup
196-
for _, ev := range cache.FileEvents() {
196+
for _, ev := range cache.ConcurrentEvents() {
197197
setConsoleTitle(fmtUpdateTitle(ev.Path()))
198198

199199
wg.Add(1)

0 commit comments

Comments
 (0)