lib/fs, lib/api, lib/model: Expose mtime remappings as part of /db/file (#7624)

* lib/fs, lib/api, lib/model: Expose mtime remappings as part of /db/file

* Fix wrong error returned by CLI

* Gofmt

* Better names

* Review comments

* Review comments
This commit is contained in:
Audrius Butkevicius
2021-05-03 11:28:25 +01:00
committed by GitHub
parent f09dcb98eb
commit 87a0eecc31
16 changed files with 305 additions and 111 deletions
+82
View File
@@ -8,6 +8,7 @@ import (
"time"
"github.com/syncthing/syncthing/lib/db"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/model"
"github.com/syncthing/syncthing/lib/protocol"
"github.com/syncthing/syncthing/lib/stats"
@@ -249,6 +250,20 @@ type Model struct {
getHelloReturnsOnCall map[int]struct {
result1 protocol.HelloIntf
}
GetMtimeMappingStub func(string, string) (fs.MtimeMapping, error)
getMtimeMappingMutex sync.RWMutex
getMtimeMappingArgsForCall []struct {
arg1 string
arg2 string
}
getMtimeMappingReturns struct {
result1 fs.MtimeMapping
result2 error
}
getMtimeMappingReturnsOnCall map[int]struct {
result1 fs.MtimeMapping
result2 error
}
GlobalDirectoryTreeStub func(string, string, int, bool) ([]*model.TreeEntry, error)
globalDirectoryTreeMutex sync.RWMutex
globalDirectoryTreeArgsForCall []struct {
@@ -1691,6 +1706,71 @@ func (fake *Model) GetHelloReturnsOnCall(i int, result1 protocol.HelloIntf) {
}{result1}
}
func (fake *Model) GetMtimeMapping(arg1 string, arg2 string) (fs.MtimeMapping, error) {
fake.getMtimeMappingMutex.Lock()
ret, specificReturn := fake.getMtimeMappingReturnsOnCall[len(fake.getMtimeMappingArgsForCall)]
fake.getMtimeMappingArgsForCall = append(fake.getMtimeMappingArgsForCall, struct {
arg1 string
arg2 string
}{arg1, arg2})
stub := fake.GetMtimeMappingStub
fakeReturns := fake.getMtimeMappingReturns
fake.recordInvocation("GetMtimeMapping", []interface{}{arg1, arg2})
fake.getMtimeMappingMutex.Unlock()
if stub != nil {
return stub(arg1, arg2)
}
if specificReturn {
return ret.result1, ret.result2
}
return fakeReturns.result1, fakeReturns.result2
}
func (fake *Model) GetMtimeMappingCallCount() int {
fake.getMtimeMappingMutex.RLock()
defer fake.getMtimeMappingMutex.RUnlock()
return len(fake.getMtimeMappingArgsForCall)
}
func (fake *Model) GetMtimeMappingCalls(stub func(string, string) (fs.MtimeMapping, error)) {
fake.getMtimeMappingMutex.Lock()
defer fake.getMtimeMappingMutex.Unlock()
fake.GetMtimeMappingStub = stub
}
func (fake *Model) GetMtimeMappingArgsForCall(i int) (string, string) {
fake.getMtimeMappingMutex.RLock()
defer fake.getMtimeMappingMutex.RUnlock()
argsForCall := fake.getMtimeMappingArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2
}
func (fake *Model) GetMtimeMappingReturns(result1 fs.MtimeMapping, result2 error) {
fake.getMtimeMappingMutex.Lock()
defer fake.getMtimeMappingMutex.Unlock()
fake.GetMtimeMappingStub = nil
fake.getMtimeMappingReturns = struct {
result1 fs.MtimeMapping
result2 error
}{result1, result2}
}
func (fake *Model) GetMtimeMappingReturnsOnCall(i int, result1 fs.MtimeMapping, result2 error) {
fake.getMtimeMappingMutex.Lock()
defer fake.getMtimeMappingMutex.Unlock()
fake.GetMtimeMappingStub = nil
if fake.getMtimeMappingReturnsOnCall == nil {
fake.getMtimeMappingReturnsOnCall = make(map[int]struct {
result1 fs.MtimeMapping
result2 error
})
}
fake.getMtimeMappingReturnsOnCall[i] = struct {
result1 fs.MtimeMapping
result2 error
}{result1, result2}
}
func (fake *Model) GlobalDirectoryTree(arg1 string, arg2 string, arg3 int, arg4 bool) ([]*model.TreeEntry, error) {
fake.globalDirectoryTreeMutex.Lock()
ret, specificReturn := fake.globalDirectoryTreeReturnsOnCall[len(fake.globalDirectoryTreeArgsForCall)]
@@ -3186,6 +3266,8 @@ func (fake *Model) Invocations() map[string][][]interface{} {
defer fake.getFolderVersionsMutex.RUnlock()
fake.getHelloMutex.RLock()
defer fake.getHelloMutex.RUnlock()
fake.getMtimeMappingMutex.RLock()
defer fake.getMtimeMappingMutex.RUnlock()
fake.globalDirectoryTreeMutex.RLock()
defer fake.globalDirectoryTreeMutex.RUnlock()
fake.indexMutex.RLock()
+13 -2
View File
@@ -95,6 +95,7 @@ type Model interface {
CurrentFolderFile(folder string, file string) (protocol.FileInfo, bool, error)
CurrentGlobalFile(folder string, file string) (protocol.FileInfo, bool, error)
GetMtimeMapping(folder string, file string) (fs.MtimeMapping, error)
Availability(folder string, file protocol.FileInfo, block protocol.BlockInfo) ([]Availability, error)
Completion(device protocol.DeviceID, folder string) (FolderCompletion, error)
@@ -2038,12 +2039,12 @@ func (m *model) CurrentFolderFile(folder string, file string) (protocol.FileInfo
func (m *model) CurrentGlobalFile(folder string, file string) (protocol.FileInfo, bool, error) {
m.fmut.RLock()
fs, ok := m.folderFiles[folder]
ffs, ok := m.folderFiles[folder]
m.fmut.RUnlock()
if !ok {
return protocol.FileInfo{}, false, ErrFolderMissing
}
snap, err := fs.Snapshot()
snap, err := ffs.Snapshot()
if err != nil {
return protocol.FileInfo{}, false, err
}
@@ -2052,6 +2053,16 @@ func (m *model) CurrentGlobalFile(folder string, file string) (protocol.FileInfo
return f, ok, nil
}
func (m *model) GetMtimeMapping(folder string, file string) (fs.MtimeMapping, error) {
m.fmut.RLock()
ffs, ok := m.folderFiles[folder]
m.fmut.RUnlock()
if !ok {
return fs.MtimeMapping{}, ErrFolderMissing
}
return fs.GetMtimeMapping(ffs.MtimeFS(), file)
}
// Connection returns the current connection for device, and a boolean whether a connection was found.
func (m *model) Connection(deviceID protocol.DeviceID) (protocol.Connection, bool) {
m.pmut.RLock()