2014-11-16 20:13:20 +00:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
2014-09-29 19:43:32 +00:00
|
|
|
//
|
2015-03-07 20:36:35 +00:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 06:52:18 +00:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2014-06-01 20:50:14 +00:00
|
|
|
|
2015-01-12 13:50:30 +00:00
|
|
|
// Package db provides a set type to track local/remote files with newness
|
2014-08-15 10:52:16 +00:00
|
|
|
// checks. We must do a certain amount of normalization in here. We will get
|
|
|
|
// fed paths with either native or wire-format separators and encodings
|
|
|
|
// depending on who calls us. We transform paths to wire-format (NFC and
|
|
|
|
// slashes) on the way to the database, and transform to native format
|
|
|
|
// (varying separator and encoding) on the way back out.
|
2015-01-12 13:50:30 +00:00
|
|
|
package db
|
2014-03-28 13:36:57 +00:00
|
|
|
|
|
|
|
import (
|
2017-12-14 09:51:17 +00:00
|
|
|
"os"
|
2018-09-02 18:58:32 +00:00
|
|
|
"sort"
|
2017-12-14 09:51:17 +00:00
|
|
|
"time"
|
2015-10-20 13:58:18 +00:00
|
|
|
|
2016-08-05 17:45:45 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/fs"
|
2015-08-06 09:29:25 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/osutil"
|
2015-09-22 17:38:46 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/protocol"
|
2015-08-06 09:29:25 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/sync"
|
2014-03-28 13:36:57 +00:00
|
|
|
)
|
|
|
|
|
2015-01-12 13:52:24 +00:00
|
|
|
type FileSet struct {
|
2017-12-14 09:51:17 +00:00
|
|
|
folder string
|
|
|
|
fs fs.Filesystem
|
|
|
|
db *Instance
|
|
|
|
blockmap *BlockMap
|
|
|
|
meta *metadataTracker
|
|
|
|
|
|
|
|
updateMutex sync.Mutex // protects database updates and the corresponding metadata changes
|
2014-03-28 13:36:57 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 07:18:42 +00:00
|
|
|
// FileIntf is the set of methods implemented by both protocol.FileInfo and
|
2016-07-04 10:40:29 +00:00
|
|
|
// FileInfoTruncated.
|
2015-01-09 07:18:42 +00:00
|
|
|
type FileIntf interface {
|
2016-07-04 10:40:29 +00:00
|
|
|
FileSize() int64
|
|
|
|
FileName() string
|
2018-07-12 08:15:57 +00:00
|
|
|
FileLocalFlags() uint32
|
2015-01-09 07:18:42 +00:00
|
|
|
IsDeleted() bool
|
|
|
|
IsInvalid() bool
|
2018-07-12 08:15:57 +00:00
|
|
|
IsIgnored() bool
|
|
|
|
IsUnsupported() bool
|
|
|
|
MustRescan() bool
|
2015-01-09 07:18:42 +00:00
|
|
|
IsDirectory() bool
|
|
|
|
IsSymlink() bool
|
2018-08-25 08:32:35 +00:00
|
|
|
ShouldConflict() bool
|
2015-01-09 07:18:42 +00:00
|
|
|
HasPermissionBits() bool
|
2017-12-14 09:51:17 +00:00
|
|
|
SequenceNo() int64
|
2018-04-16 18:08:50 +00:00
|
|
|
BlockSize() int
|
2018-06-02 13:08:32 +00:00
|
|
|
FileVersion() protocol.Vector
|
2015-01-09 07:18:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The Iterator is called with either a protocol.FileInfo or a
|
2016-07-04 10:40:29 +00:00
|
|
|
// FileInfoTruncated (depending on the method) and returns true to
|
2015-01-09 07:18:42 +00:00
|
|
|
// continue iteration, false to stop.
|
|
|
|
type Iterator func(f FileIntf) bool
|
|
|
|
|
2017-12-14 09:51:17 +00:00
|
|
|
var databaseRecheckInterval = 30 * 24 * time.Hour
|
2015-10-21 07:10:26 +00:00
|
|
|
|
2017-12-14 09:51:17 +00:00
|
|
|
func init() {
|
|
|
|
if dur, err := time.ParseDuration(os.Getenv("STRECHECKDBEVERY")); err == nil {
|
|
|
|
databaseRecheckInterval = dur
|
2015-10-20 13:58:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 09:51:17 +00:00
|
|
|
func NewFileSet(folder string, fs fs.Filesystem, db *Instance) *FileSet {
|
|
|
|
var s = FileSet{
|
|
|
|
folder: folder,
|
|
|
|
fs: fs,
|
|
|
|
db: db,
|
|
|
|
blockmap: NewBlockMap(db, db.folderIdx.ID([]byte(folder))),
|
|
|
|
meta: newMetadataTracker(),
|
|
|
|
updateMutex: sync.NewMutex(),
|
2015-10-20 13:58:18 +00:00
|
|
|
}
|
2015-10-21 07:10:26 +00:00
|
|
|
|
2017-12-14 09:51:17 +00:00
|
|
|
if err := s.meta.fromDB(db, []byte(folder)); err != nil {
|
|
|
|
l.Infof("No stored folder metadata for %q: recalculating", folder)
|
|
|
|
s.recalcCounts()
|
|
|
|
} else if age := time.Since(s.meta.Created()); age > databaseRecheckInterval {
|
|
|
|
l.Infof("Stored folder metadata for %q is %v old; recalculating", folder, age)
|
|
|
|
s.recalcCounts()
|
2015-10-20 13:58:18 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 09:51:17 +00:00
|
|
|
return &s
|
2017-11-12 20:20:34 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 09:51:17 +00:00
|
|
|
func (s *FileSet) recalcCounts() {
|
|
|
|
s.meta = newMetadataTracker()
|
2015-10-20 13:58:18 +00:00
|
|
|
|
2017-12-14 09:51:17 +00:00
|
|
|
s.db.checkGlobals([]byte(s.folder), s.meta)
|
2014-10-30 15:48:14 +00:00
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
var deviceID protocol.DeviceID
|
2017-12-14 09:51:17 +00:00
|
|
|
s.db.withAllFolderTruncated([]byte(s.folder), func(device []byte, f FileInfoTruncated) bool {
|
2014-09-28 11:00:38 +00:00
|
|
|
copy(deviceID[:], device)
|
2017-12-14 09:51:17 +00:00
|
|
|
s.meta.addFile(deviceID, f)
|
2014-07-15 11:04:37 +00:00
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
2017-12-14 09:51:17 +00:00
|
|
|
s.meta.SetCreated()
|
|
|
|
s.meta.toDB(s.db, []byte(s.folder))
|
2014-03-28 13:36:57 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 20:20:34 +00:00
|
|
|
func (s *FileSet) Drop(device protocol.DeviceID) {
|
|
|
|
l.Debugf("%s Drop(%v)", s.folder, device)
|
2016-07-23 18:32:10 +00:00
|
|
|
|
|
|
|
s.updateMutex.Lock()
|
|
|
|
defer s.updateMutex.Unlock()
|
|
|
|
|
2017-12-14 09:51:17 +00:00
|
|
|
s.db.dropDeviceFolder(device[:], []byte(s.folder), s.meta)
|
2017-11-12 20:20:34 +00:00
|
|
|
|
2014-10-07 21:15:01 +00:00
|
|
|
if device == protocol.LocalDeviceID {
|
|
|
|
s.blockmap.Drop()
|
2017-12-14 09:51:17 +00:00
|
|
|
s.meta.resetCounts(device)
|
|
|
|
// We deliberately do not reset the sequence number here. Dropping
|
|
|
|
// all files for the local device ID only happens in testing - which
|
|
|
|
// expects the sequence to be retained, like an old Replace() of all
|
|
|
|
// files would do. However, if we ever did it "in production" we
|
|
|
|
// would anyway want to retain the sequence for delta indexes to be
|
|
|
|
// happy.
|
2017-11-12 20:20:34 +00:00
|
|
|
} else {
|
|
|
|
// Here, on the other hand, we want to make sure that any file
|
|
|
|
// announced from the remote is newer than our current sequence
|
|
|
|
// number.
|
2017-12-14 09:51:17 +00:00
|
|
|
s.meta.resetAll(device)
|
2014-10-07 21:15:01 +00:00
|
|
|
}
|
2017-12-14 09:51:17 +00:00
|
|
|
|
|
|
|
s.meta.toDB(s.db, []byte(s.folder))
|
2014-03-28 13:36:57 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 13:52:24 +00:00
|
|
|
func (s *FileSet) Update(device protocol.DeviceID, fs []protocol.FileInfo) {
|
2015-10-03 15:25:21 +00:00
|
|
|
l.Debugf("%s Update(%v, [%d])", s.folder, device, len(fs))
|
2018-01-18 12:40:43 +00:00
|
|
|
|
|
|
|
// do not modify fs in place, it is still used in outer scope
|
|
|
|
fs = append([]protocol.FileInfo(nil), fs...)
|
|
|
|
|
2014-08-15 10:52:16 +00:00
|
|
|
normalizeFilenames(fs)
|
2016-07-23 18:32:10 +00:00
|
|
|
|
|
|
|
s.updateMutex.Lock()
|
|
|
|
defer s.updateMutex.Unlock()
|
|
|
|
|
2018-09-02 18:58:32 +00:00
|
|
|
defer s.meta.toDB(s.db, []byte(s.folder))
|
|
|
|
|
|
|
|
if device != protocol.LocalDeviceID {
|
|
|
|
// Easy case, just update the files and we're done.
|
|
|
|
s.db.updateFiles([]byte(s.folder), device[:], fs, s.meta)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// For the local device we have a bunch of metadata to track however...
|
|
|
|
|
|
|
|
discards := make([]protocol.FileInfo, 0, len(fs))
|
|
|
|
updates := make([]protocol.FileInfo, 0, len(fs))
|
|
|
|
// db.UpdateFiles will sort unchanged files out -> save one db lookup
|
|
|
|
// filter slice according to https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating
|
|
|
|
oldFs := fs
|
|
|
|
fs = fs[:0]
|
|
|
|
var dk []byte
|
|
|
|
folder := []byte(s.folder)
|
|
|
|
for _, nf := range oldFs {
|
2018-09-18 08:41:06 +00:00
|
|
|
dk = s.db.keyer.GenerateDeviceFileKey(dk, folder, device[:], []byte(osutil.NormalizedFilename(nf.Name)))
|
2018-09-02 18:58:32 +00:00
|
|
|
ef, ok := s.db.getFile(dk)
|
|
|
|
if ok && ef.Version.Equal(nf.Version) && ef.IsInvalid() == nf.IsInvalid() {
|
|
|
|
continue
|
2014-10-22 14:24:11 +00:00
|
|
|
}
|
2018-09-02 18:58:32 +00:00
|
|
|
|
|
|
|
nf.Sequence = s.meta.nextSeq(protocol.LocalDeviceID)
|
|
|
|
fs = append(fs, nf)
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
discards = append(discards, ef)
|
|
|
|
}
|
|
|
|
updates = append(updates, nf)
|
2014-10-22 14:24:11 +00:00
|
|
|
}
|
2017-12-14 09:51:17 +00:00
|
|
|
|
2018-09-02 18:58:32 +00:00
|
|
|
// The ordering here is important. We first remove stuff that point to
|
|
|
|
// files we are going to update, then update them, then add new index
|
|
|
|
// pointers etc. In addition, we do the discards in reverse order so
|
|
|
|
// that a reader traversing the sequence index will get a consistent
|
|
|
|
// view up until the point they meet the writer.
|
|
|
|
|
|
|
|
sort.Slice(discards, func(a, b int) bool {
|
|
|
|
// n.b. "b < a" instead of the usual "a < b"
|
|
|
|
return discards[b].Sequence < discards[a].Sequence
|
|
|
|
})
|
|
|
|
|
|
|
|
s.blockmap.Discard(discards)
|
|
|
|
s.db.removeSequences(folder, discards)
|
2017-12-14 09:51:17 +00:00
|
|
|
s.db.updateFiles([]byte(s.folder), device[:], fs, s.meta)
|
2018-09-02 18:58:32 +00:00
|
|
|
s.db.addSequences(folder, updates)
|
|
|
|
s.blockmap.Update(updates)
|
2014-03-28 13:36:57 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 13:52:24 +00:00
|
|
|
func (s *FileSet) WithNeed(device protocol.DeviceID, fn Iterator) {
|
2015-10-03 15:25:21 +00:00
|
|
|
l.Debugf("%s WithNeed(%v)", s.folder, device)
|
2018-02-25 08:39:00 +00:00
|
|
|
s.db.withNeed([]byte(s.folder), device[:], false, nativeFileIterator(fn))
|
2014-08-12 11:53:31 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 13:52:24 +00:00
|
|
|
func (s *FileSet) WithNeedTruncated(device protocol.DeviceID, fn Iterator) {
|
2015-10-03 15:25:21 +00:00
|
|
|
l.Debugf("%s WithNeedTruncated(%v)", s.folder, device)
|
2018-02-25 08:39:00 +00:00
|
|
|
s.db.withNeed([]byte(s.folder), device[:], true, nativeFileIterator(fn))
|
2014-03-28 13:36:57 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 13:52:24 +00:00
|
|
|
func (s *FileSet) WithHave(device protocol.DeviceID, fn Iterator) {
|
2015-10-03 15:25:21 +00:00
|
|
|
l.Debugf("%s WithHave(%v)", s.folder, device)
|
2016-03-18 12:16:33 +00:00
|
|
|
s.db.withHave([]byte(s.folder), device[:], nil, false, nativeFileIterator(fn))
|
2014-08-12 11:53:31 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 13:52:24 +00:00
|
|
|
func (s *FileSet) WithHaveTruncated(device protocol.DeviceID, fn Iterator) {
|
2015-10-03 15:25:21 +00:00
|
|
|
l.Debugf("%s WithHaveTruncated(%v)", s.folder, device)
|
2016-03-18 12:16:33 +00:00
|
|
|
s.db.withHave([]byte(s.folder), device[:], nil, true, nativeFileIterator(fn))
|
2014-03-28 13:36:57 +00:00
|
|
|
}
|
|
|
|
|
2018-05-01 21:39:15 +00:00
|
|
|
func (s *FileSet) WithHaveSequence(startSeq int64, fn Iterator) {
|
|
|
|
l.Debugf("%s WithHaveSequence(%v)", s.folder, startSeq)
|
|
|
|
s.db.withHaveSequence([]byte(s.folder), startSeq, nativeFileIterator(fn))
|
|
|
|
}
|
|
|
|
|
2018-05-17 07:26:40 +00:00
|
|
|
// Except for an item with a path equal to prefix, only children of prefix are iterated.
|
|
|
|
// E.g. for prefix "dir", "dir/file" is iterated, but "dir.file" is not.
|
2018-02-14 07:59:46 +00:00
|
|
|
func (s *FileSet) WithPrefixedHaveTruncated(device protocol.DeviceID, prefix string, fn Iterator) {
|
2018-05-17 07:26:40 +00:00
|
|
|
l.Debugf(`%s WithPrefixedHaveTruncated(%v, "%v")`, s.folder, device, prefix)
|
2018-02-14 07:59:46 +00:00
|
|
|
s.db.withHave([]byte(s.folder), device[:], []byte(osutil.NormalizedFilename(prefix)), true, nativeFileIterator(fn))
|
2016-03-18 12:16:33 +00:00
|
|
|
}
|
2015-01-12 13:52:24 +00:00
|
|
|
func (s *FileSet) WithGlobal(fn Iterator) {
|
2015-10-03 15:25:21 +00:00
|
|
|
l.Debugf("%s WithGlobal()", s.folder)
|
2015-10-28 20:01:46 +00:00
|
|
|
s.db.withGlobal([]byte(s.folder), nil, false, nativeFileIterator(fn))
|
2014-08-12 14:17:28 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 13:52:24 +00:00
|
|
|
func (s *FileSet) WithGlobalTruncated(fn Iterator) {
|
2015-10-03 15:25:21 +00:00
|
|
|
l.Debugf("%s WithGlobalTruncated()", s.folder)
|
2015-10-28 20:01:46 +00:00
|
|
|
s.db.withGlobal([]byte(s.folder), nil, true, nativeFileIterator(fn))
|
2015-02-07 10:52:42 +00:00
|
|
|
}
|
|
|
|
|
2018-05-17 07:26:40 +00:00
|
|
|
// Except for an item with a path equal to prefix, only children of prefix are iterated.
|
|
|
|
// E.g. for prefix "dir", "dir/file" is iterated, but "dir.file" is not.
|
2015-02-07 10:52:42 +00:00
|
|
|
func (s *FileSet) WithPrefixedGlobalTruncated(prefix string, fn Iterator) {
|
2018-05-17 07:26:40 +00:00
|
|
|
l.Debugf(`%s WithPrefixedGlobalTruncated("%v")`, s.folder, prefix)
|
2015-10-28 20:01:46 +00:00
|
|
|
s.db.withGlobal([]byte(s.folder), []byte(osutil.NormalizedFilename(prefix)), true, nativeFileIterator(fn))
|
2014-03-28 13:36:57 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 13:52:24 +00:00
|
|
|
func (s *FileSet) Get(device protocol.DeviceID, file string) (protocol.FileInfo, bool) {
|
2018-09-18 08:41:06 +00:00
|
|
|
f, ok := s.db.getFile(s.db.keyer.GenerateDeviceFileKey(nil, []byte(s.folder), device[:], []byte(osutil.NormalizedFilename(file))))
|
2014-11-05 23:41:51 +00:00
|
|
|
f.Name = osutil.NativeFilename(f.Name)
|
2015-01-06 21:12:45 +00:00
|
|
|
return f, ok
|
2014-03-28 13:36:57 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 13:52:24 +00:00
|
|
|
func (s *FileSet) GetGlobal(file string) (protocol.FileInfo, bool) {
|
2015-10-28 20:01:46 +00:00
|
|
|
fi, ok := s.db.getGlobal([]byte(s.folder), []byte(osutil.NormalizedFilename(file)), false)
|
2015-01-09 07:41:02 +00:00
|
|
|
if !ok {
|
|
|
|
return protocol.FileInfo{}, false
|
|
|
|
}
|
|
|
|
f := fi.(protocol.FileInfo)
|
2014-11-05 23:41:51 +00:00
|
|
|
f.Name = osutil.NativeFilename(f.Name)
|
2015-01-09 07:41:02 +00:00
|
|
|
return f, true
|
|
|
|
}
|
|
|
|
|
2015-01-12 13:52:24 +00:00
|
|
|
func (s *FileSet) GetGlobalTruncated(file string) (FileInfoTruncated, bool) {
|
2015-10-28 20:01:46 +00:00
|
|
|
fi, ok := s.db.getGlobal([]byte(s.folder), []byte(osutil.NormalizedFilename(file)), true)
|
2015-01-09 07:41:02 +00:00
|
|
|
if !ok {
|
|
|
|
return FileInfoTruncated{}, false
|
|
|
|
}
|
|
|
|
f := fi.(FileInfoTruncated)
|
|
|
|
f.Name = osutil.NativeFilename(f.Name)
|
|
|
|
return f, true
|
2014-03-28 13:36:57 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 13:52:24 +00:00
|
|
|
func (s *FileSet) Availability(file string) []protocol.DeviceID {
|
2015-10-28 20:01:46 +00:00
|
|
|
return s.db.availability([]byte(s.folder), []byte(osutil.NormalizedFilename(file)))
|
2014-03-28 13:36:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 19:54:24 +00:00
|
|
|
func (s *FileSet) Sequence(device protocol.DeviceID) int64 {
|
2018-07-12 08:15:57 +00:00
|
|
|
return s.meta.Counts(device, 0).Sequence
|
2014-03-28 13:36:57 +00:00
|
|
|
}
|
2014-08-15 10:52:16 +00:00
|
|
|
|
2016-10-17 12:10:17 +00:00
|
|
|
func (s *FileSet) LocalSize() Counts {
|
2018-07-12 08:15:57 +00:00
|
|
|
local := s.meta.Counts(protocol.LocalDeviceID, 0)
|
|
|
|
recvOnlyChanged := s.meta.Counts(protocol.LocalDeviceID, protocol.FlagLocalReceiveOnly)
|
|
|
|
return local.Add(recvOnlyChanged)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *FileSet) ReceiveOnlyChangedSize() Counts {
|
|
|
|
return s.meta.Counts(protocol.LocalDeviceID, protocol.FlagLocalReceiveOnly)
|
2015-10-21 07:10:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-17 12:10:17 +00:00
|
|
|
func (s *FileSet) GlobalSize() Counts {
|
2018-07-12 08:15:57 +00:00
|
|
|
global := s.meta.Counts(protocol.GlobalDeviceID, 0)
|
|
|
|
recvOnlyChanged := s.meta.Counts(protocol.GlobalDeviceID, protocol.FlagLocalReceiveOnly)
|
|
|
|
return global.Add(recvOnlyChanged)
|
2015-10-21 07:10:26 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 12:46:31 +00:00
|
|
|
func (s *FileSet) IndexID(device protocol.DeviceID) protocol.IndexID {
|
|
|
|
id := s.db.getIndexID(device[:], []byte(s.folder))
|
|
|
|
if id == 0 && device == protocol.LocalDeviceID {
|
|
|
|
// No index ID set yet. We create one now.
|
|
|
|
id = protocol.NewIndexID()
|
|
|
|
s.db.setIndexID(device[:], []byte(s.folder), id)
|
|
|
|
}
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *FileSet) SetIndexID(device protocol.DeviceID, id protocol.IndexID) {
|
|
|
|
if device == protocol.LocalDeviceID {
|
|
|
|
panic("do not explicitly set index ID for local device")
|
|
|
|
}
|
|
|
|
s.db.setIndexID(device[:], []byte(s.folder), id)
|
|
|
|
}
|
|
|
|
|
2016-08-05 17:45:45 +00:00
|
|
|
func (s *FileSet) MtimeFS() *fs.MtimeFS {
|
2018-09-18 08:41:06 +00:00
|
|
|
prefix := s.db.keyer.GenerateMtimesKey(nil, []byte(s.folder))
|
2016-08-05 17:45:45 +00:00
|
|
|
kv := NewNamespacedKV(s.db, string(prefix))
|
2017-08-19 14:36:56 +00:00
|
|
|
return fs.NewMtimeFS(s.fs, kv)
|
2016-08-05 17:45:45 +00:00
|
|
|
}
|
|
|
|
|
2016-08-07 16:21:59 +00:00
|
|
|
func (s *FileSet) ListDevices() []protocol.DeviceID {
|
2017-12-14 09:51:17 +00:00
|
|
|
return s.meta.devices()
|
2016-07-23 12:46:31 +00:00
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
// DropFolder clears out all information related to the given folder from the
|
2014-08-31 11:34:17 +00:00
|
|
|
// database.
|
2015-10-31 11:31:25 +00:00
|
|
|
func DropFolder(db *Instance, folder string) {
|
|
|
|
db.dropFolder([]byte(folder))
|
2016-08-05 17:45:45 +00:00
|
|
|
db.dropMtimes([]byte(folder))
|
2017-12-14 09:51:17 +00:00
|
|
|
db.dropFolderMeta([]byte(folder))
|
2014-10-07 21:15:01 +00:00
|
|
|
bm := &BlockMap{
|
|
|
|
db: db,
|
2016-01-03 18:08:19 +00:00
|
|
|
folder: db.folderIdx.ID([]byte(folder)),
|
2014-10-07 21:15:01 +00:00
|
|
|
}
|
|
|
|
bm.Drop()
|
2014-08-31 11:34:17 +00:00
|
|
|
}
|
|
|
|
|
2014-08-15 10:52:16 +00:00
|
|
|
func normalizeFilenames(fs []protocol.FileInfo) {
|
|
|
|
for i := range fs {
|
2014-11-05 23:41:51 +00:00
|
|
|
fs[i].Name = osutil.NormalizedFilename(fs[i].Name)
|
2014-08-15 10:52:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-09 07:18:42 +00:00
|
|
|
func nativeFileIterator(fn Iterator) Iterator {
|
|
|
|
return func(fi FileIntf) bool {
|
2014-08-15 10:52:16 +00:00
|
|
|
switch f := fi.(type) {
|
|
|
|
case protocol.FileInfo:
|
2014-11-05 23:41:51 +00:00
|
|
|
f.Name = osutil.NativeFilename(f.Name)
|
2014-08-15 10:52:16 +00:00
|
|
|
return fn(f)
|
2015-01-09 07:19:32 +00:00
|
|
|
case FileInfoTruncated:
|
2014-11-05 23:41:51 +00:00
|
|
|
f.Name = osutil.NativeFilename(f.Name)
|
2014-08-15 10:52:16 +00:00
|
|
|
return fn(f)
|
|
|
|
default:
|
|
|
|
panic("unknown interface type")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|