Merge pull request #862 from PapaYofen/fix-861

Fix https://github.com/chrislusf/seaweedfs/issues/861
This commit is contained in:
Chris Lu 2019-02-26 03:42:33 -08:00 committed by GitHub
commit 8a3e72566c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,8 +16,8 @@ const (
)
type TTL struct {
count byte
unit byte
Count byte
Unit byte
}
var EMPTY_TTL = &TTL{}
@ -43,12 +43,12 @@ func ReadTTL(ttlString string) (*TTL, error) {
}
count, err := strconv.Atoi(string(countBytes))
unit := toStoredByte(unitByte)
return &TTL{count: byte(count), unit: unit}, err
return &TTL{Count: byte(count), Unit: unit}, err
}
// read stored bytes to a ttl
func LoadTTLFromBytes(input []byte) (t *TTL) {
return &TTL{count: input[0], unit: input[1]}
return &TTL{Count: input[0], Unit: input[1]}
}
// read stored bytes to a ttl
@ -61,25 +61,25 @@ func LoadTTLFromUint32(ttl uint32) (t *TTL) {
// save stored bytes to an output with 2 bytes
func (t *TTL) ToBytes(output []byte) {
output[0] = t.count
output[1] = t.unit
output[0] = t.Count
output[1] = t.Unit
}
func (t *TTL) ToUint32() (output uint32) {
output = uint32(t.count) << 8
output += uint32(t.unit)
output = uint32(t.Count) << 8
output += uint32(t.Unit)
return output
}
func (t *TTL) String() string {
if t == nil || t.count == 0 {
if t == nil || t.Count == 0 {
return ""
}
if t.unit == Empty {
if t.Unit == Empty {
return ""
}
countString := strconv.Itoa(int(t.count))
switch t.unit {
countString := strconv.Itoa(int(t.Count))
switch t.Unit {
case Minute:
return countString + "m"
case Hour:
@ -115,21 +115,21 @@ func toStoredByte(readableUnitByte byte) byte {
}
func (t TTL) Minutes() uint32 {
switch t.unit {
switch t.Unit {
case Empty:
return 0
case Minute:
return uint32(t.count)
return uint32(t.Count)
case Hour:
return uint32(t.count) * 60
return uint32(t.Count) * 60
case Day:
return uint32(t.count) * 60 * 24
return uint32(t.Count) * 60 * 24
case Week:
return uint32(t.count) * 60 * 24 * 7
return uint32(t.Count) * 60 * 24 * 7
case Month:
return uint32(t.count) * 60 * 24 * 31
return uint32(t.Count) * 60 * 24 * 31
case Year:
return uint32(t.count) * 60 * 24 * 365
return uint32(t.Count) * 60 * 24 * 365
}
return 0
}