keep existing repo_type on explicit empty PUT; repair wiped locals as local
This commit is contained in:
@@ -135,13 +135,15 @@ func (h *RemotesHandler) update(w http.ResponseWriter, r *http.Request) {
|
||||
if oldKnown {
|
||||
remote.MutableTTL = existing.MutableTTL
|
||||
remote.QuarantineDays = existing.QuarantineDays
|
||||
remote.RepoType = existing.RepoType
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&remote); err != nil {
|
||||
http.Error(w, "invalid json", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
remote.Name = name
|
||||
if remote.RepoType == "" && oldKnown {
|
||||
remote.RepoType = existing.RepoType
|
||||
}
|
||||
if remote.RepoType == "" {
|
||||
remote.RepoType = models.RepoTypeRemote
|
||||
}
|
||||
|
||||
@@ -201,6 +201,7 @@ func TestRepoTypeKeptOnUpdate(t *testing.T) {
|
||||
{"PUT", "/rt-remote", `{` + body + `}`, 200, "rt-remote", "remote"},
|
||||
{"POST", "/", `{"name":"rt-local","package_type":"rpm","repo_type":"local"}`, 201, "rt-local", "local"},
|
||||
{"PUT", "/rt-local", `{"package_type":"rpm","description":"x"}`, 200, "rt-local", "local"},
|
||||
{"PUT", "/rt-local", `{"package_type":"rpm","repo_type":""}`, 200, "rt-local", "local"},
|
||||
{"PUT", "/rt-local", `{"package_type":"rpm","repo_type":"bogus"}`, 400, "rt-local", "local"},
|
||||
} {
|
||||
if c := do(t, h, s.method, s.path, s.json); c != s.code {
|
||||
|
||||
@@ -1 +1 @@
|
||||
UPDATE remotes SET repo_type = 'remote' WHERE repo_type = '' OR repo_type IS NULL;
|
||||
UPDATE remotes SET repo_type = CASE WHEN COALESCE(base_url, '') = '' THEN 'local' ELSE 'remote' END WHERE repo_type = '' OR repo_type IS NULL;
|
||||
|
||||
Reference in New Issue
Block a user