github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/cmd/xl-storage-format-v2-legacy.go (about) 1 // Copyright (c) 2015-2021 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package cmd 19 20 import ( 21 "fmt" 22 "time" 23 24 "github.com/tinylib/msgp/msgp" 25 ) 26 27 // unmarshalV unmarshals with a specific header version. 28 func (x *xlMetaV2VersionHeader) unmarshalV(v uint8, bts []byte) (o []byte, err error) { 29 switch v { 30 case 1: 31 return x.unmarshalV1(bts) 32 case xlHeaderVersion: 33 return x.UnmarshalMsg(bts) 34 } 35 return bts, fmt.Errorf("unknown xlHeaderVersion: %d", v) 36 } 37 38 // unmarshalV1 decodes version 1, never released. 39 func (x *xlMetaV2VersionHeader) unmarshalV1(bts []byte) (o []byte, err error) { 40 var zb0001 uint32 41 zb0001, bts, err = msgp.ReadArrayHeaderBytes(bts) 42 if err != nil { 43 err = msgp.WrapError(err) 44 return 45 } 46 if zb0001 != 4 { 47 err = msgp.ArrayError{Wanted: 4, Got: zb0001} 48 return 49 } 50 bts, err = msgp.ReadExactBytes(bts, (x.VersionID)[:]) 51 if err != nil { 52 err = msgp.WrapError(err, "VersionID") 53 return 54 } 55 x.ModTime, bts, err = msgp.ReadInt64Bytes(bts) 56 if err != nil { 57 err = msgp.WrapError(err, "ModTime") 58 return 59 } 60 { 61 var zb0002 uint8 62 zb0002, bts, err = msgp.ReadUint8Bytes(bts) 63 if err != nil { 64 err = msgp.WrapError(err, "Type") 65 return 66 } 67 x.Type = VersionType(zb0002) 68 } 69 { 70 var zb0003 uint8 71 zb0003, bts, err = msgp.ReadUint8Bytes(bts) 72 if err != nil { 73 err = msgp.WrapError(err, "Flags") 74 return 75 } 76 x.Flags = xlFlags(zb0003) 77 } 78 o = bts 79 return 80 } 81 82 // unmarshalV unmarshals with a specific metadata version. 83 func (j *xlMetaV2Version) unmarshalV(v uint8, bts []byte) (o []byte, err error) { 84 if v > xlMetaVersion { 85 return bts, fmt.Errorf("unknown xlMetaVersion: %d", v) 86 } 87 88 // Clear omitempty fields: 89 if j.ObjectV2 != nil && len(j.ObjectV2.PartIndices) > 0 { 90 j.ObjectV2.PartIndices = j.ObjectV2.PartIndices[:0] 91 } 92 o, err = j.UnmarshalMsg(bts) 93 94 // Fix inconsistent x-minio-internal-replication-timestamp by converting to UTC. 95 // Fixed in version 2 or later 96 if err == nil && j.Type == DeleteType && v < 2 { 97 if val, ok := j.DeleteMarker.MetaSys[ReservedMetadataPrefixLower+ReplicationTimestamp]; ok { 98 tm, err := time.Parse(time.RFC3339Nano, string(val)) 99 if err == nil { 100 j.DeleteMarker.MetaSys[ReservedMetadataPrefixLower+ReplicationTimestamp] = []byte(tm.UTC().Format(time.RFC3339Nano)) 101 } 102 } 103 if val, ok := j.DeleteMarker.MetaSys[ReservedMetadataPrefixLower+ReplicaTimestamp]; ok { 104 tm, err := time.Parse(time.RFC3339Nano, string(val)) 105 if err == nil { 106 j.DeleteMarker.MetaSys[ReservedMetadataPrefixLower+ReplicaTimestamp] = []byte(tm.UTC().Format(time.RFC3339Nano)) 107 } 108 } 109 } 110 111 // Clean up PartEtags on v1 112 if j.ObjectV2 != nil { 113 allEmpty := true 114 for _, tag := range j.ObjectV2.PartETags { 115 if len(tag) != 0 { 116 allEmpty = false 117 break 118 } 119 } 120 if allEmpty { 121 j.ObjectV2.PartETags = nil 122 } 123 } 124 return o, err 125 }