From e4d08b336e56f4f430b76410aebb1e93f1cdf880 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 23 Jun 2026 07:57:36 +0200 Subject: [PATCH] fix(config): remove extraneous defaults setting while unmarshalling folder options (fixes #10746, fixes #10389) (#10763) This broke PATCH on folders. Any place that needs the defaults should set them prior to unmarshal. Signed-off-by: Jakob Borg --- lib/api/api_test.go | 12 +++++++++--- lib/config/folderconfiguration.go | 11 ----------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/api/api_test.go b/lib/api/api_test.go index 2637f2395..bc6a27098 100644 --- a/lib/api/api_test.go +++ b/lib/api/api_test.go @@ -1762,9 +1762,10 @@ func TestConfigChanges(t *testing.T) { folder2Path := "/rest/config/folders/folder2" - // Create a folder and add another + // Create a folder and add another. Give folder2 a non-default + // RescanIntervalS so we can verify it survives a later partial PATCH. mod(http.MethodPut, "/rest/config/folders", []config.FolderConfiguration{{ID: "folder1", Path: "folder1"}}) - mod(http.MethodPut, folder2Path, config.FolderConfiguration{ID: "folder2", Path: "folder2"}) + mod(http.MethodPut, folder2Path, config.FolderConfiguration{ID: "folder2", Path: "folder2", RescanIntervalS: 1234}) // Check they are there get("/rest/config/folders/folder1").Body.Close() @@ -1779,9 +1780,14 @@ func TestConfigChanges(t *testing.T) { if err := unmarshalTo(resp.Body, &folder); err != nil { t.Fatal(err) } - if !dev.Paused { + if !folder.Paused { t.Error("Expected folder to be paused") } + // A partial PATCH must not reset other (default-tagged) attributes to + // their default values. + if folder.RescanIntervalS != 1234 { + t.Error("Expected RescanIntervalS to be preserved as 1234, got", folder.RescanIntervalS) + } // Delete folder2 req, _ := http.NewRequest(http.MethodDelete, baseURL+folder2Path, nil) diff --git a/lib/config/folderconfiguration.go b/lib/config/folderconfiguration.go index a2ed4e5ae..58c244e42 100644 --- a/lib/config/folderconfiguration.go +++ b/lib/config/folderconfiguration.go @@ -9,7 +9,6 @@ package config import ( "bytes" "crypto/sha256" - "encoding/json" "encoding/xml" "errors" "fmt" @@ -395,16 +394,6 @@ func (f XattrFilter) GetMaxTotalSize() int { 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)