mirror of
https://github.com/minio/mc.git
synced 2025-11-13 12:22:45 +03:00
Fix sync bug when in TypeA and TypeB sync style source doesn't exist
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
@@ -71,9 +72,13 @@ EXAMPLES:
|
|||||||
|
|
||||||
// doSyncSession - Sync an object to multiple destination
|
// doSyncSession - Sync an object to multiple destination
|
||||||
func doSyncSession(sURLs syncURLs, bar *barSend, syncQueue chan bool, ssCh chan syncSession, wg *sync.WaitGroup, s *sessionV1) {
|
func doSyncSession(sURLs syncURLs, bar *barSend, syncQueue chan bool, ssCh chan syncSession, wg *sync.WaitGroup, s *sessionV1) {
|
||||||
|
// waitgroup reply deferred until this function returns
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
|
// hold lock for map updates inside session
|
||||||
s.Lock.Lock()
|
s.Lock.Lock()
|
||||||
defer s.Lock.Unlock()
|
defer s.Lock.Unlock()
|
||||||
|
|
||||||
if !globalQuietFlag {
|
if !globalQuietFlag {
|
||||||
bar.SetCaption(sURLs.SourceContent.Name + ": ")
|
bar.SetCaption(sURLs.SourceContent.Name + ": ")
|
||||||
}
|
}
|
||||||
@@ -105,6 +110,10 @@ func doSyncSession(sURLs syncURLs, bar *barSend, syncQueue chan bool, ssCh chan
|
|||||||
var newReader io.Reader
|
var newReader io.Reader
|
||||||
switch globalQuietFlag {
|
switch globalQuietFlag {
|
||||||
case true:
|
case true:
|
||||||
|
console.Infos(SyncMessage{
|
||||||
|
Source: sURLs.SourceContent.Name,
|
||||||
|
Target: strings.Join(targetURLs, " "),
|
||||||
|
})
|
||||||
newReader = yielder.NewReader(reader)
|
newReader = yielder.NewReader(reader)
|
||||||
default:
|
default:
|
||||||
// set up progress
|
// set up progress
|
||||||
|
|||||||
@@ -53,6 +53,13 @@ type cpURLs struct {
|
|||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c cpURLs) IsEmpty() bool {
|
||||||
|
if c.SourceContent == nil && c.TargetContent == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
type cpURLsType uint8
|
type cpURLsType uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ func (i InfoMessage) String() string {
|
|||||||
return i.Message
|
return i.Message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CopyMessage container for file copy messages
|
||||||
type CopyMessage struct {
|
type CopyMessage struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Source string `json:"source"`
|
Source string `json:"source"`
|
||||||
@@ -83,3 +84,10 @@ type CopyMessage struct {
|
|||||||
func (c CopyMessage) String() string {
|
func (c CopyMessage) String() string {
|
||||||
return fmt.Sprintf("‘%s’ -> ‘%s’", c.Source, c.Target)
|
return fmt.Sprintf("‘%s’ -> ‘%s’", c.Source, c.Target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SyncMessage container for file sync messages, inherits CopyMessage
|
||||||
|
type SyncMessage CopyMessage
|
||||||
|
|
||||||
|
func (s SyncMessage) String() string {
|
||||||
|
return fmt.Sprintf("‘%s’ -> ‘%s’", s.Source, s.Target)
|
||||||
|
}
|
||||||
|
|||||||
24
sync-url.go
24
sync-url.go
@@ -52,6 +52,22 @@ type syncURLs struct {
|
|||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s syncURLs) IsEmpty() bool {
|
||||||
|
empty := false
|
||||||
|
if s.SourceContent == nil {
|
||||||
|
empty = true
|
||||||
|
if s.TargetContents == nil {
|
||||||
|
empty = true
|
||||||
|
return empty
|
||||||
|
}
|
||||||
|
if len(s.TargetContents) > 0 && s.TargetContents[0] == nil {
|
||||||
|
empty = true
|
||||||
|
return empty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return empty
|
||||||
|
}
|
||||||
|
|
||||||
type syncURLsType cpURLsType
|
type syncURLsType cpURLsType
|
||||||
|
|
||||||
// guessSyncURLType guesses the type of URL. This approach all allows prepareURL
|
// guessSyncURLType guesses the type of URL. This approach all allows prepareURL
|
||||||
@@ -91,7 +107,9 @@ func prepareSyncURLsTypeA(sourceURL string, targetURLs []string) <-chan syncURLs
|
|||||||
sURLs.SourceContent = cURLs.SourceContent
|
sURLs.SourceContent = cURLs.SourceContent
|
||||||
sURLs.TargetContents = append(sURLs.TargetContents, cURLs.TargetContent)
|
sURLs.TargetContents = append(sURLs.TargetContents, cURLs.TargetContent)
|
||||||
}
|
}
|
||||||
syncURLsCh <- sURLs
|
if !sURLs.IsEmpty() {
|
||||||
|
syncURLsCh <- sURLs
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
return syncURLsCh
|
return syncURLsCh
|
||||||
}
|
}
|
||||||
@@ -113,7 +131,9 @@ func prepareSyncURLsTypeB(sourceURL string, targetURLs []string) <-chan syncURLs
|
|||||||
sURLs.SourceContent = cURLs.SourceContent
|
sURLs.SourceContent = cURLs.SourceContent
|
||||||
sURLs.TargetContents = append(sURLs.TargetContents, cURLs.TargetContent)
|
sURLs.TargetContents = append(sURLs.TargetContents, cURLs.TargetContent)
|
||||||
}
|
}
|
||||||
syncURLsCh <- sURLs
|
if !sURLs.IsEmpty() {
|
||||||
|
syncURLsCh <- sURLs
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
return syncURLsCh
|
return syncURLsCh
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user