本文整理汇总了Golang中github.com/syncthing/syncthing/lib/config.FolderConfiguration类的典型用法代码示例。如果您正苦于以下问题:Golang FolderConfiguration类的具体用法?Golang FolderConfiguration怎么用?Golang FolderConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FolderConfiguration类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: newRWFolder
func newRWFolder(model *Model, cfg config.FolderConfiguration, ver versioner.Versioner, mtimeFS *fs.MtimeFS) service {
f := &rwFolder{
folder: folder{
stateTracker: newStateTracker(cfg.ID),
scan: newFolderScanner(cfg),
stop: make(chan struct{}),
model: model,
},
mtimeFS: mtimeFS,
dir: cfg.Path(),
versioner: ver,
ignorePerms: cfg.IgnorePerms,
copiers: cfg.Copiers,
pullers: cfg.Pullers,
order: cfg.Order,
maxConflicts: cfg.MaxConflicts,
allowSparse: !cfg.DisableSparseFiles,
checkFreeSpace: cfg.MinDiskFreePct != 0,
ignoreDelete: cfg.IgnoreDelete,
fsync: cfg.Fsync,
queue: newJobQueue(),
pullTimer: time.NewTimer(time.Second),
remoteIndex: make(chan struct{}, 1), // This needs to be 1-buffered so that we queue a notification if we're busy doing a pull when it comes.
errorsMut: sync.NewMutex(),
initialScanCompleted: make(chan struct{}),
}
f.configureCopiersAndPullers(cfg)
return f
}
开发者ID:kluppy,项目名称:syncthing,代码行数:35,代码来源:rwfolder.go
示例2: newRWFolder
func newRWFolder(m *Model, shortID uint64, cfg config.FolderConfiguration) *rwFolder {
return &rwFolder{
stateTracker: stateTracker{
folder: cfg.ID,
mut: sync.NewMutex(),
},
model: m,
progressEmitter: m.progressEmitter,
virtualMtimeRepo: db.NewVirtualMtimeRepo(m.db, cfg.ID),
folder: cfg.ID,
dir: cfg.Path(),
scanIntv: time.Duration(cfg.RescanIntervalS) * time.Second,
ignorePerms: cfg.IgnorePerms,
copiers: cfg.Copiers,
pullers: cfg.Pullers,
shortID: shortID,
order: cfg.Order,
stop: make(chan struct{}),
queue: newJobQueue(),
pullTimer: time.NewTimer(shortPullIntv),
scanTimer: time.NewTimer(time.Millisecond), // The first scan should be done immediately.
delayScan: make(chan time.Duration),
scanNow: make(chan rescanRequest),
remoteIndex: make(chan struct{}, 1), // This needs to be 1-buffered so that we queue a notification if we're busy doing a pull when it comes.
errorsMut: sync.NewMutex(),
}
}
开发者ID:kristallizer,项目名称:syncthing,代码行数:31,代码来源:rwfolder.go
示例3: newRWFolder
func newRWFolder(m *Model, shortID uint64, cfg config.FolderConfiguration) *rwFolder {
p := &rwFolder{
stateTracker: stateTracker{
folder: cfg.ID,
mut: sync.NewMutex(),
},
model: m,
progressEmitter: m.progressEmitter,
virtualMtimeRepo: db.NewVirtualMtimeRepo(m.db, cfg.ID),
folder: cfg.ID,
dir: cfg.Path(),
scanIntv: time.Duration(cfg.RescanIntervalS) * time.Second,
ignorePerms: cfg.IgnorePerms,
copiers: cfg.Copiers,
pullers: cfg.Pullers,
shortID: shortID,
order: cfg.Order,
maxConflicts: cfg.MaxConflicts,
allowSparse: !cfg.DisableSparseFiles,
checkFreeSpace: cfg.MinDiskFreePct != 0,
stop: make(chan struct{}),
queue: newJobQueue(),
pullTimer: time.NewTimer(time.Second),
scanTimer: time.NewTimer(time.Millisecond), // The first scan should be done immediately.
delayScan: make(chan time.Duration),
scanNow: make(chan rescanRequest),
remoteIndex: make(chan struct{}, 1), // This needs to be 1-buffered so that we queue a notification if we're busy doing a pull when it comes.
errorsMut: sync.NewMutex(),
}
if p.copiers == 0 {
p.copiers = defaultCopiers
}
if p.pullers == 0 {
p.pullers = defaultPullers
}
if cfg.PullerPauseS == 0 {
p.pause = defaultPullerPause
} else {
p.pause = time.Duration(cfg.PullerPauseS) * time.Second
}
if cfg.PullerSleepS == 0 {
p.sleep = defaultPullerSleep
} else {
p.sleep = time.Duration(cfg.PullerSleepS) * time.Second
}
return p
}
开发者ID:KetanSingh11,项目名称:syncthing,代码行数:55,代码来源:rwfolder.go
示例4: newRWFolder
func newRWFolder(model *Model, cfg config.FolderConfiguration, ver versioner.Versioner) service {
f := &rwFolder{
folder: folder{
stateTracker: stateTracker{
folderID: cfg.ID,
mut: sync.NewMutex(),
},
scan: folderscan{
interval: time.Duration(cfg.RescanIntervalS) * time.Second,
timer: time.NewTimer(time.Millisecond), // The first scan should be done immediately.
now: make(chan rescanRequest),
delay: make(chan time.Duration),
},
stop: make(chan struct{}),
model: model,
},
virtualMtimeRepo: db.NewVirtualMtimeRepo(model.db, cfg.ID),
dir: cfg.Path(),
ignorePerms: cfg.IgnorePerms,
copiers: cfg.Copiers,
pullers: cfg.Pullers,
order: cfg.Order,
maxConflicts: cfg.MaxConflicts,
allowSparse: !cfg.DisableSparseFiles,
checkFreeSpace: cfg.MinDiskFreePct != 0,
versioner: ver,
queue: newJobQueue(),
pullTimer: time.NewTimer(time.Second),
remoteIndex: make(chan struct{}, 1), // This needs to be 1-buffered so that we queue a notification if we're busy doing a pull when it comes.
errorsMut: sync.NewMutex(),
initialScanCompleted: make(chan struct{}),
}
f.configureCopiersAndPullers(cfg)
return f
}
开发者ID:carriercomm,项目名称:syncthing,代码行数:41,代码来源:rwfolder.go
示例5: defaultConfig
func defaultConfig(myName string) config.Configuration {
var defaultFolder config.FolderConfiguration
if !noDefaultFolder {
l.Infoln("Default folder created and/or linked to new config")
folderID := rand.String(5) + "-" + rand.String(5)
defaultFolder = config.NewFolderConfiguration(folderID, locations[locDefFolder])
defaultFolder.Label = "Default Folder (" + folderID + ")"
defaultFolder.RescanIntervalS = 60
defaultFolder.MinDiskFreePct = 1
defaultFolder.Devices = []config.FolderDeviceConfiguration{{DeviceID: myID}}
defaultFolder.AutoNormalize = true
defaultFolder.MaxConflicts = -1
} else {
l.Infoln("We will skip creation of a default folder on first start since the proper envvar is set")
}
thisDevice := config.NewDeviceConfiguration(myID, myName)
thisDevice.Addresses = []string{"dynamic"}
newCfg := config.New(myID)
if !noDefaultFolder {
newCfg.Folders = []config.FolderConfiguration{defaultFolder}
}
newCfg.Devices = []config.DeviceConfiguration{thisDevice}
port, err := getFreePort("127.0.0.1", 8384)
if err != nil {
l.Fatalln("get free port (GUI):", err)
}
newCfg.GUI.RawAddress = fmt.Sprintf("127.0.0.1:%d", port)
port, err = getFreePort("0.0.0.0", 22000)
if err != nil {
l.Fatalln("get free port (BEP):", err)
}
if port == 22000 {
newCfg.Options.ListenAddresses = []string{"default"}
} else {
newCfg.Options.ListenAddresses = []string{
fmt.Sprintf("tcp://%s", net.JoinHostPort("0.0.0.0", strconv.Itoa(port))),
"dynamic+https://relays.syncthing.net/endpoint",
}
}
return newCfg
}
开发者ID:carriercomm,项目名称:syncthing,代码行数:47,代码来源:main.go
示例6: defaultConfig
func defaultConfig(myName string) config.Configuration {
var defaultFolder config.FolderConfiguration
if !noDefaultFolder {
l.Infoln("Default folder created and/or linked to new config")
defaultFolder = config.NewFolderConfiguration("default", locations[locDefFolder])
defaultFolder.RescanIntervalS = 60
defaultFolder.MinDiskFreePct = 1
defaultFolder.Devices = []config.FolderDeviceConfiguration{{DeviceID: myID}}
defaultFolder.AutoNormalize = true
defaultFolder.MaxConflicts = -1
} else {
l.Infoln("We will skip creation of a default folder on first start since the proper envvar is set")
}
thisDevice := config.NewDeviceConfiguration(myID, myName)
thisDevice.Addresses = []string{"dynamic"}
newCfg := config.New(myID)
if !noDefaultFolder {
newCfg.Folders = []config.FolderConfiguration{defaultFolder}
}
newCfg.Devices = []config.DeviceConfiguration{thisDevice}
port, err := getFreePort("127.0.0.1", 8384)
if err != nil {
l.Fatalln("get free port (GUI):", err)
}
newCfg.GUI.RawAddress = fmt.Sprintf("127.0.0.1:%d", port)
port, err = getFreePort("0.0.0.0", 22000)
if err != nil {
l.Fatalln("get free port (BEP):", err)
}
newCfg.Options.ListenAddress = []string{fmt.Sprintf("tcp://0.0.0.0:%d", port)}
return newCfg
}
开发者ID:18pineda,项目名称:syncthing,代码行数:38,代码来源:main.go
示例7: TestFolderErrors
func TestFolderErrors(t *testing.T) {
// This test intentionally avoids starting the folders. If they are
// started, they will perform an initial scan, which will create missing
// folder markers and race with the stuff we do in the test.
fcfg := config.FolderConfiguration{
ID: "folder",
RawPath: "testdata/testfolder",
}
cfg := config.Wrap("/tmp/test", config.Configuration{
Folders: []config.FolderConfiguration{fcfg},
})
for _, file := range []string{".stfolder", "testfolder/.stfolder", "testfolder"} {
if err := os.Remove("testdata/" + file); err != nil && !os.IsNotExist(err) {
t.Fatal(err)
}
}
ldb := db.OpenMemory()
// Case 1 - new folder, directory and marker created
m := model.NewModel(cfg, protocol.LocalDeviceID, "device", "syncthing", "dev", ldb, nil)
m.AddFolder(fcfg)
if err := m.CheckFolderHealth("folder"); err != nil {
t.Error("Unexpected error", cfg.Folders()["folder"].Invalid)
}
s, err := os.Stat("testdata/testfolder")
if err != nil || !s.IsDir() {
t.Error(err)
}
_, err = os.Stat("testdata/testfolder/.stfolder")
if err != nil {
t.Error(err)
}
if err := os.Remove("testdata/testfolder/.stfolder"); err != nil {
t.Fatal(err)
}
if err := os.Remove("testdata/testfolder/"); err != nil {
t.Fatal(err)
}
// Case 2 - new folder, marker created
fcfg.RawPath = "testdata/"
cfg = config.Wrap("/tmp/test", config.Configuration{
Folders: []config.FolderConfiguration{fcfg},
})
m = model.NewModel(cfg, protocol.LocalDeviceID, "device", "syncthing", "dev", ldb, nil)
m.AddFolder(fcfg)
if err := m.CheckFolderHealth("folder"); err != nil {
t.Error("Unexpected error", cfg.Folders()["folder"].Invalid)
}
_, err = os.Stat("testdata/.stfolder")
if err != nil {
t.Error(err)
}
if err := os.Remove("testdata/.stfolder"); err != nil {
t.Fatal(err)
}
// Case 3 - Folder marker missing
set := db.NewFileSet("folder", ldb)
set.Update(protocol.LocalDeviceID, []protocol.FileInfo{
{Name: "dummyfile"},
})
m = model.NewModel(cfg, protocol.LocalDeviceID, "device", "syncthing", "dev", ldb, nil)
m.AddFolder(fcfg)
if err := m.CheckFolderHealth("folder"); err == nil || err.Error() != "folder marker missing" {
t.Error("Incorrect error: Folder marker missing !=", m.CheckFolderHealth("folder"))
}
// Case 3.1 - recover after folder marker missing
if err = fcfg.CreateMarker(); err != nil {
t.Error(err)
}
if err := m.CheckFolderHealth("folder"); err != nil {
t.Error("Unexpected error", cfg.Folders()["folder"].Invalid)
}
// Case 4 - Folder path missing
if err := os.Remove("testdata/testfolder/.stfolder"); err != nil && !os.IsNotExist(err) {
t.Fatal(err)
}
if err := os.Remove("testdata/testfolder"); err != nil && !os.IsNotExist(err) {
//.........这里部分代码省略.........
开发者ID:WeavingCode,项目名称:syncthing,代码行数:101,代码来源:main_test.go
示例8: TestFolderWithoutRestart
func TestFolderWithoutRestart(t *testing.T) {
log.Println("Cleaning...")
err := removeAll("testfolder-p1", "testfolder-p4", "h1/index*", "h4/index*")
if err != nil {
t.Fatal(err)
}
defer removeAll("testfolder-p1", "testfolder-p4")
if err := generateFiles("testfolder-p1", 50, 18, "../LICENSE"); err != nil {
t.Fatal(err)
}
p1 := startInstance(t, 1)
defer checkedStop(t, p1)
p4 := startInstance(t, 4)
defer checkedStop(t, p4)
if ok, err := p1.ConfigInSync(); err != nil || !ok {
t.Fatal("p1 should be in sync;", ok, err)
}
if ok, err := p4.ConfigInSync(); err != nil || !ok {
t.Fatal("p4 should be in sync;", ok, err)
}
// Add a new folder to p1, shared with p4. Back up and restore the config
// first.
log.Println("Adding testfolder to p1...")
os.Remove("h1/config.xml.orig")
os.Rename("h1/config.xml", "h1/config.xml.orig")
defer osutil.Rename("h1/config.xml.orig", "h1/config.xml")
cfg, err := p1.GetConfig()
if err != nil {
t.Fatal(err)
}
newFolder := config.FolderConfiguration{
ID: "testfolder",
RawPath: "testfolder-p1",
RescanIntervalS: 86400,
Copiers: 1,
Hashers: 1,
Pullers: 1,
Devices: []config.FolderDeviceConfiguration{{DeviceID: p4.ID()}},
}
newDevice := config.DeviceConfiguration{
DeviceID: p4.ID(),
Name: "p4",
Addresses: []string{"dynamic"},
Compression: protocol.CompressMetadata,
}
cfg.Folders = append(cfg.Folders, newFolder)
cfg.Devices = append(cfg.Devices, newDevice)
if err = p1.PostConfig(cfg); err != nil {
t.Fatal(err)
}
// Add a new folder to p4, shared with p1. Back up and restore the config
// first.
log.Println("Adding testfolder to p4...")
os.Remove("h4/config.xml.orig")
os.Rename("h4/config.xml", "h4/config.xml.orig")
defer osutil.Rename("h4/config.xml.orig", "h4/config.xml")
cfg, err = p4.GetConfig()
if err != nil {
t.Fatal(err)
}
newFolder.RawPath = "testfolder-p4"
newFolder.Devices = []config.FolderDeviceConfiguration{{DeviceID: p1.ID()}}
newDevice.DeviceID = p1.ID()
newDevice.Name = "p1"
newDevice.Addresses = []string{"127.0.0.1:22001"}
cfg.Folders = append(cfg.Folders, newFolder)
cfg.Devices = append(cfg.Devices, newDevice)
if err = p4.PostConfig(cfg); err != nil {
t.Fatal(err)
}
// The change should not require a restart, so the config should be "in sync"
if ok, err := p1.ConfigInSync(); err != nil || !ok {
t.Fatal("p1 should be in sync;", ok, err)
}
if ok, err := p4.ConfigInSync(); err != nil || !ok {
t.Fatal("p4 should be in sync;", ok, err)
}
// The folder should start and scan - wait for the event that signals this
//.........这里部分代码省略.........
开发者ID:rwx-zwx-awx,项目名称:syncthing,代码行数:101,代码来源:norestart_test.go
注:本文中的github.com/syncthing/syncthing/lib/config.FolderConfiguration类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论