diff options
author | Jakob Borg <jakob@nym.se> | 2014-04-01 23:18:32 +0200 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-04-02 11:57:18 +0200 |
commit | 15699a39cf8528b0ef3b970cb38adf64e99522d5 (patch) | |
tree | 0c1fda724337c632eeffbeb9bd0bf7c01324a72f /files | |
parent | a1f32095dfeea0188c4fb5d3708ca8b0097cdae7 (diff) |
Synchronize directory existence & metadata (fixes #11)
Diffstat (limited to 'files')
-rw-r--r-- | files/set.go | 10 | ||||
-rw-r--r-- | files/set_test.go | 5 |
2 files changed, 11 insertions, 4 deletions
diff --git a/files/set.go b/files/set.go index 7de636b4b7..f691f1f070 100644 --- a/files/set.go +++ b/files/set.go @@ -112,7 +112,7 @@ func (m *Set) ReplaceWithDelete(id uint, fs []scanner.File) { if _, ok := nf[ck.Name]; !ok { cf := m.files[ck].File if cf.Flags&protocol.FlagDeleted != protocol.FlagDeleted { - cf.Flags = protocol.FlagDeleted + cf.Flags |= protocol.FlagDeleted cf.Blocks = nil cf.Size = 0 cf.Version = lamport.Default.Tick(cf.Version) @@ -145,9 +145,13 @@ func (m *Set) Need(id uint) []scanner.File { } var fs []scanner.File m.Lock() + rkID := m.remoteKey[id] for name, gk := range m.globalKey { - if gk.newerThan(m.remoteKey[id][name]) { - fs = append(fs, m.files[gk].File) + if gk.newerThan(rkID[name]) { + if m.files[gk].File.Flags&protocol.FlagDirectory == 0 || // Regular file + m.files[gk].File.Flags&(protocol.FlagDirectory|protocol.FlagDeleted) == protocol.FlagDirectory { // Non-deleted directory + fs = append(fs, m.files[gk].File) + } } } m.Unlock() diff --git a/files/set_test.go b/files/set_test.go index 1731c2019c..d28baca8bf 100644 --- a/files/set_test.go +++ b/files/set_test.go @@ -77,6 +77,7 @@ func TestLocalDeleted(t *testing.T) { scanner.File{Name: "b", Version: 1000}, scanner.File{Name: "c", Version: 1000}, scanner.File{Name: "d", Version: 1000}, + scanner.File{Name: "z", Version: 1000, Flags: protocol.FlagDirectory}, } m.ReplaceWithDelete(cid.LocalID, local1) @@ -91,6 +92,7 @@ func TestLocalDeleted(t *testing.T) { scanner.File{Name: "b", Version: 1001, Flags: protocol.FlagDeleted}, local1[2], scanner.File{Name: "d", Version: 1002, Flags: protocol.FlagDeleted}, + scanner.File{Name: "z", Version: 1003, Flags: protocol.FlagDeleted | protocol.FlagDirectory}, } m.ReplaceWithDelete(cid.LocalID, local2) @@ -109,8 +111,9 @@ func TestLocalDeleted(t *testing.T) { expectedGlobal2 := []scanner.File{ local1[0], scanner.File{Name: "b", Version: 1001, Flags: protocol.FlagDeleted}, - scanner.File{Name: "c", Version: 1003, Flags: protocol.FlagDeleted}, + scanner.File{Name: "c", Version: 1004, Flags: protocol.FlagDeleted}, scanner.File{Name: "d", Version: 1002, Flags: protocol.FlagDeleted}, + scanner.File{Name: "z", Version: 1003, Flags: protocol.FlagDeleted | protocol.FlagDirectory}, } m.ReplaceWithDelete(cid.LocalID, local3) |