Rename FolderConfiguration.Directory to FolderConfiguration.Path

This commit is contained in:
Audrius Butkevicius 2014-09-28 12:56:35 +01:00
parent fdf8ee7015
commit f561d3261a
6 changed files with 30 additions and 30 deletions

View File

@ -351,7 +351,7 @@ func syncthingMain() {
cfg.Folders = []config.FolderConfiguration{ cfg.Folders = []config.FolderConfiguration{
{ {
ID: "default", ID: "default",
Directory: defaultFolder, Path: defaultFolder,
RescanIntervalS: 60, RescanIntervalS: 60,
Devices: []config.FolderDeviceConfiguration{{DeviceID: myID}}, Devices: []config.FolderDeviceConfiguration{{DeviceID: myID}},
}, },
@ -438,10 +438,10 @@ nextFolder:
if folder.Invalid != "" { if folder.Invalid != "" {
continue continue
} }
folder.Directory = expandTilde(folder.Directory) folder.Path = expandTilde(folder.Path)
m.AddFolder(folder) m.AddFolder(folder)
fi, err := os.Stat(folder.Directory) fi, err := os.Stat(folder.Path)
if m.CurrentLocalVersion(folder.ID) > 0 { if m.CurrentLocalVersion(folder.ID) > 0 {
// Safety check. If the cached index contains files but the // Safety check. If the cached index contains files but the
// folder doesn't exist, we have a problem. We would assume // folder doesn't exist, we have a problem. We would assume
@ -455,7 +455,7 @@ nextFolder:
} else if os.IsNotExist(err) { } else if os.IsNotExist(err) {
// If we don't have any files in the index, and the directory // If we don't have any files in the index, and the directory
// doesn't exist, try creating it. // doesn't exist, try creating it.
err = os.MkdirAll(folder.Directory, 0700) err = os.MkdirAll(folder.Path, 0700)
} }
if err != nil { if err != nil {
@ -533,7 +533,7 @@ nextFolder:
validIndexes := make(map[string]bool) validIndexes := make(map[string]bool)
for _, folder := range cfg.Folders { for _, folder := range cfg.Folders {
dir := expandTilde(folder.Directory) dir := expandTilde(folder.Path)
id := fmt.Sprintf("%x", sha1.Sum([]byte(dir))) id := fmt.Sprintf("%x", sha1.Sum([]byte(dir)))
validIndexes[id] = true validIndexes[id] = true
} }
@ -717,9 +717,9 @@ func renewUPnP(port int) {
func resetFolders() { func resetFolders() {
suffix := fmt.Sprintf(".syncthing-reset-%d", time.Now().UnixNano()) suffix := fmt.Sprintf(".syncthing-reset-%d", time.Now().UnixNano())
for _, folder := range cfg.Folders { for _, folder := range cfg.Folders {
if _, err := os.Stat(folder.Directory); err == nil { if _, err := os.Stat(folder.Path); err == nil {
l.Infof("Reset: Moving %s -> %s", folder.Directory, folder.Directory+suffix) l.Infof("Reset: Moving %s -> %s", folder.Path, folder.Path+suffix)
os.Rename(folder.Directory, folder.Directory+suffix) os.Rename(folder.Path, folder.Path+suffix)
} }
} }

View File

@ -107,7 +107,7 @@
</tr> </tr>
<tr> <tr>
<th><span class="glyphicon glyphicon-folder-open"></span>&emsp;<span translate>Folder</span></th> <th><span class="glyphicon glyphicon-folder-open"></span>&emsp;<span translate>Folder</span></th>
<td class="text-right">{{folder.Directory}}</td> <td class="text-right">{{folder.Path}}</td>
</tr> </tr>
<tr ng-if="model[folder.ID].invalid"> <tr ng-if="model[folder.ID].invalid">
<th><span class="glyphicon glyphicon-warning-sign"></span>&emsp;<span translate>Error</span></th> <th><span class="glyphicon glyphicon-warning-sign"></span>&emsp;<span translate>Error</span></th>
@ -569,7 +569,7 @@
</dl> </dl>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<div class="pull-left"><span translate>Editing</span> <code>{{currentFolder.Directory}}/.stignore</code></div> <div class="pull-left"><span translate>Editing</span> <code>{{currentFolder.Path}}/.stignore</code></div>
<button type="button" class="btn btn-primary btn-sm" data-dismiss="modal" ng-click="saveIgnores()"><span class="glyphicon glyphicon-ok"></span>&emsp;<span translate>Save</span></button> <button type="button" class="btn btn-primary btn-sm" data-dismiss="modal" ng-click="saveIgnores()"><span class="glyphicon glyphicon-ok"></span>&emsp;<span translate>Save</span></button>
<button type="button" class="btn btn-default btn-sm" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span>&emsp;<span translate>Close</span></button> <button type="button" class="btn btn-default btn-sm" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span>&emsp;<span translate>Close</span></button>
</div> </div>

View File

@ -34,7 +34,7 @@ type Configuration struct {
type FolderConfiguration struct { type FolderConfiguration struct {
ID string `xml:"id,attr"` ID string `xml:"id,attr"`
Directory string `xml:"directory,attr"` Path string `xml:"path,attr"`
Devices []FolderDeviceConfiguration `xml:"device"` Devices []FolderDeviceConfiguration `xml:"device"`
ReadOnly bool `xml:"ro,attr"` ReadOnly bool `xml:"ro,attr"`
RescanIntervalS int `xml:"rescanIntervalS,attr" default:"60"` RescanIntervalS int `xml:"rescanIntervalS,attr" default:"60"`
@ -306,7 +306,7 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) {
for i := range cfg.Folders { for i := range cfg.Folders {
folder := &cfg.Folders[i] folder := &cfg.Folders[i]
if len(folder.Directory) == 0 { if len(folder.Path) == 0 {
folder.Invalid = "no directory configured" folder.Invalid = "no directory configured"
continue continue
} }

View File

@ -56,7 +56,7 @@ func TestDeviceConfig(t *testing.T) {
expectedFolders := []FolderConfiguration{ expectedFolders := []FolderConfiguration{
{ {
ID: "test", ID: "test",
Directory: "~/Sync", Path: "~/Sync",
Devices: []FolderDeviceConfiguration{{DeviceID: device1}, {DeviceID: device4}}, Devices: []FolderDeviceConfiguration{{DeviceID: device1}, {DeviceID: device4}},
ReadOnly: true, ReadOnly: true,
RescanIntervalS: 600, RescanIntervalS: 600,

View File

@ -150,7 +150,7 @@ func (m *Model) StartFolderRW(folder string) {
p := Puller{ p := Puller{
folder: folder, folder: folder,
dir: cfg.Directory, dir: cfg.Path,
scanIntv: time.Duration(cfg.RescanIntervalS) * time.Second, scanIntv: time.Duration(cfg.RescanIntervalS) * time.Second,
model: m, model: m,
} }
@ -160,7 +160,7 @@ func (m *Model) StartFolderRW(folder string) {
if !ok { if !ok {
l.Fatalf("Requested versioning type %q that does not exist", cfg.Versioning.Type) l.Fatalf("Requested versioning type %q that does not exist", cfg.Versioning.Type)
} }
p.versioner = factory(folder, cfg.Directory, cfg.Versioning.Params) p.versioner = factory(folder, cfg.Path, cfg.Versioning.Params)
} }
go p.Serve() go p.Serve()
@ -623,7 +623,7 @@ func (m *Model) Request(deviceID protocol.DeviceID, folder, name string, offset
l.Debugf("%v REQ(in): %s: %q / %q o=%d s=%d", m, deviceID, folder, name, offset, size) l.Debugf("%v REQ(in): %s: %q / %q o=%d s=%d", m, deviceID, folder, name, offset, size)
} }
m.fmut.RLock() m.fmut.RLock()
fn := filepath.Join(m.folderCfgs[folder].Directory, name) fn := filepath.Join(m.folderCfgs[folder].Path, name)
m.fmut.RUnlock() m.fmut.RUnlock()
fd, err := os.Open(fn) // XXX: Inefficient, should cache fd? fd, err := os.Open(fn) // XXX: Inefficient, should cache fd?
if err != nil { if err != nil {
@ -693,7 +693,7 @@ func (m *Model) GetIgnores(folder string) ([]string, error) {
m.fmut.Lock() m.fmut.Lock()
defer m.fmut.Unlock() defer m.fmut.Unlock()
fd, err := os.Open(filepath.Join(cfg.Directory, ".stignore")) fd, err := os.Open(filepath.Join(cfg.Path, ".stignore"))
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return lines, nil return lines, nil
@ -717,7 +717,7 @@ func (m *Model) SetIgnores(folder string, content []string) error {
return fmt.Errorf("Folder %s does not exist", folder) return fmt.Errorf("Folder %s does not exist", folder)
} }
fd, err := ioutil.TempFile(cfg.Directory, ".syncthing.stignore-"+folder) fd, err := ioutil.TempFile(cfg.Path, ".syncthing.stignore-"+folder)
if err != nil { if err != nil {
l.Warnln("Saving .stignore:", err) l.Warnln("Saving .stignore:", err)
return err return err
@ -738,7 +738,7 @@ func (m *Model) SetIgnores(folder string, content []string) error {
return err return err
} }
file := filepath.Join(cfg.Directory, ".stignore") file := filepath.Join(cfg.Path, ".stignore")
err = osutil.Rename(fd.Name(), file) err = osutil.Rename(fd.Name(), file)
if err != nil { if err != nil {
l.Warnln("Saving .stignore:", err) l.Warnln("Saving .stignore:", err)
@ -963,7 +963,7 @@ func (m *Model) CleanFolders() {
m.fmut.RLock() m.fmut.RLock()
var dirs = make([]string, 0, len(m.folderCfgs)) var dirs = make([]string, 0, len(m.folderCfgs))
for _, cfg := range m.folderCfgs { for _, cfg := range m.folderCfgs {
dirs = append(dirs, cfg.Directory) dirs = append(dirs, cfg.Path)
} }
m.fmut.RUnlock() m.fmut.RUnlock()
@ -993,7 +993,7 @@ func (m *Model) ScanFolderSub(folder, sub string) error {
m.fmut.RLock() m.fmut.RLock()
fs, ok := m.folderFiles[folder] fs, ok := m.folderFiles[folder]
dir := m.folderCfgs[folder].Directory dir := m.folderCfgs[folder].Path
ignores, _ := ignore.Load(filepath.Join(dir, ".stignore")) ignores, _ := ignore.Load(filepath.Join(dir, ".stignore"))
m.folderIgnores[folder] = ignores m.folderIgnores[folder] = ignores

View File

@ -58,7 +58,7 @@ func init() {
func TestRequest(t *testing.T) { func TestRequest(t *testing.T) {
db, _ := leveldb.Open(storage.NewMemStorage(), nil) db, _ := leveldb.Open(storage.NewMemStorage(), nil)
m := NewModel("/tmp", &config.Configuration{}, "device", "syncthing", "dev", db) m := NewModel("/tmp", &config.Configuration{}, "device", "syncthing", "dev", db)
m.AddFolder(config.FolderConfiguration{ID: "default", Directory: "testdata"}) m.AddFolder(config.FolderConfiguration{ID: "default", Path: "testdata"})
m.ScanFolder("default") m.ScanFolder("default")
bs, err := m.Request(device1, "default", "foo", 0, 6) bs, err := m.Request(device1, "default", "foo", 0, 6)
@ -95,7 +95,7 @@ func genFiles(n int) []protocol.FileInfo {
func BenchmarkIndex10000(b *testing.B) { func BenchmarkIndex10000(b *testing.B) {
db, _ := leveldb.Open(storage.NewMemStorage(), nil) db, _ := leveldb.Open(storage.NewMemStorage(), nil)
m := NewModel("/tmp", nil, "device", "syncthing", "dev", db) m := NewModel("/tmp", nil, "device", "syncthing", "dev", db)
m.AddFolder(config.FolderConfiguration{ID: "default", Directory: "testdata"}) m.AddFolder(config.FolderConfiguration{ID: "default", Path: "testdata"})
m.ScanFolder("default") m.ScanFolder("default")
files := genFiles(10000) files := genFiles(10000)
@ -108,7 +108,7 @@ func BenchmarkIndex10000(b *testing.B) {
func BenchmarkIndex00100(b *testing.B) { func BenchmarkIndex00100(b *testing.B) {
db, _ := leveldb.Open(storage.NewMemStorage(), nil) db, _ := leveldb.Open(storage.NewMemStorage(), nil)
m := NewModel("/tmp", nil, "device", "syncthing", "dev", db) m := NewModel("/tmp", nil, "device", "syncthing", "dev", db)
m.AddFolder(config.FolderConfiguration{ID: "default", Directory: "testdata"}) m.AddFolder(config.FolderConfiguration{ID: "default", Path: "testdata"})
m.ScanFolder("default") m.ScanFolder("default")
files := genFiles(100) files := genFiles(100)
@ -121,7 +121,7 @@ func BenchmarkIndex00100(b *testing.B) {
func BenchmarkIndexUpdate10000f10000(b *testing.B) { func BenchmarkIndexUpdate10000f10000(b *testing.B) {
db, _ := leveldb.Open(storage.NewMemStorage(), nil) db, _ := leveldb.Open(storage.NewMemStorage(), nil)
m := NewModel("/tmp", nil, "device", "syncthing", "dev", db) m := NewModel("/tmp", nil, "device", "syncthing", "dev", db)
m.AddFolder(config.FolderConfiguration{ID: "default", Directory: "testdata"}) m.AddFolder(config.FolderConfiguration{ID: "default", Path: "testdata"})
m.ScanFolder("default") m.ScanFolder("default")
files := genFiles(10000) files := genFiles(10000)
m.Index(device1, "default", files) m.Index(device1, "default", files)
@ -135,7 +135,7 @@ func BenchmarkIndexUpdate10000f10000(b *testing.B) {
func BenchmarkIndexUpdate10000f00100(b *testing.B) { func BenchmarkIndexUpdate10000f00100(b *testing.B) {
db, _ := leveldb.Open(storage.NewMemStorage(), nil) db, _ := leveldb.Open(storage.NewMemStorage(), nil)
m := NewModel("/tmp", nil, "device", "syncthing", "dev", db) m := NewModel("/tmp", nil, "device", "syncthing", "dev", db)
m.AddFolder(config.FolderConfiguration{ID: "default", Directory: "testdata"}) m.AddFolder(config.FolderConfiguration{ID: "default", Path: "testdata"})
m.ScanFolder("default") m.ScanFolder("default")
files := genFiles(10000) files := genFiles(10000)
m.Index(device1, "default", files) m.Index(device1, "default", files)
@ -150,7 +150,7 @@ func BenchmarkIndexUpdate10000f00100(b *testing.B) {
func BenchmarkIndexUpdate10000f00001(b *testing.B) { func BenchmarkIndexUpdate10000f00001(b *testing.B) {
db, _ := leveldb.Open(storage.NewMemStorage(), nil) db, _ := leveldb.Open(storage.NewMemStorage(), nil)
m := NewModel("/tmp", nil, "device", "syncthing", "dev", db) m := NewModel("/tmp", nil, "device", "syncthing", "dev", db)
m.AddFolder(config.FolderConfiguration{ID: "default", Directory: "testdata"}) m.AddFolder(config.FolderConfiguration{ID: "default", Path: "testdata"})
m.ScanFolder("default") m.ScanFolder("default")
files := genFiles(10000) files := genFiles(10000)
m.Index(device1, "default", files) m.Index(device1, "default", files)
@ -208,7 +208,7 @@ func (FakeConnection) Statistics() protocol.Statistics {
func BenchmarkRequest(b *testing.B) { func BenchmarkRequest(b *testing.B) {
db, _ := leveldb.Open(storage.NewMemStorage(), nil) db, _ := leveldb.Open(storage.NewMemStorage(), nil)
m := NewModel("/tmp", nil, "device", "syncthing", "dev", db) m := NewModel("/tmp", nil, "device", "syncthing", "dev", db)
m.AddFolder(config.FolderConfiguration{ID: "default", Directory: "testdata"}) m.AddFolder(config.FolderConfiguration{ID: "default", Path: "testdata"})
m.ScanFolder("default") m.ScanFolder("default")
const n = 1000 const n = 1000
@ -380,7 +380,7 @@ func TestIgnores(t *testing.T) {
db, _ := leveldb.Open(storage.NewMemStorage(), nil) db, _ := leveldb.Open(storage.NewMemStorage(), nil)
m := NewModel("/tmp", nil, "device", "syncthing", "dev", db) m := NewModel("/tmp", nil, "device", "syncthing", "dev", db)
m.AddFolder(config.FolderConfiguration{ID: "default", Directory: "testdata"}) m.AddFolder(config.FolderConfiguration{ID: "default", Path: "testdata"})
expected := []string{ expected := []string{
".*", ".*",
@ -440,7 +440,7 @@ func TestIgnores(t *testing.T) {
t.Error("No error") t.Error("No error")
} }
m.AddFolder(config.FolderConfiguration{ID: "fresh", Directory: "XXX"}) m.AddFolder(config.FolderConfiguration{ID: "fresh", Path: "XXX"})
ignores, err = m.GetIgnores("fresh") ignores, err = m.GetIgnores("fresh")
if err != nil { if err != nil {
t.Error(err) t.Error(err)