This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree 2 files changed +19
-1
lines changed
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,11 @@ func (c *ObjectLRU) Put(obj plumbing.EncodedObject) {
61
61
c .actualSize += objSize
62
62
for c .actualSize > c .MaxSize {
63
63
last := c .ll .Back ()
64
+ if last == nil {
65
+ c .actualSize = 0
66
+ break
67
+ }
68
+
64
69
lastObj := last .Value .(plumbing.EncodedObject )
65
70
lastSize := FileSize (lastObj .Size ())
66
71
Original file line number Diff line number Diff line change @@ -153,6 +153,19 @@ func (s *ObjectSuite) TestDefaultLRU(c *C) {
153
153
c .Assert (defaultLRU .MaxSize , Equals , DefaultMaxSize )
154
154
}
155
155
156
+ func (s * ObjectSuite ) TestObjectUpdateOverflow (c * C ) {
157
+ o := NewObjectLRU (9 * Byte )
158
+
159
+ a1 := newObject (s .aObject .Hash ().String (), 9 * Byte )
160
+ a2 := newObject (s .aObject .Hash ().String (), 1 * Byte )
161
+ b := newObject (s .bObject .Hash ().String (), 1 * Byte )
162
+
163
+ o .Put (a1 )
164
+ a1 .SetSize (- 5 )
165
+ o .Put (a2 )
166
+ o .Put (b )
167
+ }
168
+
156
169
type dummyObject struct {
157
170
hash plumbing.Hash
158
171
size FileSize
@@ -169,6 +182,6 @@ func (d *dummyObject) Hash() plumbing.Hash { return d.hash }
169
182
func (* dummyObject ) Type () plumbing.ObjectType { return plumbing .InvalidObject }
170
183
func (* dummyObject ) SetType (plumbing.ObjectType ) {}
171
184
func (d * dummyObject ) Size () int64 { return int64 (d .size ) }
172
- func (* dummyObject ) SetSize (s int64 ) { }
185
+ func (d * dummyObject ) SetSize (s int64 ) { d . size = FileSize ( s ) }
173
186
func (* dummyObject ) Reader () (io.ReadCloser , error ) { return nil , nil }
174
187
func (* dummyObject ) Writer () (io.WriteCloser , error ) { return nil , nil }
You can’t perform that action at this time.
0 commit comments