summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-09-27 16:55:12 +0100
committerGitHub <noreply@github.com>2021-09-27 16:55:12 +0100
commitb5856c443729c6825618595a0e746202553aa95c (patch)
treedf1689a9f1986eef8738c0316ae16a4703a848f4 /models
parent4e0cca3f7d9dd227df161e3548cc374c169d3dc6 (diff)
downloadgitea-b5856c443729c6825618595a0e746202553aa95c.tar.gz
gitea-b5856c443729c6825618595a0e746202553aa95c.zip
Create doctor command to fix repo_units broken by dumps from 1.14.3-1.14.6 (#17136)
There was a serious issue with the `gitea dump` command in 1.14.3-1.14.6 which led to corruption of the `config` field of the `repo_unit` table. This PR adds a doctor command to attempt to fix the broken repo_units. Users affected by #16961 should run: ``` gitea doctor --fix --run fix-broken-repo-units ``` Fix #16961 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'models')
-rw-r--r--models/helper.go2
-rw-r--r--models/repo_unit.go6
2 files changed, 7 insertions, 1 deletions
diff --git a/models/helper.go b/models/helper.go
index c499b5512d..710c15a978 100644
--- a/models/helper.go
+++ b/models/helper.go
@@ -51,7 +51,7 @@ func JSONUnmarshalHandleDoubleEncode(bs []byte, v interface{}) error {
rs = append(rs, temp...)
}
if ok {
- if rs[0] == 0xff && rs[1] == 0xfe {
+ if len(rs) > 1 && rs[0] == 0xff && rs[1] == 0xfe {
rs = rs[2:]
}
err = json.Unmarshal(rs, v)
diff --git a/models/repo_unit.go b/models/repo_unit.go
index 7061119bd8..474f65bf03 100644
--- a/models/repo_unit.go
+++ b/models/repo_unit.go
@@ -220,3 +220,9 @@ func getUnitsByRepoID(e db.Engine, repoID int64) (units []*RepoUnit, err error)
return units, nil
}
+
+// UpdateRepoUnit updates the provided repo unit
+func UpdateRepoUnit(unit *RepoUnit) error {
+ _, err := db.GetEngine(db.DefaultContext).ID(unit.ID).Update(unit)
+ return err
+}