Avoid removing session v7 json files by migrateSessionV5ToV6 (#2)
This commit is contained in:
committed by
Harshavardhana
parent
c4c99999bc
commit
94f4c4cd2d
+20
-11
@@ -124,13 +124,14 @@ func deltaSourceTarget(sourceURL string, targetURL string, isForce bool, isFake
|
||||
|
||||
// List both source and target, compare and return values through channel.
|
||||
for diffMsg := range objectDifference(sourceClnt, targetClnt, sourceURL, targetURL) {
|
||||
if diffMsg.Diff == differInNone {
|
||||
switch diffMsg.Diff {
|
||||
case differInNone:
|
||||
// No difference, continue.
|
||||
continue
|
||||
} else if diffMsg.Diff == differInType {
|
||||
case differInType:
|
||||
mirrorURLsCh <- mirrorURLs{Error: errInvalidTarget(diffMsg.SecondURL)}
|
||||
continue
|
||||
} else if diffMsg.Diff == differInSize {
|
||||
case differInSize:
|
||||
if !isForce && !isFake {
|
||||
// Size differs and force not set
|
||||
mirrorURLsCh <- mirrorURLs{Error: errOverWriteNotAllowed(diffMsg.SecondURL)}
|
||||
@@ -148,7 +149,7 @@ func deltaSourceTarget(sourceURL string, targetURL string, isForce bool, isFake
|
||||
TargetContent: targetContent,
|
||||
}
|
||||
continue
|
||||
} else if diffMsg.Diff == differInFirst {
|
||||
case differInFirst:
|
||||
sourceSuffix := strings.TrimPrefix(diffMsg.FirstURL, sourceURL)
|
||||
// Either available only in source or size differs and force is set
|
||||
targetPath := urlJoinPath(targetURL, sourceSuffix)
|
||||
@@ -160,18 +161,26 @@ func deltaSourceTarget(sourceURL string, targetURL string, isForce bool, isFake
|
||||
TargetAlias: targetAlias,
|
||||
TargetContent: targetContent,
|
||||
}
|
||||
} else if diffMsg.Diff == differInSecond && isRemove {
|
||||
if !isForce && !isFake {
|
||||
// Object removal not allowed if force is not set.
|
||||
case differInSecond:
|
||||
if isRemove {
|
||||
if !isForce && !isFake {
|
||||
// Object removal not allowed if force is not set.
|
||||
mirrorURLsCh <- mirrorURLs{
|
||||
Error: errDeleteNotAllowed(diffMsg.SecondURL),
|
||||
}
|
||||
continue
|
||||
}
|
||||
mirrorURLsCh <- mirrorURLs{
|
||||
Error: errDeleteNotAllowed(diffMsg.SecondURL),
|
||||
TargetAlias: targetAlias,
|
||||
TargetContent: diffMsg.secondContent,
|
||||
}
|
||||
continue
|
||||
}
|
||||
continue
|
||||
default:
|
||||
mirrorURLsCh <- mirrorURLs{
|
||||
TargetAlias: targetAlias,
|
||||
TargetContent: diffMsg.secondContent,
|
||||
Error: errUnrecognizedDiffType(diffMsg.Diff).Trace(diffMsg.FirstURL, diffMsg.SecondURL),
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-1
@@ -18,6 +18,7 @@ package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/probe"
|
||||
@@ -65,13 +66,21 @@ func migrateSessionV6ToV7() {
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate session version '5' to version '6', all older sessions are
|
||||
// in-fact removed and not migrated. All session files from '6' and
|
||||
// above should be migrated - See: migrateSessionV6ToV7().
|
||||
func migrateSessionV5ToV6() {
|
||||
for _, sid := range getSessionIDs() {
|
||||
sV6Header, err := loadSessionV6Header(sid)
|
||||
fatalIf(err.Trace(sid), "Unable to load version ‘6’. Migration failed please report this issue at https://github.com/minio/mc/issues.")
|
||||
if sV6Header.Version == "6" { // It is new format.
|
||||
|
||||
sessionVersion, e := strconv.Atoi(sV6Header.Version)
|
||||
fatalIf(probe.NewError(e), "Unable to load version ‘6’. Migration failed please report this issue at https://github.com/minio/mc/issues.")
|
||||
|
||||
if sessionVersion > 5 { // It is new format.
|
||||
continue
|
||||
}
|
||||
|
||||
/*** Remove all session files older than v6 ***/
|
||||
|
||||
sessionFile, err := getSessionFile(sid)
|
||||
|
||||
@@ -31,6 +31,10 @@ var (
|
||||
return probe.NewError(errors.New("Invalid arguments provided, cannot proceed.")).Untrace()
|
||||
}
|
||||
|
||||
errUnrecognizedDiffType = func(diff differType) *probe.Error {
|
||||
return probe.NewError(errors.New("Unrecognized diffType: " + diff.String() + " provided.")).Untrace()
|
||||
}
|
||||
|
||||
errInvalidAliasedURL = func(URL string) *probe.Error {
|
||||
return probe.NewError(errors.New("Use ‘mc config host add mycloud " + URL + " ...’ to add an alias. Use the alias for S3 operations.")).Untrace()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user