Skip to content

Commit 4b8b214

Browse files
authored
Create doctor command to fix repo_units broken by dumps from 1.14.3-1.14.6 (#17136) (#17137)
Backport #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 <[email protected]>
1 parent ebae7e1 commit 4b8b214

File tree

4 files changed

+607
-13
lines changed

4 files changed

+607
-13
lines changed

models/login_source.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ var (
7171
_ convert.Conversion = &SSPIConfig{}
7272
)
7373

74-
// jsonUnmarshalHandleDoubleEncode - due to a bug in xorm (see https://gitea.com/xorm/xorm/pulls/1957) - it's
74+
// JSONUnmarshalHandleDoubleEncode - due to a bug in xorm (see https://gitea.com/xorm/xorm/pulls/1957) - it's
7575
// possible that a Blob may be double encoded or gain an unwanted prefix of 0xff 0xfe.
76-
func jsonUnmarshalHandleDoubleEncode(bs []byte, v interface{}) error {
76+
func JSONUnmarshalHandleDoubleEncode(bs []byte, v interface{}) error {
7777
json := jsoniter.ConfigCompatibleWithStandardLibrary
7878
err := json.Unmarshal(bs, v)
7979
if err != nil {
@@ -89,7 +89,7 @@ func jsonUnmarshalHandleDoubleEncode(bs []byte, v interface{}) error {
8989
rs = append(rs, temp...)
9090
}
9191
if ok {
92-
if rs[0] == 0xff && rs[1] == 0xfe {
92+
if len(rs) > 1 && rs[0] == 0xff && rs[1] == 0xfe {
9393
rs = rs[2:]
9494
}
9595
err = json.Unmarshal(rs, v)
@@ -108,7 +108,7 @@ type LDAPConfig struct {
108108

109109
// FromDB fills up a LDAPConfig from serialized format.
110110
func (cfg *LDAPConfig) FromDB(bs []byte) error {
111-
err := jsonUnmarshalHandleDoubleEncode(bs, &cfg)
111+
err := JSONUnmarshalHandleDoubleEncode(bs, &cfg)
112112
if err != nil {
113113
return err
114114
}
@@ -149,7 +149,7 @@ type SMTPConfig struct {
149149

150150
// FromDB fills up an SMTPConfig from serialized format.
151151
func (cfg *SMTPConfig) FromDB(bs []byte) error {
152-
return jsonUnmarshalHandleDoubleEncode(bs, cfg)
152+
return JSONUnmarshalHandleDoubleEncode(bs, cfg)
153153
}
154154

155155
// ToDB exports an SMTPConfig to a serialized format.
@@ -166,7 +166,7 @@ type PAMConfig struct {
166166

167167
// FromDB fills up a PAMConfig from serialized format.
168168
func (cfg *PAMConfig) FromDB(bs []byte) error {
169-
return jsonUnmarshalHandleDoubleEncode(bs, cfg)
169+
return JSONUnmarshalHandleDoubleEncode(bs, cfg)
170170
}
171171

172172
// ToDB exports a PAMConfig to a serialized format.
@@ -187,7 +187,7 @@ type OAuth2Config struct {
187187

188188
// FromDB fills up an OAuth2Config from serialized format.
189189
func (cfg *OAuth2Config) FromDB(bs []byte) error {
190-
return jsonUnmarshalHandleDoubleEncode(bs, cfg)
190+
return JSONUnmarshalHandleDoubleEncode(bs, cfg)
191191
}
192192

193193
// ToDB exports an SMTPConfig to a serialized format.
@@ -207,7 +207,7 @@ type SSPIConfig struct {
207207

208208
// FromDB fills up an SSPIConfig from serialized format.
209209
func (cfg *SSPIConfig) FromDB(bs []byte) error {
210-
return jsonUnmarshalHandleDoubleEncode(bs, cfg)
210+
return JSONUnmarshalHandleDoubleEncode(bs, cfg)
211211
}
212212

213213
// ToDB exports an SSPIConfig to a serialized format.

models/repo_unit.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type UnitConfig struct{}
2828

2929
// FromDB fills up a UnitConfig from serialized format.
3030
func (cfg *UnitConfig) FromDB(bs []byte) error {
31-
return jsonUnmarshalHandleDoubleEncode(bs, &cfg)
31+
return JSONUnmarshalHandleDoubleEncode(bs, &cfg)
3232
}
3333

3434
// ToDB exports a UnitConfig to a serialized format.
@@ -44,7 +44,7 @@ type ExternalWikiConfig struct {
4444

4545
// FromDB fills up a ExternalWikiConfig from serialized format.
4646
func (cfg *ExternalWikiConfig) FromDB(bs []byte) error {
47-
return jsonUnmarshalHandleDoubleEncode(bs, &cfg)
47+
return JSONUnmarshalHandleDoubleEncode(bs, &cfg)
4848
}
4949

5050
// ToDB exports a ExternalWikiConfig to a serialized format.
@@ -62,7 +62,7 @@ type ExternalTrackerConfig struct {
6262

6363
// FromDB fills up a ExternalTrackerConfig from serialized format.
6464
func (cfg *ExternalTrackerConfig) FromDB(bs []byte) error {
65-
return jsonUnmarshalHandleDoubleEncode(bs, &cfg)
65+
return JSONUnmarshalHandleDoubleEncode(bs, &cfg)
6666
}
6767

6868
// ToDB exports a ExternalTrackerConfig to a serialized format.
@@ -80,7 +80,7 @@ type IssuesConfig struct {
8080

8181
// FromDB fills up a IssuesConfig from serialized format.
8282
func (cfg *IssuesConfig) FromDB(bs []byte) error {
83-
return jsonUnmarshalHandleDoubleEncode(bs, &cfg)
83+
return JSONUnmarshalHandleDoubleEncode(bs, &cfg)
8484
}
8585

8686
// ToDB exports a IssuesConfig to a serialized format.
@@ -104,7 +104,7 @@ type PullRequestsConfig struct {
104104

105105
// FromDB fills up a PullRequestsConfig from serialized format.
106106
func (cfg *PullRequestsConfig) FromDB(bs []byte) error {
107-
return jsonUnmarshalHandleDoubleEncode(bs, &cfg)
107+
return JSONUnmarshalHandleDoubleEncode(bs, &cfg)
108108
}
109109

110110
// ToDB exports a PullRequestsConfig to a serialized format.
@@ -219,3 +219,9 @@ func getUnitsByRepoID(e Engine, repoID int64) (units []*RepoUnit, err error) {
219219

220220
return units, nil
221221
}
222+
223+
// UpdateRepoUnit updates the provided repo unit
224+
func UpdateRepoUnit(unit *RepoUnit) error {
225+
_, err := x.ID(unit.ID).Update(unit)
226+
return err
227+
}

0 commit comments

Comments
 (0)