From c25107eff3e8f1ed702e09e2c8e6d4fce5d99db1 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sun, 1 Mar 2015 10:34:32 +0100 Subject: [PATCH] Handle weird Lstat() returns for disappeared items (ref #1373) --- internal/model/model.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/model/model.go b/internal/model/model.go index 4605f9c3..83f289f0 100644 --- a/internal/model/model.go +++ b/internal/model/model.go @@ -1242,8 +1242,16 @@ func (m *Model) ScanFolderSub(folder, sub string) error { "size": f.Size(), }) batch = append(batch, nf) - } else if _, err := os.Lstat(filepath.Join(folderCfg.Path, f.Name)); err != nil && os.IsNotExist(err) { - // File has been deleted + } else if _, err := os.Lstat(filepath.Join(folderCfg.Path, f.Name)); err != nil { + // File has been deleted. + + // We don't specifically verify that the error is + // os.IsNotExist because there is a corner case when a + // directory is suddenly transformed into a file. When that + // happens, files that were in the directory (that is now a + // file) are deleted but will return a confusing error ("not a + // directory") when we try to Lstat() them. + nf := protocol.FileInfo{ Name: f.Name, Flags: f.Flags | protocol.FlagDeleted,