mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 02:18:44 -07:00
Rename package internal/files to internal/db
This commit is contained in:
parent
a2548b1fd0
commit
8d6db7be31
2
build.go
2
build.go
@ -301,7 +301,7 @@ func assets() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func xdr() {
|
func xdr() {
|
||||||
runPrint("go", "generate", "./internal/discover", "./internal/files", "./internal/protocol")
|
runPrint("go", "generate", "./internal/discover", "./internal/db", "./internal/protocol")
|
||||||
}
|
}
|
||||||
|
|
||||||
func translate() {
|
func translate() {
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/syncthing/syncthing/internal/files"
|
"github.com/syncthing/syncthing/internal/db"
|
||||||
"github.com/syncthing/syncthing/internal/protocol"
|
"github.com/syncthing/syncthing/internal/protocol"
|
||||||
"github.com/syndtr/goleveldb/leveldb"
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
)
|
)
|
||||||
@ -34,17 +34,17 @@ func main() {
|
|||||||
device := flag.String("device", "", "Device ID (blank for global)")
|
device := flag.String("device", "", "Device ID (blank for global)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
db, err := leveldb.OpenFile(flag.Arg(0), nil)
|
ldb, err := leveldb.OpenFile(flag.Arg(0), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fs := files.NewSet(*folder, db)
|
fs := db.NewSet(*folder, ldb)
|
||||||
|
|
||||||
if *device == "" {
|
if *device == "" {
|
||||||
log.Printf("*** Global index for folder %q", *folder)
|
log.Printf("*** Global index for folder %q", *folder)
|
||||||
fs.WithGlobalTruncated(func(fi files.FileIntf) bool {
|
fs.WithGlobalTruncated(func(fi db.FileIntf) bool {
|
||||||
f := fi.(files.FileInfoTruncated)
|
f := fi.(db.FileInfoTruncated)
|
||||||
fmt.Println(f)
|
fmt.Println(f)
|
||||||
fmt.Println("\t", fs.Availability(f.Name))
|
fmt.Println("\t", fs.Availability(f.Name))
|
||||||
return true
|
return true
|
||||||
@ -55,8 +55,8 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
log.Printf("*** Have index for folder %q device %q", *folder, n)
|
log.Printf("*** Have index for folder %q device %q", *folder, n)
|
||||||
fs.WithHaveTruncated(n, func(fi files.FileIntf) bool {
|
fs.WithHaveTruncated(n, func(fi db.FileIntf) bool {
|
||||||
f := fi.(files.FileInfoTruncated)
|
f := fi.(db.FileInfoTruncated)
|
||||||
fmt.Println(f)
|
fmt.Println(f)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
@ -34,9 +34,9 @@ import (
|
|||||||
"github.com/calmh/logger"
|
"github.com/calmh/logger"
|
||||||
"github.com/syncthing/syncthing/internal/auto"
|
"github.com/syncthing/syncthing/internal/auto"
|
||||||
"github.com/syncthing/syncthing/internal/config"
|
"github.com/syncthing/syncthing/internal/config"
|
||||||
|
"github.com/syncthing/syncthing/internal/db"
|
||||||
"github.com/syncthing/syncthing/internal/discover"
|
"github.com/syncthing/syncthing/internal/discover"
|
||||||
"github.com/syncthing/syncthing/internal/events"
|
"github.com/syncthing/syncthing/internal/events"
|
||||||
"github.com/syncthing/syncthing/internal/files"
|
|
||||||
"github.com/syncthing/syncthing/internal/model"
|
"github.com/syncthing/syncthing/internal/model"
|
||||||
"github.com/syncthing/syncthing/internal/osutil"
|
"github.com/syncthing/syncthing/internal/osutil"
|
||||||
"github.com/syncthing/syncthing/internal/protocol"
|
"github.com/syncthing/syncthing/internal/protocol"
|
||||||
@ -784,7 +784,7 @@ func mimeTypeForFile(file string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func toNeedSlice(fs []files.FileInfoTruncated) []map[string]interface{} {
|
func toNeedSlice(fs []db.FileInfoTruncated) []map[string]interface{} {
|
||||||
output := make([]map[string]interface{}, len(fs))
|
output := make([]map[string]interface{}, len(fs))
|
||||||
for i, file := range fs {
|
for i, file := range fs {
|
||||||
output[i] = map[string]interface{}{
|
output[i] = map[string]interface{}{
|
||||||
@ -794,7 +794,7 @@ func toNeedSlice(fs []files.FileInfoTruncated) []map[string]interface{} {
|
|||||||
"Version": file.Version,
|
"Version": file.Version,
|
||||||
"LocalVersion": file.LocalVersion,
|
"LocalVersion": file.LocalVersion,
|
||||||
"NumBlocks": file.NumBlocks,
|
"NumBlocks": file.NumBlocks,
|
||||||
"Size": files.BlocksToSize(file.NumBlocks),
|
"Size": db.BlocksToSize(file.NumBlocks),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return output
|
return output
|
||||||
|
@ -38,9 +38,9 @@ import (
|
|||||||
"github.com/calmh/logger"
|
"github.com/calmh/logger"
|
||||||
"github.com/juju/ratelimit"
|
"github.com/juju/ratelimit"
|
||||||
"github.com/syncthing/syncthing/internal/config"
|
"github.com/syncthing/syncthing/internal/config"
|
||||||
|
"github.com/syncthing/syncthing/internal/db"
|
||||||
"github.com/syncthing/syncthing/internal/discover"
|
"github.com/syncthing/syncthing/internal/discover"
|
||||||
"github.com/syncthing/syncthing/internal/events"
|
"github.com/syncthing/syncthing/internal/events"
|
||||||
"github.com/syncthing/syncthing/internal/files"
|
|
||||||
"github.com/syncthing/syncthing/internal/model"
|
"github.com/syncthing/syncthing/internal/model"
|
||||||
"github.com/syncthing/syncthing/internal/osutil"
|
"github.com/syncthing/syncthing/internal/osutil"
|
||||||
"github.com/syncthing/syncthing/internal/protocol"
|
"github.com/syncthing/syncthing/internal/protocol"
|
||||||
@ -489,21 +489,21 @@ func syncthingMain() {
|
|||||||
readRateLimit = ratelimit.NewBucketWithRate(float64(1000*opts.MaxRecvKbps), int64(5*1000*opts.MaxRecvKbps))
|
readRateLimit = ratelimit.NewBucketWithRate(float64(1000*opts.MaxRecvKbps), int64(5*1000*opts.MaxRecvKbps))
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := leveldb.OpenFile(filepath.Join(confDir, "index"), &opt.Options{OpenFilesCacheCapacity: 100})
|
ldb, err := leveldb.OpenFile(filepath.Join(confDir, "index"), &opt.Options{OpenFilesCacheCapacity: 100})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Fatalln("Cannot open database:", err, "- Is another copy of Syncthing already running?")
|
l.Fatalln("Cannot open database:", err, "- Is another copy of Syncthing already running?")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove database entries for folders that no longer exist in the config
|
// Remove database entries for folders that no longer exist in the config
|
||||||
folders := cfg.Folders()
|
folders := cfg.Folders()
|
||||||
for _, folder := range files.ListFolders(db) {
|
for _, folder := range db.ListFolders(ldb) {
|
||||||
if _, ok := folders[folder]; !ok {
|
if _, ok := folders[folder]; !ok {
|
||||||
l.Infof("Cleaning data for dropped folder %q", folder)
|
l.Infof("Cleaning data for dropped folder %q", folder)
|
||||||
files.DropFolder(db, folder)
|
db.DropFolder(ldb, folder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m := model.NewModel(cfg, myName, "syncthing", Version, db)
|
m := model.NewModel(cfg, myName, "syncthing", Version, ldb)
|
||||||
|
|
||||||
sanityCheckFolders(cfg, m)
|
sanityCheckFolders(cfg, m)
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/syncthing/syncthing/internal/config"
|
"github.com/syncthing/syncthing/internal/config"
|
||||||
"github.com/syncthing/syncthing/internal/files"
|
"github.com/syncthing/syncthing/internal/db"
|
||||||
"github.com/syncthing/syncthing/internal/model"
|
"github.com/syncthing/syncthing/internal/model"
|
||||||
"github.com/syncthing/syncthing/internal/protocol"
|
"github.com/syncthing/syncthing/internal/protocol"
|
||||||
|
|
||||||
@ -44,11 +44,11 @@ func TestSanityCheck(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db, _ := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, _ := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
|
|
||||||
// Case 1 - new folder, directory and marker created
|
// Case 1 - new folder, directory and marker created
|
||||||
|
|
||||||
m := model.NewModel(cfg, "device", "syncthing", "dev", db)
|
m := model.NewModel(cfg, "device", "syncthing", "dev", ldb)
|
||||||
sanityCheckFolders(cfg, m)
|
sanityCheckFolders(cfg, m)
|
||||||
|
|
||||||
if cfg.Folders()["folder"].Invalid != "" {
|
if cfg.Folders()["folder"].Invalid != "" {
|
||||||
@ -75,7 +75,7 @@ func TestSanityCheck(t *testing.T) {
|
|||||||
Folders: []config.FolderConfiguration{fcfg},
|
Folders: []config.FolderConfiguration{fcfg},
|
||||||
})
|
})
|
||||||
|
|
||||||
m = model.NewModel(cfg, "device", "syncthing", "dev", db)
|
m = model.NewModel(cfg, "device", "syncthing", "dev", ldb)
|
||||||
sanityCheckFolders(cfg, m)
|
sanityCheckFolders(cfg, m)
|
||||||
|
|
||||||
if cfg.Folders()["folder"].Invalid != "" {
|
if cfg.Folders()["folder"].Invalid != "" {
|
||||||
@ -91,12 +91,12 @@ func TestSanityCheck(t *testing.T) {
|
|||||||
|
|
||||||
// Case 3 - marker missing
|
// Case 3 - marker missing
|
||||||
|
|
||||||
set := files.NewSet("folder", db)
|
set := db.NewSet("folder", ldb)
|
||||||
set.Update(protocol.LocalDeviceID, []protocol.FileInfo{
|
set.Update(protocol.LocalDeviceID, []protocol.FileInfo{
|
||||||
{Name: "dummyfile"},
|
{Name: "dummyfile"},
|
||||||
})
|
})
|
||||||
|
|
||||||
m = model.NewModel(cfg, "device", "syncthing", "dev", db)
|
m = model.NewModel(cfg, "device", "syncthing", "dev", ldb)
|
||||||
sanityCheckFolders(cfg, m)
|
sanityCheckFolders(cfg, m)
|
||||||
|
|
||||||
if cfg.Folders()["folder"].Invalid != "folder marker missing" {
|
if cfg.Folders()["folder"].Invalid != "folder marker missing" {
|
||||||
@ -110,7 +110,7 @@ func TestSanityCheck(t *testing.T) {
|
|||||||
Folders: []config.FolderConfiguration{fcfg},
|
Folders: []config.FolderConfiguration{fcfg},
|
||||||
})
|
})
|
||||||
|
|
||||||
m = model.NewModel(cfg, "device", "syncthing", "dev", db)
|
m = model.NewModel(cfg, "device", "syncthing", "dev", ldb)
|
||||||
sanityCheckFolders(cfg, m)
|
sanityCheckFolders(cfg, m)
|
||||||
|
|
||||||
if cfg.Folders()["folder"].Invalid != "folder path missing" {
|
if cfg.Folders()["folder"].Invalid != "folder path missing" {
|
||||||
|
@ -13,14 +13,14 @@
|
|||||||
// You should have received a copy of the GNU General Public License along
|
// You should have received a copy of the GNU General Public License along
|
||||||
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// Package files provides a set type to track local/remote files with newness
|
// Package db provides a set type to track local/remote files with newness
|
||||||
// checks. We must do a certain amount of normalization in here. We will get
|
// 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
|
// fed paths with either native or wire-format separators and encodings
|
||||||
// depending on who calls us. We transform paths to wire-format (NFC and
|
// 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
|
// slashes) on the way to the database, and transform to native format
|
||||||
// (varying separator and encoding) on the way back out.
|
// (varying separator and encoding) on the way back out.
|
||||||
|
|
||||||
package files
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -13,7 +13,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License along
|
// You should have received a copy of the GNU General Public License along
|
||||||
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package files
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
@ -13,7 +13,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License along
|
// You should have received a copy of the GNU General Public License along
|
||||||
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package files_test
|
package db_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
@ -13,7 +13,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License along
|
// You should have received a copy of the GNU General Public License along
|
||||||
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package files
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
@ -16,7 +16,7 @@
|
|||||||
//go:generate -command genxdr go run ../../Godeps/_workspace/src/github.com/calmh/xdr/cmd/genxdr/main.go
|
//go:generate -command genxdr go run ../../Godeps/_workspace/src/github.com/calmh/xdr/cmd/genxdr/main.go
|
||||||
//go:generate genxdr -o leveldb_xdr.go leveldb.go
|
//go:generate genxdr -o leveldb_xdr.go leveldb.go
|
||||||
|
|
||||||
package files
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -13,7 +13,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License along
|
// You should have received a copy of the GNU General Public License along
|
||||||
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package files
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -2,7 +2,7 @@
|
|||||||
// This file is automatically generated by genxdr. Do not edit.
|
// This file is automatically generated by genxdr. Do not edit.
|
||||||
// ************************************************************
|
// ************************************************************
|
||||||
|
|
||||||
package files
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -13,13 +13,13 @@
|
|||||||
// You should have received a copy of the GNU General Public License along
|
// You should have received a copy of the GNU General Public License along
|
||||||
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// Package files provides a set type to track local/remote files with newness
|
// Package db provides a set type to track local/remote files with newness
|
||||||
// checks. We must do a certain amount of normalization in here. We will get
|
// 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
|
// fed paths with either native or wire-format separators and encodings
|
||||||
// depending on who calls us. We transform paths to wire-format (NFC and
|
// 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
|
// slashes) on the way to the database, and transform to native format
|
||||||
// (varying separator and encoding) on the way back out.
|
// (varying separator and encoding) on the way back out.
|
||||||
package files
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
@ -13,7 +13,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License along
|
// You should have received a copy of the GNU General Public License along
|
||||||
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package files_test
|
package db_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -22,7 +22,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/syncthing/syncthing/internal/files"
|
"github.com/syncthing/syncthing/internal/db"
|
||||||
"github.com/syncthing/syncthing/internal/lamport"
|
"github.com/syncthing/syncthing/internal/lamport"
|
||||||
"github.com/syncthing/syncthing/internal/protocol"
|
"github.com/syncthing/syncthing/internal/protocol"
|
||||||
"github.com/syndtr/goleveldb/leveldb"
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
@ -49,9 +49,9 @@ func genBlocks(n int) []protocol.BlockInfo {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func globalList(s *files.Set) []protocol.FileInfo {
|
func globalList(s *db.Set) []protocol.FileInfo {
|
||||||
var fs []protocol.FileInfo
|
var fs []protocol.FileInfo
|
||||||
s.WithGlobal(func(fi files.FileIntf) bool {
|
s.WithGlobal(func(fi db.FileIntf) bool {
|
||||||
f := fi.(protocol.FileInfo)
|
f := fi.(protocol.FileInfo)
|
||||||
fs = append(fs, f)
|
fs = append(fs, f)
|
||||||
return true
|
return true
|
||||||
@ -59,9 +59,9 @@ func globalList(s *files.Set) []protocol.FileInfo {
|
|||||||
return fs
|
return fs
|
||||||
}
|
}
|
||||||
|
|
||||||
func haveList(s *files.Set, n protocol.DeviceID) []protocol.FileInfo {
|
func haveList(s *db.Set, n protocol.DeviceID) []protocol.FileInfo {
|
||||||
var fs []protocol.FileInfo
|
var fs []protocol.FileInfo
|
||||||
s.WithHave(n, func(fi files.FileIntf) bool {
|
s.WithHave(n, func(fi db.FileIntf) bool {
|
||||||
f := fi.(protocol.FileInfo)
|
f := fi.(protocol.FileInfo)
|
||||||
fs = append(fs, f)
|
fs = append(fs, f)
|
||||||
return true
|
return true
|
||||||
@ -69,9 +69,9 @@ func haveList(s *files.Set, n protocol.DeviceID) []protocol.FileInfo {
|
|||||||
return fs
|
return fs
|
||||||
}
|
}
|
||||||
|
|
||||||
func needList(s *files.Set, n protocol.DeviceID) []protocol.FileInfo {
|
func needList(s *db.Set, n protocol.DeviceID) []protocol.FileInfo {
|
||||||
var fs []protocol.FileInfo
|
var fs []protocol.FileInfo
|
||||||
s.WithNeed(n, func(fi files.FileIntf) bool {
|
s.WithNeed(n, func(fi db.FileIntf) bool {
|
||||||
f := fi.(protocol.FileInfo)
|
f := fi.(protocol.FileInfo)
|
||||||
fs = append(fs, f)
|
fs = append(fs, f)
|
||||||
return true
|
return true
|
||||||
@ -106,12 +106,12 @@ func (l fileList) String() string {
|
|||||||
func TestGlobalSet(t *testing.T) {
|
func TestGlobalSet(t *testing.T) {
|
||||||
lamport.Default = lamport.Clock{}
|
lamport.Default = lamport.Clock{}
|
||||||
|
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
m := files.NewSet("test", db)
|
m := db.NewSet("test", ldb)
|
||||||
|
|
||||||
local0 := fileList{
|
local0 := fileList{
|
||||||
protocol.FileInfo{Name: "a", Version: 1000, Blocks: genBlocks(1)},
|
protocol.FileInfo{Name: "a", Version: 1000, Blocks: genBlocks(1)},
|
||||||
@ -267,12 +267,12 @@ func TestGlobalSet(t *testing.T) {
|
|||||||
func TestNeedWithInvalid(t *testing.T) {
|
func TestNeedWithInvalid(t *testing.T) {
|
||||||
lamport.Default = lamport.Clock{}
|
lamport.Default = lamport.Clock{}
|
||||||
|
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := files.NewSet("test", db)
|
s := db.NewSet("test", ldb)
|
||||||
|
|
||||||
localHave := fileList{
|
localHave := fileList{
|
||||||
protocol.FileInfo{Name: "a", Version: 1000, Blocks: genBlocks(1)},
|
protocol.FileInfo{Name: "a", Version: 1000, Blocks: genBlocks(1)},
|
||||||
@ -309,12 +309,12 @@ func TestNeedWithInvalid(t *testing.T) {
|
|||||||
func TestUpdateToInvalid(t *testing.T) {
|
func TestUpdateToInvalid(t *testing.T) {
|
||||||
lamport.Default = lamport.Clock{}
|
lamport.Default = lamport.Clock{}
|
||||||
|
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := files.NewSet("test", db)
|
s := db.NewSet("test", ldb)
|
||||||
|
|
||||||
localHave := fileList{
|
localHave := fileList{
|
||||||
protocol.FileInfo{Name: "a", Version: 1000, Blocks: genBlocks(1)},
|
protocol.FileInfo{Name: "a", Version: 1000, Blocks: genBlocks(1)},
|
||||||
@ -346,12 +346,12 @@ func TestUpdateToInvalid(t *testing.T) {
|
|||||||
func TestInvalidAvailability(t *testing.T) {
|
func TestInvalidAvailability(t *testing.T) {
|
||||||
lamport.Default = lamport.Clock{}
|
lamport.Default = lamport.Clock{}
|
||||||
|
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := files.NewSet("test", db)
|
s := db.NewSet("test", ldb)
|
||||||
|
|
||||||
remote0Have := fileList{
|
remote0Have := fileList{
|
||||||
protocol.FileInfo{Name: "both", Version: 1001, Blocks: genBlocks(2)},
|
protocol.FileInfo{Name: "both", Version: 1001, Blocks: genBlocks(2)},
|
||||||
@ -387,11 +387,11 @@ func TestInvalidAvailability(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLocalDeleted(t *testing.T) {
|
func TestLocalDeleted(t *testing.T) {
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
m := files.NewSet("test", db)
|
m := db.NewSet("test", ldb)
|
||||||
lamport.Default = lamport.Clock{}
|
lamport.Default = lamport.Clock{}
|
||||||
|
|
||||||
local1 := []protocol.FileInfo{
|
local1 := []protocol.FileInfo{
|
||||||
@ -462,7 +462,7 @@ func TestLocalDeleted(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Benchmark10kReplace(b *testing.B) {
|
func Benchmark10kReplace(b *testing.B) {
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -474,7 +474,7 @@ func Benchmark10kReplace(b *testing.B) {
|
|||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
m := files.NewSet("test", db)
|
m := db.NewSet("test", ldb)
|
||||||
m.ReplaceWithDelete(protocol.LocalDeviceID, local)
|
m.ReplaceWithDelete(protocol.LocalDeviceID, local)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -485,12 +485,12 @@ func Benchmark10kUpdateChg(b *testing.B) {
|
|||||||
remote = append(remote, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
|
remote = append(remote, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
m := files.NewSet("test", db)
|
m := db.NewSet("test", ldb)
|
||||||
m.Replace(remoteDevice0, remote)
|
m.Replace(remoteDevice0, remote)
|
||||||
|
|
||||||
var local []protocol.FileInfo
|
var local []protocol.FileInfo
|
||||||
@ -517,11 +517,11 @@ func Benchmark10kUpdateSme(b *testing.B) {
|
|||||||
remote = append(remote, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
|
remote = append(remote, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
m := files.NewSet("test", db)
|
m := db.NewSet("test", ldb)
|
||||||
m.Replace(remoteDevice0, remote)
|
m.Replace(remoteDevice0, remote)
|
||||||
|
|
||||||
var local []protocol.FileInfo
|
var local []protocol.FileInfo
|
||||||
@ -543,12 +543,12 @@ func Benchmark10kNeed2k(b *testing.B) {
|
|||||||
remote = append(remote, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
|
remote = append(remote, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
m := files.NewSet("test", db)
|
m := db.NewSet("test", ldb)
|
||||||
m.Replace(remoteDevice0, remote)
|
m.Replace(remoteDevice0, remote)
|
||||||
|
|
||||||
var local []protocol.FileInfo
|
var local []protocol.FileInfo
|
||||||
@ -576,12 +576,12 @@ func Benchmark10kHaveFullList(b *testing.B) {
|
|||||||
remote = append(remote, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
|
remote = append(remote, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
m := files.NewSet("test", db)
|
m := db.NewSet("test", ldb)
|
||||||
m.Replace(remoteDevice0, remote)
|
m.Replace(remoteDevice0, remote)
|
||||||
|
|
||||||
var local []protocol.FileInfo
|
var local []protocol.FileInfo
|
||||||
@ -609,12 +609,12 @@ func Benchmark10kGlobal(b *testing.B) {
|
|||||||
remote = append(remote, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
|
remote = append(remote, protocol.FileInfo{Name: fmt.Sprintf("file%d", i), Version: 1000})
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
m := files.NewSet("test", db)
|
m := db.NewSet("test", ldb)
|
||||||
m.Replace(remoteDevice0, remote)
|
m.Replace(remoteDevice0, remote)
|
||||||
|
|
||||||
var local []protocol.FileInfo
|
var local []protocol.FileInfo
|
||||||
@ -637,12 +637,12 @@ func Benchmark10kGlobal(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGlobalReset(t *testing.T) {
|
func TestGlobalReset(t *testing.T) {
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
m := files.NewSet("test", db)
|
m := db.NewSet("test", ldb)
|
||||||
|
|
||||||
local := []protocol.FileInfo{
|
local := []protocol.FileInfo{
|
||||||
{Name: "a", Version: 1000},
|
{Name: "a", Version: 1000},
|
||||||
@ -678,12 +678,12 @@ func TestGlobalReset(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNeed(t *testing.T) {
|
func TestNeed(t *testing.T) {
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
m := files.NewSet("test", db)
|
m := db.NewSet("test", ldb)
|
||||||
|
|
||||||
local := []protocol.FileInfo{
|
local := []protocol.FileInfo{
|
||||||
{Name: "a", Version: 1000},
|
{Name: "a", Version: 1000},
|
||||||
@ -719,12 +719,12 @@ func TestNeed(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLocalVersion(t *testing.T) {
|
func TestLocalVersion(t *testing.T) {
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
m := files.NewSet("test", db)
|
m := db.NewSet("test", ldb)
|
||||||
|
|
||||||
local1 := []protocol.FileInfo{
|
local1 := []protocol.FileInfo{
|
||||||
{Name: "a", Version: 1000},
|
{Name: "a", Version: 1000},
|
||||||
@ -758,12 +758,12 @@ func TestLocalVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestListDropFolder(t *testing.T) {
|
func TestListDropFolder(t *testing.T) {
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s0 := files.NewSet("test0", db)
|
s0 := db.NewSet("test0", ldb)
|
||||||
local1 := []protocol.FileInfo{
|
local1 := []protocol.FileInfo{
|
||||||
{Name: "a", Version: 1000},
|
{Name: "a", Version: 1000},
|
||||||
{Name: "b", Version: 1000},
|
{Name: "b", Version: 1000},
|
||||||
@ -771,7 +771,7 @@ func TestListDropFolder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
s0.Replace(protocol.LocalDeviceID, local1)
|
s0.Replace(protocol.LocalDeviceID, local1)
|
||||||
|
|
||||||
s1 := files.NewSet("test1", db)
|
s1 := db.NewSet("test1", ldb)
|
||||||
local2 := []protocol.FileInfo{
|
local2 := []protocol.FileInfo{
|
||||||
{Name: "d", Version: 1002},
|
{Name: "d", Version: 1002},
|
||||||
{Name: "e", Version: 1002},
|
{Name: "e", Version: 1002},
|
||||||
@ -782,7 +782,7 @@ func TestListDropFolder(t *testing.T) {
|
|||||||
// Check that we have both folders and their data is in the global list
|
// Check that we have both folders and their data is in the global list
|
||||||
|
|
||||||
expectedFolderList := []string{"test0", "test1"}
|
expectedFolderList := []string{"test0", "test1"}
|
||||||
if actualFolderList := files.ListFolders(db); !reflect.DeepEqual(actualFolderList, expectedFolderList) {
|
if actualFolderList := db.ListFolders(ldb); !reflect.DeepEqual(actualFolderList, expectedFolderList) {
|
||||||
t.Fatalf("FolderList mismatch\nE: %v\nA: %v", expectedFolderList, actualFolderList)
|
t.Fatalf("FolderList mismatch\nE: %v\nA: %v", expectedFolderList, actualFolderList)
|
||||||
}
|
}
|
||||||
if l := len(globalList(s0)); l != 3 {
|
if l := len(globalList(s0)); l != 3 {
|
||||||
@ -794,10 +794,10 @@ func TestListDropFolder(t *testing.T) {
|
|||||||
|
|
||||||
// Drop one of them and check that it's gone.
|
// Drop one of them and check that it's gone.
|
||||||
|
|
||||||
files.DropFolder(db, "test1")
|
db.DropFolder(ldb, "test1")
|
||||||
|
|
||||||
expectedFolderList = []string{"test0"}
|
expectedFolderList = []string{"test0"}
|
||||||
if actualFolderList := files.ListFolders(db); !reflect.DeepEqual(actualFolderList, expectedFolderList) {
|
if actualFolderList := db.ListFolders(ldb); !reflect.DeepEqual(actualFolderList, expectedFolderList) {
|
||||||
t.Fatalf("FolderList mismatch\nE: %v\nA: %v", expectedFolderList, actualFolderList)
|
t.Fatalf("FolderList mismatch\nE: %v\nA: %v", expectedFolderList, actualFolderList)
|
||||||
}
|
}
|
||||||
if l := len(globalList(s0)); l != 3 {
|
if l := len(globalList(s0)); l != 3 {
|
||||||
@ -809,12 +809,12 @@ func TestListDropFolder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGlobalNeedWithInvalid(t *testing.T) {
|
func TestGlobalNeedWithInvalid(t *testing.T) {
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := files.NewSet("test1", db)
|
s := db.NewSet("test1", ldb)
|
||||||
|
|
||||||
rem0 := fileList{
|
rem0 := fileList{
|
||||||
protocol.FileInfo{Name: "a", Version: 1002, Blocks: genBlocks(4)},
|
protocol.FileInfo{Name: "a", Version: 1002, Blocks: genBlocks(4)},
|
||||||
@ -849,12 +849,12 @@ func TestGlobalNeedWithInvalid(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLongPath(t *testing.T) {
|
func TestLongPath(t *testing.T) {
|
||||||
db, err := leveldb.Open(storage.NewMemStorage(), nil)
|
ldb, err := leveldb.Open(storage.NewMemStorage(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := files.NewSet("test", db)
|
s := db.NewSet("test", ldb)
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
@ -16,7 +16,7 @@
|
|||||||
//go:generate -command genxdr go run ../../Godeps/_workspace/src/github.com/calmh/xdr/cmd/genxdr/main.go
|
//go:generate -command genxdr go run ../../Godeps/_workspace/src/github.com/calmh/xdr/cmd/genxdr/main.go
|
||||||
//go:generate genxdr -o truncated_xdr.go truncated.go
|
//go:generate genxdr -o truncated_xdr.go truncated.go
|
||||||
|
|
||||||
package files
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -2,7 +2,7 @@
|
|||||||
// This file is automatically generated by genxdr. Do not edit.
|
// This file is automatically generated by genxdr. Do not edit.
|
||||||
// ************************************************************
|
// ************************************************************
|
||||||
|
|
||||||
package files
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -31,8 +31,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/syncthing/syncthing/internal/config"
|
"github.com/syncthing/syncthing/internal/config"
|
||||||
|
"github.com/syncthing/syncthing/internal/db"
|
||||||
"github.com/syncthing/syncthing/internal/events"
|
"github.com/syncthing/syncthing/internal/events"
|
||||||
"github.com/syncthing/syncthing/internal/files"
|
|
||||||
"github.com/syncthing/syncthing/internal/ignore"
|
"github.com/syncthing/syncthing/internal/ignore"
|
||||||
"github.com/syncthing/syncthing/internal/lamport"
|
"github.com/syncthing/syncthing/internal/lamport"
|
||||||
"github.com/syncthing/syncthing/internal/osutil"
|
"github.com/syncthing/syncthing/internal/osutil"
|
||||||
@ -86,7 +86,7 @@ type service interface {
|
|||||||
type Model struct {
|
type Model struct {
|
||||||
cfg *config.Wrapper
|
cfg *config.Wrapper
|
||||||
db *leveldb.DB
|
db *leveldb.DB
|
||||||
finder *files.BlockFinder
|
finder *db.BlockFinder
|
||||||
progressEmitter *ProgressEmitter
|
progressEmitter *ProgressEmitter
|
||||||
|
|
||||||
deviceName string
|
deviceName string
|
||||||
@ -94,7 +94,7 @@ type Model struct {
|
|||||||
clientVersion string
|
clientVersion string
|
||||||
|
|
||||||
folderCfgs map[string]config.FolderConfiguration // folder -> cfg
|
folderCfgs map[string]config.FolderConfiguration // folder -> cfg
|
||||||
folderFiles map[string]*files.Set // folder -> files
|
folderFiles map[string]*db.Set // folder -> files
|
||||||
folderDevices map[string][]protocol.DeviceID // folder -> deviceIDs
|
folderDevices map[string][]protocol.DeviceID // folder -> deviceIDs
|
||||||
deviceFolders map[protocol.DeviceID][]string // deviceID -> folders
|
deviceFolders map[protocol.DeviceID][]string // deviceID -> folders
|
||||||
deviceStatRefs map[protocol.DeviceID]*stats.DeviceStatisticsReference // deviceID -> statsRef
|
deviceStatRefs map[protocol.DeviceID]*stats.DeviceStatisticsReference // deviceID -> statsRef
|
||||||
@ -126,15 +126,15 @@ var (
|
|||||||
// NewModel creates and starts a new model. The model starts in read-only mode,
|
// NewModel creates and starts a new model. The model starts in read-only mode,
|
||||||
// where it sends index information to connected peers and responds to requests
|
// where it sends index information to connected peers and responds to requests
|
||||||
// for file data without altering the local folder in any way.
|
// for file data without altering the local folder in any way.
|
||||||
func NewModel(cfg *config.Wrapper, deviceName, clientName, clientVersion string, db *leveldb.DB) *Model {
|
func NewModel(cfg *config.Wrapper, deviceName, clientName, clientVersion string, ldb *leveldb.DB) *Model {
|
||||||
m := &Model{
|
m := &Model{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
db: db,
|
db: ldb,
|
||||||
deviceName: deviceName,
|
deviceName: deviceName,
|
||||||
clientName: clientName,
|
clientName: clientName,
|
||||||
clientVersion: clientVersion,
|
clientVersion: clientVersion,
|
||||||
folderCfgs: make(map[string]config.FolderConfiguration),
|
folderCfgs: make(map[string]config.FolderConfiguration),
|
||||||
folderFiles: make(map[string]*files.Set),
|
folderFiles: make(map[string]*db.Set),
|
||||||
folderDevices: make(map[string][]protocol.DeviceID),
|
folderDevices: make(map[string][]protocol.DeviceID),
|
||||||
deviceFolders: make(map[protocol.DeviceID][]string),
|
deviceFolders: make(map[protocol.DeviceID][]string),
|
||||||
deviceStatRefs: make(map[protocol.DeviceID]*stats.DeviceStatisticsReference),
|
deviceStatRefs: make(map[protocol.DeviceID]*stats.DeviceStatisticsReference),
|
||||||
@ -146,7 +146,7 @@ func NewModel(cfg *config.Wrapper, deviceName, clientName, clientVersion string,
|
|||||||
protoConn: make(map[protocol.DeviceID]protocol.Connection),
|
protoConn: make(map[protocol.DeviceID]protocol.Connection),
|
||||||
rawConn: make(map[protocol.DeviceID]io.Closer),
|
rawConn: make(map[protocol.DeviceID]io.Closer),
|
||||||
deviceVer: make(map[protocol.DeviceID]string),
|
deviceVer: make(map[protocol.DeviceID]string),
|
||||||
finder: files.NewBlockFinder(db, cfg),
|
finder: db.NewBlockFinder(ldb, cfg),
|
||||||
progressEmitter: NewProgressEmitter(cfg),
|
progressEmitter: NewProgressEmitter(cfg),
|
||||||
}
|
}
|
||||||
if cfg.Options().ProgressUpdateIntervalS > -1 {
|
if cfg.Options().ProgressUpdateIntervalS > -1 {
|
||||||
@ -309,7 +309,7 @@ func (m *Model) Completion(device protocol.DeviceID, folder string) float64 {
|
|||||||
return 0 // Folder doesn't exist, so we hardly have any of it
|
return 0 // Folder doesn't exist, so we hardly have any of it
|
||||||
}
|
}
|
||||||
|
|
||||||
rf.WithGlobalTruncated(func(f files.FileIntf) bool {
|
rf.WithGlobalTruncated(func(f db.FileIntf) bool {
|
||||||
if !f.IsDeleted() {
|
if !f.IsDeleted() {
|
||||||
tot += f.Size()
|
tot += f.Size()
|
||||||
}
|
}
|
||||||
@ -321,7 +321,7 @@ func (m *Model) Completion(device protocol.DeviceID, folder string) float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var need int64
|
var need int64
|
||||||
rf.WithNeedTruncated(device, func(f files.FileIntf) bool {
|
rf.WithNeedTruncated(device, func(f db.FileIntf) bool {
|
||||||
if !f.IsDeleted() {
|
if !f.IsDeleted() {
|
||||||
need += f.Size()
|
need += f.Size()
|
||||||
}
|
}
|
||||||
@ -346,7 +346,7 @@ func sizeOf(fs []protocol.FileInfo) (files, deleted int, bytes int64) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func sizeOfFile(f files.FileIntf) (files, deleted int, bytes int64) {
|
func sizeOfFile(f db.FileIntf) (files, deleted int, bytes int64) {
|
||||||
if !f.IsDeleted() {
|
if !f.IsDeleted() {
|
||||||
files++
|
files++
|
||||||
} else {
|
} else {
|
||||||
@ -364,7 +364,7 @@ func (m *Model) GlobalSize(folder string) (nfiles, deleted int, bytes int64) {
|
|||||||
m.fmut.RLock()
|
m.fmut.RLock()
|
||||||
defer m.fmut.RUnlock()
|
defer m.fmut.RUnlock()
|
||||||
if rf, ok := m.folderFiles[folder]; ok {
|
if rf, ok := m.folderFiles[folder]; ok {
|
||||||
rf.WithGlobalTruncated(func(f files.FileIntf) bool {
|
rf.WithGlobalTruncated(func(f db.FileIntf) bool {
|
||||||
fs, de, by := sizeOfFile(f)
|
fs, de, by := sizeOfFile(f)
|
||||||
nfiles += fs
|
nfiles += fs
|
||||||
deleted += de
|
deleted += de
|
||||||
@ -383,7 +383,7 @@ func (m *Model) LocalSize(folder string) (nfiles, deleted int, bytes int64) {
|
|||||||
m.fmut.RLock()
|
m.fmut.RLock()
|
||||||
defer m.fmut.RUnlock()
|
defer m.fmut.RUnlock()
|
||||||
if rf, ok := m.folderFiles[folder]; ok {
|
if rf, ok := m.folderFiles[folder]; ok {
|
||||||
rf.WithHaveTruncated(protocol.LocalDeviceID, func(f files.FileIntf) bool {
|
rf.WithHaveTruncated(protocol.LocalDeviceID, func(f db.FileIntf) bool {
|
||||||
if f.IsInvalid() {
|
if f.IsInvalid() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -404,7 +404,7 @@ func (m *Model) NeedSize(folder string) (nfiles int, bytes int64) {
|
|||||||
m.fmut.RLock()
|
m.fmut.RLock()
|
||||||
defer m.fmut.RUnlock()
|
defer m.fmut.RUnlock()
|
||||||
if rf, ok := m.folderFiles[folder]; ok {
|
if rf, ok := m.folderFiles[folder]; ok {
|
||||||
rf.WithNeedTruncated(protocol.LocalDeviceID, func(f files.FileIntf) bool {
|
rf.WithNeedTruncated(protocol.LocalDeviceID, func(f db.FileIntf) bool {
|
||||||
fs, de, by := sizeOfFile(f)
|
fs, de, by := sizeOfFile(f)
|
||||||
nfiles += fs + de
|
nfiles += fs + de
|
||||||
bytes += by
|
bytes += by
|
||||||
@ -421,21 +421,21 @@ func (m *Model) NeedSize(folder string) (nfiles int, bytes int64) {
|
|||||||
// NeedFiles returns the list of currently needed files in progress, queued,
|
// NeedFiles returns the list of currently needed files in progress, queued,
|
||||||
// and to be queued on next puller iteration. Also takes a soft cap which is
|
// and to be queued on next puller iteration. Also takes a soft cap which is
|
||||||
// only respected when adding files from the model rather than the runner queue.
|
// only respected when adding files from the model rather than the runner queue.
|
||||||
func (m *Model) NeedFolderFiles(folder string, max int) ([]files.FileInfoTruncated, []files.FileInfoTruncated, []files.FileInfoTruncated) {
|
func (m *Model) NeedFolderFiles(folder string, max int) ([]db.FileInfoTruncated, []db.FileInfoTruncated, []db.FileInfoTruncated) {
|
||||||
defer m.leveldbPanicWorkaround()
|
defer m.leveldbPanicWorkaround()
|
||||||
|
|
||||||
m.fmut.RLock()
|
m.fmut.RLock()
|
||||||
defer m.fmut.RUnlock()
|
defer m.fmut.RUnlock()
|
||||||
if rf, ok := m.folderFiles[folder]; ok {
|
if rf, ok := m.folderFiles[folder]; ok {
|
||||||
var progress, queued, rest []files.FileInfoTruncated
|
var progress, queued, rest []db.FileInfoTruncated
|
||||||
var seen map[string]bool
|
var seen map[string]bool
|
||||||
|
|
||||||
runner, ok := m.folderRunners[folder]
|
runner, ok := m.folderRunners[folder]
|
||||||
if ok {
|
if ok {
|
||||||
progressNames, queuedNames := runner.Jobs()
|
progressNames, queuedNames := runner.Jobs()
|
||||||
|
|
||||||
progress = make([]files.FileInfoTruncated, len(progressNames))
|
progress = make([]db.FileInfoTruncated, len(progressNames))
|
||||||
queued = make([]files.FileInfoTruncated, len(queuedNames))
|
queued = make([]db.FileInfoTruncated, len(queuedNames))
|
||||||
seen = make(map[string]bool, len(progressNames)+len(queuedNames))
|
seen = make(map[string]bool, len(progressNames)+len(queuedNames))
|
||||||
|
|
||||||
for i, name := range progressNames {
|
for i, name := range progressNames {
|
||||||
@ -454,9 +454,9 @@ func (m *Model) NeedFolderFiles(folder string, max int) ([]files.FileInfoTruncat
|
|||||||
}
|
}
|
||||||
left := max - len(progress) - len(queued)
|
left := max - len(progress) - len(queued)
|
||||||
if max < 1 || left > 0 {
|
if max < 1 || left > 0 {
|
||||||
rf.WithNeedTruncated(protocol.LocalDeviceID, func(f files.FileIntf) bool {
|
rf.WithNeedTruncated(protocol.LocalDeviceID, func(f db.FileIntf) bool {
|
||||||
left--
|
left--
|
||||||
ft := f.(files.FileInfoTruncated)
|
ft := f.(db.FileInfoTruncated)
|
||||||
if !seen[ft.Name] {
|
if !seen[ft.Name] {
|
||||||
rest = append(rest, ft)
|
rest = append(rest, ft)
|
||||||
}
|
}
|
||||||
@ -949,7 +949,7 @@ func (m *Model) receivedFile(folder, filename string) {
|
|||||||
m.folderStatRef(folder).ReceivedFile(filename)
|
m.folderStatRef(folder).ReceivedFile(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendIndexes(conn protocol.Connection, folder string, fs *files.Set, ignores *ignore.Matcher) {
|
func sendIndexes(conn protocol.Connection, folder string, fs *db.Set, ignores *ignore.Matcher) {
|
||||||
deviceID := conn.ID()
|
deviceID := conn.ID()
|
||||||
name := conn.Name()
|
name := conn.Name()
|
||||||
var err error
|
var err error
|
||||||
@ -974,7 +974,7 @@ func sendIndexes(conn protocol.Connection, folder string, fs *files.Set, ignores
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendIndexTo(initial bool, minLocalVer uint64, conn protocol.Connection, folder string, fs *files.Set, ignores *ignore.Matcher) (uint64, error) {
|
func sendIndexTo(initial bool, minLocalVer uint64, conn protocol.Connection, folder string, fs *db.Set, ignores *ignore.Matcher) (uint64, error) {
|
||||||
deviceID := conn.ID()
|
deviceID := conn.ID()
|
||||||
name := conn.Name()
|
name := conn.Name()
|
||||||
batch := make([]protocol.FileInfo, 0, indexBatchSize)
|
batch := make([]protocol.FileInfo, 0, indexBatchSize)
|
||||||
@ -982,7 +982,7 @@ func sendIndexTo(initial bool, minLocalVer uint64, conn protocol.Connection, fol
|
|||||||
maxLocalVer := uint64(0)
|
maxLocalVer := uint64(0)
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
fs.WithHave(protocol.LocalDeviceID, func(fi files.FileIntf) bool {
|
fs.WithHave(protocol.LocalDeviceID, func(fi db.FileIntf) bool {
|
||||||
f := fi.(protocol.FileInfo)
|
f := fi.(protocol.FileInfo)
|
||||||
if f.LocalVersion <= minLocalVer {
|
if f.LocalVersion <= minLocalVer {
|
||||||
return true
|
return true
|
||||||
@ -1081,7 +1081,7 @@ func (m *Model) AddFolder(cfg config.FolderConfiguration) {
|
|||||||
|
|
||||||
m.fmut.Lock()
|
m.fmut.Lock()
|
||||||
m.folderCfgs[cfg.ID] = cfg
|
m.folderCfgs[cfg.ID] = cfg
|
||||||
m.folderFiles[cfg.ID] = files.NewSet(cfg.ID, m.db)
|
m.folderFiles[cfg.ID] = db.NewSet(cfg.ID, m.db)
|
||||||
|
|
||||||
m.folderDevices[cfg.ID] = make([]protocol.DeviceID, len(cfg.Devices))
|
m.folderDevices[cfg.ID] = make([]protocol.DeviceID, len(cfg.Devices))
|
||||||
for i, device := range cfg.Devices {
|
for i, device := range cfg.Devices {
|
||||||
@ -1182,8 +1182,8 @@ func (m *Model) ScanFolderSub(folder, sub string) error {
|
|||||||
batch = batch[:0]
|
batch = batch[:0]
|
||||||
// TODO: We should limit the Have scanning to start at sub
|
// TODO: We should limit the Have scanning to start at sub
|
||||||
seenPrefix := false
|
seenPrefix := false
|
||||||
fs.WithHaveTruncated(protocol.LocalDeviceID, func(fi files.FileIntf) bool {
|
fs.WithHaveTruncated(protocol.LocalDeviceID, func(fi db.FileIntf) bool {
|
||||||
f := fi.(files.FileInfoTruncated)
|
f := fi.(db.FileInfoTruncated)
|
||||||
if !strings.HasPrefix(f.Name, sub) {
|
if !strings.HasPrefix(f.Name, sub) {
|
||||||
// Return true so that we keep iterating, until we get to the part
|
// Return true so that we keep iterating, until we get to the part
|
||||||
// of the tree we are interested in. Then return false so we stop
|
// of the tree we are interested in. Then return false so we stop
|
||||||
@ -1323,7 +1323,7 @@ func (m *Model) Override(folder string) {
|
|||||||
|
|
||||||
m.setState(folder, FolderScanning)
|
m.setState(folder, FolderScanning)
|
||||||
batch := make([]protocol.FileInfo, 0, indexBatchSize)
|
batch := make([]protocol.FileInfo, 0, indexBatchSize)
|
||||||
fs.WithNeed(protocol.LocalDeviceID, func(fi files.FileIntf) bool {
|
fs.WithNeed(protocol.LocalDeviceID, func(fi db.FileIntf) bool {
|
||||||
need := fi.(protocol.FileInfo)
|
need := fi.(protocol.FileInfo)
|
||||||
if len(batch) == indexBatchSize {
|
if len(batch) == indexBatchSize {
|
||||||
fs.Update(protocol.LocalDeviceID, batch)
|
fs.Update(protocol.LocalDeviceID, batch)
|
||||||
|
@ -28,8 +28,8 @@ import (
|
|||||||
"github.com/AudriusButkevicius/lfu-go"
|
"github.com/AudriusButkevicius/lfu-go"
|
||||||
|
|
||||||
"github.com/syncthing/syncthing/internal/config"
|
"github.com/syncthing/syncthing/internal/config"
|
||||||
|
"github.com/syncthing/syncthing/internal/db"
|
||||||
"github.com/syncthing/syncthing/internal/events"
|
"github.com/syncthing/syncthing/internal/events"
|
||||||
"github.com/syncthing/syncthing/internal/files"
|
|
||||||
"github.com/syncthing/syncthing/internal/ignore"
|
"github.com/syncthing/syncthing/internal/ignore"
|
||||||
"github.com/syncthing/syncthing/internal/osutil"
|
"github.com/syncthing/syncthing/internal/osutil"
|
||||||
"github.com/syncthing/syncthing/internal/protocol"
|
"github.com/syncthing/syncthing/internal/protocol"
|
||||||
@ -299,7 +299,7 @@ func (p *Puller) pullerIteration(ignores *ignore.Matcher) int {
|
|||||||
|
|
||||||
var deletions []protocol.FileInfo
|
var deletions []protocol.FileInfo
|
||||||
|
|
||||||
folderFiles.WithNeed(protocol.LocalDeviceID, func(intf files.FileIntf) bool {
|
folderFiles.WithNeed(protocol.LocalDeviceID, func(intf db.FileIntf) bool {
|
||||||
|
|
||||||
// Needed items are delivered sorted lexicographically. This isn't
|
// Needed items are delivered sorted lexicographically. This isn't
|
||||||
// really optimal from a performance point of view - it would be
|
// really optimal from a performance point of view - it would be
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/syncthing/syncthing/internal/files"
|
"github.com/syncthing/syncthing/internal/db"
|
||||||
"github.com/syncthing/syncthing/internal/protocol"
|
"github.com/syncthing/syncthing/internal/protocol"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ func (s *sharedPullerState) Progress() *pullerProgress {
|
|||||||
CopiedFromElsewhere: s.copyTotal - s.copyNeeded - s.copyOrigin,
|
CopiedFromElsewhere: s.copyTotal - s.copyNeeded - s.copyOrigin,
|
||||||
Pulled: s.pullTotal - s.pullNeeded,
|
Pulled: s.pullTotal - s.pullNeeded,
|
||||||
Pulling: s.pullNeeded,
|
Pulling: s.pullNeeded,
|
||||||
BytesTotal: files.BlocksToSize(total),
|
BytesTotal: db.BlocksToSize(total),
|
||||||
BytesDone: files.BlocksToSize(done),
|
BytesDone: db.BlocksToSize(done),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user