-
Notifications
You must be signed in to change notification settings - Fork 547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor mc cp and make session optional #2910
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,7 +162,7 @@ func loadSessionV8(sid string) (*sessionV8, *probe.Error) { | |
} | ||
|
||
// newSessionV8 provides a new session. | ||
func newSessionV8() *sessionV8 { | ||
func newSessionV8(sessionID string) *sessionV8 { | ||
s := &sessionV8{} | ||
s.Header = &sessionV8Header{} | ||
s.Header.Version = globalSessionConfigVersion | ||
|
@@ -177,7 +177,7 @@ func newSessionV8() *sessionV8 { | |
s.Header.UserMetaData = make(map[string]string) | ||
s.Header.When = UTCNow() | ||
s.mutex = new(sync.Mutex) | ||
s.SessionID = newRandomID(8) | ||
s.SessionID = sessionID | ||
|
||
sessionDataFile, err := getSessionDataFile(s.SessionID) | ||
fatalIf(err.Trace(s.SessionID), "Unable to create session data file \""+sessionDataFile+"\".") | ||
|
@@ -375,6 +375,18 @@ func (s sessionV8) CloseAndDie() { | |
console.Fatalln("Session safely terminated. To resume session `mc session resume " + s.SessionID + "`") | ||
} | ||
|
||
func (s sessionV8) copyCloseAndDie(sessionFlag bool) { | ||
if sessionFlag { | ||
s.Close() | ||
console.Fatalln("Command terminated safely. Run this command to resume copy again.") | ||
} else { | ||
s.mutex.Lock() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: why do we need to do anything at all when session flag wasn't passed along with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure. I am just keeping session behaviour same as |
||
defer s.mutex.Unlock() | ||
|
||
s.DataFP.Close() // ignore error. | ||
} | ||
} | ||
|
||
// Create a factory function to simplify checking if | ||
// object was last operated on. | ||
func isLastFactory(lastURL string) func(string) bool { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -35,9 +35,9 @@ func (s *TestSuite) TestSession(c *C) { | |||||
c.Assert(err, IsNil) | ||||||
c.Assert(isSessionDirExists(), Equals, true) | ||||||
|
||||||
session := newSessionV8() | ||||||
session := newSessionV8(getHash("cp", []string{"mybucket", "myminio/mybucket"})) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor nit
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not correct. I am simulating |
||||||
c.Assert(session.Header.CommandArgs, IsNil) | ||||||
c.Assert(len(session.SessionID), Equals, 8) | ||||||
c.Assert(len(session.SessionID) >= 8, Equals, true) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about the following assert? It asserts a more stronger property than
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not correct. Existing session support generates 8 bytes long random string whereas this PR generates guessable session ID using SHA-256 where the length is 32 bytes long. This change makes both to work. When session support is deprecated and removed, this check will be fine-tuned. |
||||||
_, e := os.Stat(session.DataFP.Name()) | ||||||
c.Assert(e, IsNil) | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: This would result in exit code being non-zero. Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CloseAndDie()
does the same thing. I am keeping the same behaviour.