Przeglądaj źródła

Merge branch 'main' into v2

* main:
  fix(config): properly apply defaults when reading folder configuration (#10034)
  chore(model): add metric for total number of conflicts (#10037)
  build: replace underscore in Debian version (#10032)
Jakob Borg 6 miesięcy temu
rodzic
commit
7d51b1b620

+ 3 - 0
build.go

@@ -628,6 +628,9 @@ func buildDeb(target target) {
 		// than just 0.14.26. This rectifies that.
 		// than just 0.14.26. This rectifies that.
 		debver = strings.Replace(debver, "-", "~", -1)
 		debver = strings.Replace(debver, "-", "~", -1)
 	}
 	}
+	if strings.Contains(debver, "_") {
+		debver = strings.Replace(debver, "_", "~", -1)
+	}
 	args := []string{
 	args := []string{
 		"-t", "deb",
 		"-t", "deb",
 		"-s", "dir",
 		"-s", "dir",

+ 8 - 4
lib/config/config_test.go

@@ -101,7 +101,7 @@ func TestDefaultValues(t *testing.T) {
 		Defaults: Defaults{
 		Defaults: Defaults{
 			Folder: FolderConfiguration{
 			Folder: FolderConfiguration{
 				FilesystemType:   FilesystemTypeBasic,
 				FilesystemType:   FilesystemTypeBasic,
-				Path:             "~",
+				Path:             "",
 				Type:             FolderTypeSendReceive,
 				Type:             FolderTypeSendReceive,
 				Devices:          []FolderDeviceConfiguration{{DeviceID: device1}},
 				Devices:          []FolderDeviceConfiguration{{DeviceID: device1}},
 				RescanIntervalS:  3600,
 				RescanIntervalS:  3600,
@@ -180,7 +180,7 @@ func TestDeviceConfig(t *testing.T) {
 				Devices:          []FolderDeviceConfiguration{{DeviceID: device1}, {DeviceID: device4}},
 				Devices:          []FolderDeviceConfiguration{{DeviceID: device1}, {DeviceID: device4}},
 				Type:             FolderTypeSendOnly,
 				Type:             FolderTypeSendOnly,
 				RescanIntervalS:  600,
 				RescanIntervalS:  600,
-				FSWatcherEnabled: false,
+				FSWatcherEnabled: true,
 				FSWatcherDelayS:  10,
 				FSWatcherDelayS:  10,
 				Copiers:          0,
 				Copiers:          0,
 				Hashers:          0,
 				Hashers:          0,
@@ -188,13 +188,17 @@ func TestDeviceConfig(t *testing.T) {
 				MinDiskFree:      Size{1, "%"},
 				MinDiskFree:      Size{1, "%"},
 				MaxConflicts:     -1,
 				MaxConflicts:     -1,
 				Versioning: VersioningConfiguration{
 				Versioning: VersioningConfiguration{
-					Params: map[string]string{},
+					CleanupIntervalS: 3600,
+					FSType:           FilesystemTypeBasic,
+					Params:           map[string]string{},
 				},
 				},
 				MarkerName:          DefaultMarkerName,
 				MarkerName:          DefaultMarkerName,
 				JunctionsAsDirs:     true,
 				JunctionsAsDirs:     true,
 				MaxConcurrentWrites: maxConcurrentWritesDefault,
 				MaxConcurrentWrites: maxConcurrentWritesDefault,
 				XattrFilter: XattrFilter{
 				XattrFilter: XattrFilter{
-					Entries: []XattrFilterEntry{},
+					MaxSingleEntrySize: 1024,
+					MaxTotalSize:       4096,
+					Entries:            []XattrFilterEntry{},
 				},
 				},
 			},
 			},
 		}
 		}

+ 24 - 1
lib/config/folderconfiguration.go

@@ -9,6 +9,8 @@ package config
 import (
 import (
 	"bytes"
 	"bytes"
 	"crypto/sha256"
 	"crypto/sha256"
+	"encoding/json"
+	"encoding/xml"
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
 	"path"
 	"path"
@@ -22,6 +24,7 @@ import (
 	"github.com/syncthing/syncthing/lib/build"
 	"github.com/syncthing/syncthing/lib/build"
 	"github.com/syncthing/syncthing/lib/fs"
 	"github.com/syncthing/syncthing/lib/fs"
 	"github.com/syncthing/syncthing/lib/protocol"
 	"github.com/syncthing/syncthing/lib/protocol"
+	"github.com/syncthing/syncthing/lib/structutil"
 )
 )
 
 
 var (
 var (
@@ -47,7 +50,7 @@ type FolderConfiguration struct {
 	ID                      string                      `json:"id" xml:"id,attr" nodefault:"true"`
 	ID                      string                      `json:"id" xml:"id,attr" nodefault:"true"`
 	Label                   string                      `json:"label" xml:"label,attr" restart:"false"`
 	Label                   string                      `json:"label" xml:"label,attr" restart:"false"`
 	FilesystemType          FilesystemType              `json:"filesystemType" xml:"filesystemType" default:"basic"`
 	FilesystemType          FilesystemType              `json:"filesystemType" xml:"filesystemType" default:"basic"`
-	Path                    string                      `json:"path" xml:"path,attr" default:"~"`
+	Path                    string                      `json:"path" xml:"path,attr"`
 	Type                    FolderType                  `json:"type" xml:"type,attr"`
 	Type                    FolderType                  `json:"type" xml:"type,attr"`
 	Devices                 []FolderDeviceConfiguration `json:"devices" xml:"device"`
 	Devices                 []FolderDeviceConfiguration `json:"devices" xml:"device"`
 	RescanIntervalS         int                         `json:"rescanIntervalS" xml:"rescanIntervalS,attr" default:"3600"`
 	RescanIntervalS         int                         `json:"rescanIntervalS" xml:"rescanIntervalS,attr" default:"3600"`
@@ -391,3 +394,23 @@ func (f XattrFilter) GetMaxSingleEntrySize() int {
 func (f XattrFilter) GetMaxTotalSize() int {
 func (f XattrFilter) GetMaxTotalSize() int {
 	return f.MaxTotalSize
 	return f.MaxTotalSize
 }
 }
+
+func (f *FolderConfiguration) UnmarshalJSON(data []byte) error {
+	structutil.SetDefaults(f)
+
+	// avoid recursing into this method
+	type noCustomUnmarshal FolderConfiguration
+	ptr := (*noCustomUnmarshal)(f)
+
+	return json.Unmarshal(data, ptr)
+}
+
+func (f *FolderConfiguration) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
+	structutil.SetDefaults(f)
+
+	// avoid recursing into this method
+	type noCustomUnmarshal FolderConfiguration
+	ptr := (*noCustomUnmarshal)(f)
+
+	return d.DecodeElement(ptr, &start)
+}

+ 1 - 0
lib/model/folder_sendrecv.go

@@ -1809,6 +1809,7 @@ func (f *sendReceiveFolder) moveForConflict(name, lastModBy string, scanChan cha
 		return nil
 		return nil
 	}
 	}
 
 
+	metricFolderConflictsTotal.WithLabelValues(f.ID).Inc()
 	newName := conflictName(name, lastModBy)
 	newName := conflictName(name, lastModBy)
 	err := f.mtimefs.Rename(name, newName)
 	err := f.mtimefs.Rename(name, newName)
 	if fs.IsNotExist(err) {
 	if fs.IsNotExist(err) {

+ 8 - 0
lib/model/metrics.go

@@ -57,6 +57,13 @@ var (
 		Name:      "folder_processed_bytes_total",
 		Name:      "folder_processed_bytes_total",
 		Help:      "Total amount of data processed during folder syncing, per folder ID and data source (network/local_origin/local_other/skipped)",
 		Help:      "Total amount of data processed during folder syncing, per folder ID and data source (network/local_origin/local_other/skipped)",
 	}, []string{"folder", "source"})
 	}, []string{"folder", "source"})
+
+	metricFolderConflictsTotal = promauto.NewCounterVec(prometheus.CounterOpts{
+		Namespace: "syncthing",
+		Subsystem: "model",
+		Name:      "folder_conflicts_total",
+		Help:      "Total number of conflicts",
+	}, []string{"folder"})
 )
 )
 
 
 const (
 const (
@@ -88,4 +95,5 @@ func registerFolderMetrics(folderID string) {
 	metricFolderProcessedBytesTotal.WithLabelValues(folderID, metricSourceLocalOrigin)
 	metricFolderProcessedBytesTotal.WithLabelValues(folderID, metricSourceLocalOrigin)
 	metricFolderProcessedBytesTotal.WithLabelValues(folderID, metricSourceLocalOther)
 	metricFolderProcessedBytesTotal.WithLabelValues(folderID, metricSourceLocalOther)
 	metricFolderProcessedBytesTotal.WithLabelValues(folderID, metricSourceSkipped)
 	metricFolderProcessedBytesTotal.WithLabelValues(folderID, metricSourceSkipped)
+	metricFolderConflictsTotal.WithLabelValues(folderID)
 }
 }