implement helpers to get relevant info instead of FileInfo() (#18228)

This commit is contained in:
Harshavardhana 2023-10-12 15:29:59 -07:00 committed by GitHub
parent 763ff085a6
commit 409c391850
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 5 deletions

View File

@ -328,6 +328,18 @@ func (x xlMetaV2VersionHeader) sortsBefore(o xlMetaV2VersionHeader) bool {
return false
}
func (j xlMetaV2Version) getDataDir() string {
if j.Valid() {
switch j.Type {
case LegacyType:
return j.ObjectV1.DataDir
case ObjectType:
return uuid.UUID(j.ObjectV2.DataDir).String()
}
}
return ""
}
// Valid xl meta xlMetaV2Version is valid
func (j xlMetaV2Version) Valid() bool {
if !j.Type.valid() {
@ -1170,6 +1182,20 @@ func (x *xlMetaV2) AppendTo(dst []byte) ([]byte, error) {
return append(dst, x.data...), nil
}
func (x *xlMetaV2) findVersionStr(key string) (idx int, ver *xlMetaV2Version, err error) {
if key == nullVersionID {
key = ""
}
var u uuid.UUID
if key != "" {
u, err = uuid.Parse(key)
if err != nil {
return -1, nil, errFileVersionNotFound
}
}
return x.findVersion(u)
}
func (x *xlMetaV2) findVersion(key [16]byte) (idx int, ver *xlMetaV2Version, err error) {
for i, ver := range x.versions {
if key == ver.header.VersionID {

View File

@ -2442,19 +2442,20 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath string, f
}
// Replace the data of null version or any other existing version-id
ofi, err := xlMeta.ToFileInfo(dstVolume, dstPath, reqVID, false, false)
if err == nil && !ofi.Deleted {
if xlMeta.SharedDataDirCountStr(reqVID, ofi.DataDir) == 0 {
_, ver, err := xlMeta.findVersionStr(reqVID)
if err == nil {
dataDir := ver.getDataDir()
if dataDir != "" && (xlMeta.SharedDataDirCountStr(reqVID, dataDir) == 0) {
// Purge the destination path as we are not preserving anything
// versioned object was not requested.
oldDstDataPath = pathJoin(dstVolumeDir, dstPath, ofi.DataDir)
oldDstDataPath = pathJoin(dstVolumeDir, dstPath, dataDir)
// if old destination path is same as new destination path
// there is nothing to purge, this is true in case of healing
// avoid setting oldDstDataPath at that point.
if oldDstDataPath == dstDataPath {
oldDstDataPath = ""
} else {
xlMeta.data.remove(reqVID, ofi.DataDir)
xlMeta.data.remove(reqVID, dataDir)
}
}
}