Skip to content

Commit 192faa6

Browse files
committed
Fix a bug where lfs gc never worked.
1 parent e7d6f74 commit 192faa6

File tree

2 files changed

+69
-16
lines changed

2 files changed

+69
-16
lines changed

modules/setting/cron_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,56 @@ EXTEND = true
4141
assert.Equal(t, "white rabbit", extended.Second)
4242
assert.True(t, extended.Extend)
4343
}
44+
45+
// Test_getCronSettings2 tests that getCronSettings can not handle two levels of embedding
46+
func Test_getCronSettings2(t *testing.T) {
47+
type BaseStruct struct {
48+
Enabled bool
49+
RunAtStart bool
50+
Schedule string
51+
}
52+
53+
type Extended struct {
54+
BaseStruct
55+
Extend bool
56+
}
57+
type Extended2 struct {
58+
Extended
59+
Third string
60+
}
61+
62+
iniStr := `
63+
[cron.test]
64+
ENABLED = TRUE
65+
RUN_AT_START = TRUE
66+
SCHEDULE = @every 1h
67+
EXTEND = true
68+
THIRD = white rabbit
69+
`
70+
cfg, err := NewConfigProviderFromData(iniStr)
71+
assert.NoError(t, err)
72+
73+
extended := &Extended2{
74+
Extended: Extended{
75+
BaseStruct: BaseStruct{
76+
Enabled: false,
77+
RunAtStart: false,
78+
Schedule: "@every 72h",
79+
},
80+
Extend: false,
81+
},
82+
Third: "black rabbit",
83+
}
84+
85+
_, err = getCronSettings(cfg, "test", extended)
86+
assert.NoError(t, err)
87+
88+
// This confirms the first level of embedding works
89+
assert.Equal(t, "white rabbit", extended.Third)
90+
assert.True(t, extended.Extend)
91+
92+
// This confirms 2 levels of embedding doesn't work
93+
assert.False(t, extended.Enabled)
94+
assert.False(t, extended.RunAtStart)
95+
assert.Equal(t, "@every 72h", extended.Schedule)
96+
}

services/cron/tasks_extended.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,29 +176,29 @@ func registerGCLFS() {
176176
return
177177
}
178178
type GCLFSConfig struct {
179-
OlderThanConfig
179+
BaseConfig
180+
OlderThan time.Duration
180181
LastUpdatedMoreThanAgo time.Duration
181182
NumberToCheckPerRepo int64
182183
ProportionToCheckPerRepo float64
183184
}
184185

185186
RegisterTaskFatal("gc_lfs", &GCLFSConfig{
186-
OlderThanConfig: OlderThanConfig{
187-
BaseConfig: BaseConfig{
188-
Enabled: false,
189-
RunAtStart: false,
190-
Schedule: "@every 24h",
191-
},
192-
// Only attempt to garbage collect lfs meta objects older than a week as the order of git lfs upload
193-
// and git object upload is not necessarily guaranteed. It's possible to imagine a situation whereby
194-
// an LFS object is uploaded but the git branch is not uploaded immediately, or there are some rapid
195-
// changes in new branches that might lead to lfs objects becoming temporarily unassociated with git
196-
// objects.
197-
//
198-
// It is likely that a week is potentially excessive but it should definitely be enough that any
199-
// unassociated LFS object is genuinely unassociated.
200-
OlderThan: 24 * time.Hour * 7,
187+
BaseConfig: BaseConfig{
188+
Enabled: false,
189+
RunAtStart: false,
190+
Schedule: "@every 24h",
201191
},
192+
// Only attempt to garbage collect lfs meta objects older than a week as the order of git lfs upload
193+
// and git object upload is not necessarily guaranteed. It's possible to imagine a situation whereby
194+
// an LFS object is uploaded but the git branch is not uploaded immediately, or there are some rapid
195+
// changes in new branches that might lead to lfs objects becoming temporarily unassociated with git
196+
// objects.
197+
//
198+
// It is likely that a week is potentially excessive but it should definitely be enough that any
199+
// unassociated LFS object is genuinely unassociated.
200+
OlderThan: 24 * time.Hour * 7,
201+
202202
// Only GC things that haven't been looked at in the past 3 days
203203
LastUpdatedMoreThanAgo: 24 * time.Hour * 3,
204204
NumberToCheckPerRepo: 100,

0 commit comments

Comments
 (0)