Browse Source

Run go fmt -w

Audrius Butkevicius 11 years ago
parent
commit
26e4669316

+ 3 - 3
cmd/syncthing/main.go

@@ -353,12 +353,12 @@ func syncthingMain() {
 				ID:              "default",
 				Directory:       defaultFolder,
 				RescanIntervalS: 60,
-				Devices:           []config.FolderDeviceConfiguration{{DeviceID: myID}},
+				Devices:         []config.FolderDeviceConfiguration{{DeviceID: myID}},
 			},
 		}
 		cfg.Devices = []config.DeviceConfiguration{
 			{
-				DeviceID:    myID,
+				DeviceID:  myID,
 				Addresses: []string{"dynamic"},
 				Name:      myName,
 			},
@@ -856,7 +856,7 @@ next:
 		}
 
 		events.Default.Log(events.DeviceRejected, map[string]string{
-			"device":    remoteID.String(),
+			"device":  remoteID.String(),
 			"address": conn.RemoteAddr().String(),
 		})
 		l.Infof("Connection from %s with unknown device ID %s; ignoring", conn.RemoteAddr(), remoteID)

+ 23 - 23
internal/config/config.go

@@ -23,24 +23,24 @@ import (
 var l = logger.DefaultLogger
 
 type Configuration struct {
-	Location     string                    `xml:"-" json:"-"`
-	Version      int                       `xml:"version,attr" default:"3"`
-	Folders []FolderConfiguration `xml:"folder"`
-	Devices        []DeviceConfiguration       `xml:"device"`
-	GUI          GUIConfiguration          `xml:"gui"`
-	Options      OptionsConfiguration      `xml:"options"`
-	XMLName      xml.Name                  `xml:"configuration" json:"-"`
+	Location string                `xml:"-" json:"-"`
+	Version  int                   `xml:"version,attr" default:"3"`
+	Folders  []FolderConfiguration `xml:"folder"`
+	Devices  []DeviceConfiguration `xml:"device"`
+	GUI      GUIConfiguration      `xml:"gui"`
+	Options  OptionsConfiguration  `xml:"options"`
+	XMLName  xml.Name              `xml:"configuration" json:"-"`
 }
 
 type FolderConfiguration struct {
-	ID              string                        `xml:"id,attr"`
-	Directory       string                        `xml:"directory,attr"`
-	Devices           []FolderDeviceConfiguration `xml:"device"`
-	ReadOnly        bool                          `xml:"ro,attr"`
-	RescanIntervalS int                           `xml:"rescanIntervalS,attr" default:"60"`
-	IgnorePerms     bool                          `xml:"ignorePerms,attr"`
-	Invalid         string                        `xml:"-"` // Set at runtime when there is an error, not saved
-	Versioning      VersioningConfiguration       `xml:"versioning"`
+	ID              string                      `xml:"id,attr"`
+	Directory       string                      `xml:"directory,attr"`
+	Devices         []FolderDeviceConfiguration `xml:"device"`
+	ReadOnly        bool                        `xml:"ro,attr"`
+	RescanIntervalS int                         `xml:"rescanIntervalS,attr" default:"60"`
+	IgnorePerms     bool                        `xml:"ignorePerms,attr"`
+	Invalid         string                      `xml:"-"` // Set at runtime when there is an error, not saved
+	Versioning      VersioningConfiguration     `xml:"versioning"`
 
 	deviceIDs []protocol.DeviceID
 }
@@ -96,12 +96,12 @@ func (r *FolderConfiguration) DeviceIDs() []protocol.DeviceID {
 }
 
 type DeviceConfiguration struct {
-	DeviceID      protocol.DeviceID `xml:"id,attr"`
-	Name        string          `xml:"name,attr,omitempty"`
-	Addresses   []string        `xml:"address,omitempty"`
-	Compression bool            `xml:"compression,attr"`
-	CertName    string          `xml:"certName,attr,omitempty"`
-	Introducer  bool            `xml:"introducer,attr"`
+	DeviceID    protocol.DeviceID `xml:"id,attr"`
+	Name        string            `xml:"name,attr,omitempty"`
+	Addresses   []string          `xml:"address,omitempty"`
+	Compression bool              `xml:"compression,attr"`
+	CertName    string            `xml:"certName,attr,omitempty"`
+	Introducer  bool              `xml:"introducer,attr"`
 }
 
 type FolderDeviceConfiguration struct {
@@ -375,7 +375,7 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) {
 		myName, _ := os.Hostname()
 		cfg.Devices = append(cfg.Devices, DeviceConfiguration{
 			DeviceID: myID,
-			Name:   myName,
+			Name:     myName,
 		})
 	}
 	sort.Sort(DeviceConfigurationList(cfg.Devices))
@@ -527,7 +527,7 @@ func convertV1V2(cfg *Configuration) {
 	// Set and sort the list of devices.
 	for _, device := range devices {
 		cfg.Devices = append(cfg.Devices, DeviceConfiguration{
-			DeviceID:    device.DeviceID,
+			DeviceID:  device.DeviceID,
 			Name:      device.Deprecated_Name,
 			Addresses: device.Deprecated_Addresses,
 		})

+ 11 - 11
internal/config/config_test.go

@@ -57,20 +57,20 @@ func TestDeviceConfig(t *testing.T) {
 			{
 				ID:              "test",
 				Directory:       "~/Sync",
-				Devices:           []FolderDeviceConfiguration{{DeviceID: device1}, {DeviceID: device4}},
+				Devices:         []FolderDeviceConfiguration{{DeviceID: device1}, {DeviceID: device4}},
 				ReadOnly:        true,
 				RescanIntervalS: 600,
 			},
 		}
 		expectedDevices := []DeviceConfiguration{
 			{
-				DeviceID:      device1,
+				DeviceID:    device1,
 				Name:        "device one",
 				Addresses:   []string{"a"},
 				Compression: true,
 			},
 			{
-				DeviceID:      device4,
+				DeviceID:    device4,
 				Name:        "device two",
 				Addresses:   []string{"b"},
 				Compression: true,
@@ -144,22 +144,22 @@ func TestDeviceAddressesDynamic(t *testing.T) {
 	name, _ := os.Hostname()
 	expected := []DeviceConfiguration{
 		{
-			DeviceID:      device1,
+			DeviceID:    device1,
 			Addresses:   []string{"dynamic"},
 			Compression: true,
 		},
 		{
-			DeviceID:      device2,
+			DeviceID:    device2,
 			Addresses:   []string{"dynamic"},
 			Compression: true,
 		},
 		{
-			DeviceID:      device3,
+			DeviceID:    device3,
 			Addresses:   []string{"dynamic"},
 			Compression: true,
 		},
 		{
-			DeviceID:    device4,
+			DeviceID:  device4,
 			Name:      name, // Set when auto created
 			Addresses: []string{"dynamic"},
 		},
@@ -179,19 +179,19 @@ func TestDeviceAddressesStatic(t *testing.T) {
 	name, _ := os.Hostname()
 	expected := []DeviceConfiguration{
 		{
-			DeviceID:    device1,
+			DeviceID:  device1,
 			Addresses: []string{"192.0.2.1", "192.0.2.2"},
 		},
 		{
-			DeviceID:    device2,
+			DeviceID:  device2,
 			Addresses: []string{"192.0.2.3:6070", "[2001:db8::42]:4242"},
 		},
 		{
-			DeviceID:    device3,
+			DeviceID:  device3,
 			Addresses: []string{"[2001:db8::44]:4444", "192.0.2.4:6090"},
 		},
 		{
-			DeviceID:    device4,
+			DeviceID:  device4,
 			Name:      name, // Set when auto created
 			Addresses: []string{"dynamic"},
 		},

+ 2 - 2
internal/discover/discover.go

@@ -380,8 +380,8 @@ func (d *Discoverer) registerDevice(addr net.Addr, device Device) bool {
 			addrs[i] = current[i].addr
 		}
 		events.Default.Log(events.DeviceDiscovered, map[string]interface{}{
-			"device":  id.String(),
-			"addrs": addrs,
+			"device": id.String(),
+			"addrs":  addrs,
 		})
 	}
 

+ 1 - 1
internal/discover/packets.go

@@ -10,7 +10,7 @@ const (
 )
 
 type Query struct {
-	Magic  uint32
+	Magic    uint32
 	DeviceID []byte // max:32
 }
 

+ 3 - 3
internal/files/leveldb.go

@@ -41,7 +41,7 @@ const (
 
 type fileVersion struct {
 	version uint64
-	device    []byte
+	device  []byte
 }
 
 type versionList struct {
@@ -355,7 +355,7 @@ func ldbUpdateGlobal(db dbReader, batch dbWriter, folder, device, file []byte, v
 
 	var fl versionList
 	nv := fileVersion{
-		device:    device,
+		device:  device,
 		version: version,
 	}
 	if svl != nil {
@@ -455,7 +455,7 @@ func ldbWithHave(db *leveldb.DB, folder, device []byte, truncate bool, fn fileIt
 func ldbWithAllFolderTruncated(db *leveldb.DB, folder []byte, fn func(device []byte, f protocol.FileInfoTruncated) bool) {
 	runtime.GC()
 
-	start := deviceKey(folder, nil, nil)                                                // before all folder/device files
+	start := deviceKey(folder, nil, nil)                                                  // before all folder/device files
 	limit := deviceKey(folder, protocol.LocalDeviceID[:], []byte{0xff, 0xff, 0xff, 0xff}) // after all folder/device files
 	snap, err := db.GetSnapshot()
 	if err != nil {

+ 2 - 2
internal/files/set.go

@@ -29,14 +29,14 @@ type bitset uint64
 type Set struct {
 	localVersion map[protocol.DeviceID]uint64
 	mutex        sync.Mutex
-	folder         string
+	folder       string
 	db           *leveldb.DB
 }
 
 func NewSet(folder string, db *leveldb.DB) *Set {
 	var s = Set{
 		localVersion: make(map[protocol.DeviceID]uint64),
-		folder:         folder,
+		folder:       folder,
 		db:           db,
 	}
 

+ 30 - 30
internal/model/model.go

@@ -69,29 +69,29 @@ type Model struct {
 	cfg      *config.Configuration
 	db       *leveldb.DB
 
-	deviceName      string
+	deviceName    string
 	clientName    string
 	clientVersion string
 
-	folderCfgs     map[string]config.FolderConfiguration          // folder -> cfg
-	folderFiles    map[string]*files.Set                              // folder -> files
-	folderDevices    map[string][]protocol.DeviceID                       // folder -> deviceIDs
-	deviceFolders    map[protocol.DeviceID][]string                       // deviceID -> folders
+	folderCfgs     map[string]config.FolderConfiguration                  // folder -> cfg
+	folderFiles    map[string]*files.Set                                  // folder -> files
+	folderDevices  map[string][]protocol.DeviceID                         // folder -> deviceIDs
+	deviceFolders  map[protocol.DeviceID][]string                         // deviceID -> folders
 	deviceStatRefs map[protocol.DeviceID]*stats.DeviceStatisticsReference // deviceID -> statsRef
-	folderIgnores  map[string]ignore.Patterns                         // folder -> list of ignore patterns
-	rmut         sync.RWMutex                                       // protects the above
+	folderIgnores  map[string]ignore.Patterns                             // folder -> list of ignore patterns
+	rmut           sync.RWMutex                                           // protects the above
 
 	folderState        map[string]folderState // folder -> state
-	folderStateChanged map[string]time.Time // folder -> time when state changed
-	smut             sync.RWMutex
+	folderStateChanged map[string]time.Time   // folder -> time when state changed
+	smut               sync.RWMutex
 
 	protoConn map[protocol.DeviceID]protocol.Connection
 	rawConn   map[protocol.DeviceID]io.Closer
-	deviceVer   map[protocol.DeviceID]string
+	deviceVer map[protocol.DeviceID]string
 	pmut      sync.RWMutex // protects protoConn and rawConn
 
 	addedFolder bool
-	started   bool
+	started     bool
 }
 
 var (
@@ -104,22 +104,22 @@ var (
 // for file data without altering the local folder in any way.
 func NewModel(indexDir string, cfg *config.Configuration, deviceName, clientName, clientVersion string, db *leveldb.DB) *Model {
 	m := &Model{
-		indexDir:         indexDir,
-		cfg:              cfg,
-		db:               db,
+		indexDir:           indexDir,
+		cfg:                cfg,
+		db:                 db,
 		deviceName:         deviceName,
-		clientName:       clientName,
-		clientVersion:    clientVersion,
+		clientName:         clientName,
+		clientVersion:      clientVersion,
 		folderCfgs:         make(map[string]config.FolderConfiguration),
 		folderFiles:        make(map[string]*files.Set),
-		folderDevices:        make(map[string][]protocol.DeviceID),
-		deviceFolders:        make(map[protocol.DeviceID][]string),
+		folderDevices:      make(map[string][]protocol.DeviceID),
+		deviceFolders:      make(map[protocol.DeviceID][]string),
 		deviceStatRefs:     make(map[protocol.DeviceID]*stats.DeviceStatisticsReference),
 		folderIgnores:      make(map[string]ignore.Patterns),
 		folderState:        make(map[string]folderState),
 		folderStateChanged: make(map[string]time.Time),
-		protoConn:        make(map[protocol.DeviceID]protocol.Connection),
-		rawConn:          make(map[protocol.DeviceID]io.Closer),
+		protoConn:          make(map[protocol.DeviceID]protocol.Connection),
+		rawConn:            make(map[protocol.DeviceID]io.Closer),
 		deviceVer:          make(map[protocol.DeviceID]string),
 	}
 
@@ -149,7 +149,7 @@ func (m *Model) StartFolderRW(folder string) {
 	}
 
 	p := Puller{
-		folder:     folder,
+		folder:   folder,
 		dir:      cfg.Directory,
 		scanIntv: time.Duration(cfg.RescanIntervalS) * time.Second,
 		model:    m,
@@ -411,8 +411,8 @@ func (m *Model) Index(deviceID protocol.DeviceID, folder string, fs []protocol.F
 	files.Replace(deviceID, fs)
 
 	events.Default.Log(events.RemoteIndexUpdated, map[string]interface{}{
-		"device":    deviceID.String(),
-		"folder":    folder,
+		"device":  deviceID.String(),
+		"folder":  folder,
 		"items":   len(fs),
 		"version": files.LocalVersion(deviceID),
 	})
@@ -452,8 +452,8 @@ func (m *Model) IndexUpdate(deviceID protocol.DeviceID, folder string, fs []prot
 	files.Update(deviceID, fs)
 
 	events.Default.Log(events.RemoteIndexUpdated, map[string]interface{}{
-		"device":    deviceID.String(),
-		"folder":    folder,
+		"device":  deviceID.String(),
+		"folder":  folder,
 		"items":   len(fs),
 		"version": files.LocalVersion(deviceID),
 	})
@@ -890,7 +890,7 @@ func (m *Model) updateLocal(folder string, f protocol.FileInfo) {
 	m.folderFiles[folder].Update(protocol.LocalDeviceID, []protocol.FileInfo{f})
 	m.rmut.RUnlock()
 	events.Default.Log(events.LocalIndexUpdated, map[string]interface{}{
-		"folder":     folder,
+		"folder":   folder,
 		"name":     f.Name,
 		"modified": time.Unix(f.Modified, 0),
 		"flags":    fmt.Sprintf("0%o", f.Flags),
@@ -1022,7 +1022,7 @@ func (m *Model) ScanFolderSub(folder, sub string) error {
 	batch := make([]protocol.FileInfo, 0, 00)
 	for f := range fchan {
 		events.Default.Log(events.LocalIndexUpdated, map[string]interface{}{
-			"folder":     folder,
+			"folder":   folder,
 			"name":     f.Name,
 			"modified": time.Unix(f.Modified, 0),
 			"flags":    fmt.Sprintf("0%o", f.Flags),
@@ -1070,7 +1070,7 @@ func (m *Model) ScanFolderSub(folder, sub string) error {
 					Version:  f.Version, // The file is still the same, so don't bump version
 				}
 				events.Default.Log(events.LocalIndexUpdated, map[string]interface{}{
-					"folder":     folder,
+					"folder":   folder,
 					"name":     f.Name,
 					"modified": time.Unix(f.Modified, 0),
 					"flags":    fmt.Sprintf("0%o", f.Flags),
@@ -1086,7 +1086,7 @@ func (m *Model) ScanFolderSub(folder, sub string) error {
 					Version:  lamport.Default.Tick(f.Version),
 				}
 				events.Default.Log(events.LocalIndexUpdated, map[string]interface{}{
-					"folder":     folder,
+					"folder":   folder,
 					"name":     f.Name,
 					"modified": time.Unix(f.Modified, 0),
 					"flags":    fmt.Sprintf("0%o", f.Flags),
@@ -1153,7 +1153,7 @@ func (m *Model) setState(folder string, state folderState) {
 		m.folderStateChanged[folder] = time.Now()
 		eventData := map[string]interface{}{
 			"folder": folder,
-			"to":   state.String(),
+			"to":     state.String(),
 		}
 		if ok {
 			eventData["duration"] = time.Since(changed).Seconds()

+ 1 - 1
internal/model/model_test.go

@@ -287,7 +287,7 @@ func TestClusterConfig(t *testing.T) {
 	cfg := config.New("/tmp/test", device1)
 	cfg.Devices = []config.DeviceConfiguration{
 		{
-			DeviceID:     device1,
+			DeviceID:   device1,
 			Introducer: true,
 		},
 		{

+ 8 - 8
internal/model/puller.go

@@ -26,9 +26,9 @@ const (
 	copiersPerFolder   = 1
 	pullersPerFolder   = 16
 	finishersPerFolder = 2
-	pauseIntv        = 60 * time.Second
-	nextPullIntv     = 10 * time.Second
-	checkPullIntv    = 1 * time.Second
+	pauseIntv          = 60 * time.Second
+	nextPullIntv       = 10 * time.Second
+	checkPullIntv      = 1 * time.Second
 )
 
 // A pullBlockState is passed to the puller routine for each block that needs
@@ -46,12 +46,12 @@ type copyBlocksState struct {
 }
 
 var (
-	activity  = newDeviceActivity()
+	activity    = newDeviceActivity()
 	errNoDevice = errors.New("no available source device")
 )
 
 type Puller struct {
-	folder      string
+	folder    string
 	dir       string
 	scanIntv  time.Duration
 	model     *Model
@@ -129,7 +129,7 @@ loop:
 						// version that includes those files in curVer. So we
 						// catch the case that localVersion might have
 						// decresed here.
-						l.Debugln(p,"adjusting curVer",lv)
+						l.Debugln(p, "adjusting curVer", lv)
 						curVer = lv
 					}
 					prevVer = curVer
@@ -241,7 +241,7 @@ func (p *Puller) pullerIteration(ncopiers, npullers, nfinishers int) int {
 
 		events.Default.Log(events.ItemStarted, map[string]string{
 			"folder": p.folder,
-			"item": file.Name,
+			"item":   file.Name,
 		})
 
 		if debug {
@@ -384,7 +384,7 @@ func (p *Puller) handleFile(file protocol.FileInfo, copyChan chan<- copyBlocksSt
 
 	s := sharedPullerState{
 		file:       file,
-		folder:       p.folder,
+		folder:     p.folder,
 		tempName:   tempName,
 		realName:   realName,
 		pullNeeded: len(pullBlocks),

+ 1 - 1
internal/model/sharedpullerstate.go

@@ -17,7 +17,7 @@ import (
 type sharedPullerState struct {
 	// Immutable, does not require locking
 	file     protocol.FileInfo
-	folder     string
+	folder   string
 	tempName string
 	realName string
 

+ 1 - 1
internal/protocol/common_test.go

@@ -11,7 +11,7 @@ import (
 
 type TestModel struct {
 	data     []byte
-	folder     string
+	folder   string
 	name     string
 	offset   int64
 	size     int

+ 9 - 9
internal/protocol/message.go

@@ -8,7 +8,7 @@ import "fmt"
 
 type IndexMessage struct {
 	Folder string // max:64
-	Files      []FileInfo
+	Files  []FileInfo
 }
 
 type FileInfo struct {
@@ -91,9 +91,9 @@ func (b BlockInfo) String() string {
 
 type RequestMessage struct {
 	Folder string // max:64
-	Name       string // max:8192
-	Offset     uint64
-	Size       uint32
+	Name   string // max:8192
+	Offset uint64
+	Size   uint32
 }
 
 type ResponseMessage struct {
@@ -101,10 +101,10 @@ type ResponseMessage struct {
 }
 
 type ClusterConfigMessage struct {
-	ClientName    string       // max:64
-	ClientVersion string       // max:64
-	Folders  []Folder // max:64
-	Options       []Option     // max:64
+	ClientName    string   // max:64
+	ClientVersion string   // max:64
+	Folders       []Folder // max:64
+	Options       []Option // max:64
 }
 
 func (o *ClusterConfigMessage) GetOption(key string) string {
@@ -117,7 +117,7 @@ func (o *ClusterConfigMessage) GetOption(key string) string {
 }
 
 type Folder struct {
-	ID    string // max:64
+	ID      string   // max:64
 	Devices []Device // max:64
 }
 

+ 2 - 2
internal/stats/device.go

@@ -24,13 +24,13 @@ type DeviceStatistics struct {
 }
 
 type DeviceStatisticsReference struct {
-	db   *leveldb.DB
+	db     *leveldb.DB
 	device protocol.DeviceID
 }
 
 func NewDeviceStatisticsReference(db *leveldb.DB, device protocol.DeviceID) *DeviceStatisticsReference {
 	return &DeviceStatisticsReference{
-		db:   db,
+		db:     db,
 		device: device,
 	}
 }

+ 2 - 2
internal/versioner/simple.go

@@ -20,7 +20,7 @@ func init() {
 
 // The type holds our configuration
 type Simple struct {
-	keep     int
+	keep       int
 	folderPath string
 }
 
@@ -32,7 +32,7 @@ func NewSimple(folderID, folderPath string, params map[string]string) Versioner
 	}
 
 	s := Simple{
-		keep:     keep,
+		keep:       keep,
 		folderPath: folderPath,
 	}
 

+ 2 - 2
internal/versioner/staggered.go

@@ -30,7 +30,7 @@ type Interval struct {
 type Staggered struct {
 	versionsPath  string
 	cleanInterval int64
-	folderPath      string
+	folderPath    string
 	interval      [4]Interval
 	mutex         *sync.Mutex
 }
@@ -111,7 +111,7 @@ func NewStaggered(folderID, folderPath string, params map[string]string) Version
 	s := Staggered{
 		versionsPath:  versionsDir,
 		cleanInterval: cleanInterval,
-		folderPath:      folderPath,
+		folderPath:    folderPath,
 		interval: [4]Interval{
 			Interval{30, 3600},               // first hour -> 30 sec between versions
 			Interval{3600, 86400},            // next day -> 1 h between versions