Skip to content

Commit 4e536b3

Browse files
committed
fix: add file to the temp list also on the first check
1 parent 39ad6d8 commit 4e536b3

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

dropbox.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ func (w *DropboxWatcher) sync(firstSync bool) {
142142

143143
fileList := make(map[string]*DropboxObject, 0)
144144
err := w.enumerateFiles(w.watchDir, func(obj *DropboxObject) bool {
145+
// Store the files to check the deleted one
146+
fileList[obj.Key] = obj
147+
145148
if !firstSync {
146-
// Store the files to check the deleted one
147-
fileList[obj.Key] = obj
148149
// Check if the object is cached by Key
149150
cached := w.getCachedObject(obj)
150151
// Object has been cached previously by Key

gdrive.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ func (w *GDriveWatcher) sync(firstSync bool) {
128128
fileList := make(map[string]*GDriveObject, 0)
129129

130130
err := w.enumerateFiles(w.watchDir, func(obj *GDriveObject) bool {
131+
// Store the files to check the deleted one
132+
fileList[obj.ID] = obj
131133
// With the first sync we need to cache all the files
132134
if !firstSync {
133-
// Store the files to check the deleted one
134-
fileList[obj.ID] = obj
135135
// Check if the object is cached by Key
136136
cached := w.getCachedObject(obj)
137137
// Object has been cached previously by Key

local.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ func (w *LocalWatcher) sync(firstSync bool) {
233233
FileMode: fi.Mode(),
234234
}
235235

236-
if !firstSync {
237-
fileList[walkPath] = obj
236+
fileList[walkPath] = obj
238237

238+
if !firstSync {
239239
// Check if the object is cached by Key
240240
cached := w.getCachedObject(obj)
241241
// Object has been cached previously by Key
@@ -276,18 +276,16 @@ func (w *LocalWatcher) sync(firstSync bool) {
276276
return
277277
}
278278

279-
if len(fileList) != 0 {
280-
for k, o := range w.cache {
281-
if _, found := fileList[k]; !found {
282-
// file not found in the list...deleting it
283-
delete(w.cache, k)
284-
event := Event{
285-
Key: o.Key,
286-
Type: FileDeleted,
287-
Object: o,
288-
}
289-
w.Events <- event
279+
for k, o := range w.cache {
280+
if _, found := fileList[k]; !found {
281+
// file not found in the list...deleting it
282+
delete(w.cache, k)
283+
event := Event{
284+
Key: o.Key,
285+
Type: FileDeleted,
286+
Object: o,
290287
}
288+
w.Events <- event
291289
}
292290
}
293291
}

s3.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ func (u *S3Watcher) sync(firstSync bool) {
168168
return true // continue
169169
}
170170

171-
if !firstSync {
172-
// Store the files to check the deleted one
173-
fileList[upd.Key] = upd
171+
// Store the files to check the deleted one
172+
fileList[upd.Key] = upd
174173

174+
if !firstSync {
175175
// Check if the object is cached by Key
176176
cached := u.getCachedObject(upd)
177177
// Object has been cached previously by Key
@@ -212,16 +212,18 @@ func (u *S3Watcher) sync(firstSync bool) {
212212
return
213213
}
214214

215-
for k, o := range u.cache {
216-
if _, found := fileList[k]; !found {
217-
// file not found in the list...deleting it
218-
delete(u.cache, k)
219-
event := Event{
220-
Key: o.Key,
221-
Type: FileDeleted,
222-
Object: o,
215+
if !firstSync {
216+
for k, o := range u.cache {
217+
if _, found := fileList[k]; !found {
218+
// file not found in the list...deleting it
219+
delete(u.cache, k)
220+
event := Event{
221+
Key: o.Key,
222+
Type: FileDeleted,
223+
Object: o,
224+
}
225+
u.Events <- event
223226
}
224-
u.Events <- event
225227
}
226228
}
227229
}

0 commit comments

Comments
 (0)