all: Add receive only folder type (#5027)
Adds a receive only folder type that does not send changes, and where the user can optionally revert local changes. Also changes some of the icons to make the three folder types distinguishable.
This commit is contained in:
@@ -57,6 +57,7 @@ const (
|
||||
type service interface {
|
||||
BringToFront(string)
|
||||
Override(*db.FileSet, func([]protocol.FileInfo))
|
||||
Revert(*db.FileSet, func([]protocol.FileInfo))
|
||||
DelayScan(d time.Duration)
|
||||
IgnoresUpdated() // ignore matcher was updated notification
|
||||
SchedulePull() // something relevant changed, we should try a pull
|
||||
@@ -690,6 +691,18 @@ func (m *Model) LocalSize(folder string) db.Counts {
|
||||
return db.Counts{}
|
||||
}
|
||||
|
||||
// ReceiveOnlyChangedSize returns the number of files, deleted files and
|
||||
// total bytes for all files that have changed locally in a receieve only
|
||||
// folder.
|
||||
func (m *Model) ReceiveOnlyChangedSize(folder string) db.Counts {
|
||||
m.fmut.RLock()
|
||||
defer m.fmut.RUnlock()
|
||||
if rf, ok := m.folderFiles[folder]; ok {
|
||||
return rf.ReceiveOnlyChangedSize()
|
||||
}
|
||||
return db.Counts{}
|
||||
}
|
||||
|
||||
// NeedSize returns the number and total size of currently needed files.
|
||||
func (m *Model) NeedSize(folder string) db.Counts {
|
||||
m.fmut.RLock()
|
||||
@@ -1747,6 +1760,12 @@ func sendIndexTo(prevSequence int64, conn protocol.Connection, folder string, fs
|
||||
|
||||
// Mark the file as invalid if any of the local bad stuff flags are set.
|
||||
f.RawInvalid = f.IsInvalid()
|
||||
// If the file is marked LocalReceive (i.e., changed locally on a
|
||||
// receive only folder) we do not want it to ever become the
|
||||
// globally best version, invalid or not.
|
||||
if f.IsReceiveOnlyChanged() {
|
||||
f.Version = protocol.Vector{}
|
||||
}
|
||||
f.LocalFlags = 0 // never sent externally
|
||||
|
||||
if dropSymlinks && f.IsSymlink() {
|
||||
@@ -1940,7 +1959,7 @@ func (m *Model) ScanFolderSubdirs(folder string, subs []string) error {
|
||||
return runner.Scan(subs)
|
||||
}
|
||||
|
||||
func (m *Model) internalScanFolderSubdirs(ctx context.Context, folder string, subDirs []string) error {
|
||||
func (m *Model) internalScanFolderSubdirs(ctx context.Context, folder string, subDirs []string, localFlags uint32) error {
|
||||
m.fmut.RLock()
|
||||
if err := m.checkFolderRunningLocked(folder); err != nil {
|
||||
m.fmut.RUnlock()
|
||||
@@ -2010,6 +2029,7 @@ func (m *Model) internalScanFolderSubdirs(ctx context.Context, folder string, su
|
||||
ShortID: m.shortID,
|
||||
ProgressTickIntervalS: folderCfg.ScanProgressIntervalS,
|
||||
UseLargeBlocks: folderCfg.UseLargeBlocks,
|
||||
LocalFlags: localFlags,
|
||||
})
|
||||
|
||||
if err := runner.CheckHealth(); err != nil {
|
||||
@@ -2106,6 +2126,7 @@ func (m *Model) internalScanFolderSubdirs(ctx context.Context, folder string, su
|
||||
ModifiedBy: m.id.Short(),
|
||||
Deleted: true,
|
||||
Version: f.Version.Update(m.shortID),
|
||||
LocalFlags: localFlags,
|
||||
}
|
||||
// We do not want to override the global version
|
||||
// with the deleted file. Keeping only our local
|
||||
@@ -2289,6 +2310,24 @@ func (m *Model) Override(folder string) {
|
||||
})
|
||||
}
|
||||
|
||||
func (m *Model) Revert(folder string) {
|
||||
// Grab the runner and the file set.
|
||||
|
||||
m.fmut.RLock()
|
||||
fs, fsOK := m.folderFiles[folder]
|
||||
runner, runnerOK := m.folderRunners[folder]
|
||||
m.fmut.RUnlock()
|
||||
if !fsOK || !runnerOK {
|
||||
return
|
||||
}
|
||||
|
||||
// Run the revert, taking updates as if they came from scanning.
|
||||
|
||||
runner.Revert(fs, func(files []protocol.FileInfo) {
|
||||
m.updateLocalsFromScanning(folder, files)
|
||||
})
|
||||
}
|
||||
|
||||
// CurrentSequence returns the change version for the given folder.
|
||||
// This is guaranteed to increment if the contents of the local folder has
|
||||
// changed.
|
||||
|
||||
Reference in New Issue
Block a user