Skip to content
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

find*Multi version to find all clashes and matches #528

Merged
merged 1 commit into from
Dec 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,33 @@ func (g *Commands) byRemoteResolve(relToRoot, fsPath string, r *File, push bool)
}

func (g *Commands) changeListResolve(relToRoot, fsPath string, push bool) (cl, clashes []*Change, err error) {
var r *File
resolver := g.rem.FindByPath

r, err = resolver(relToRoot)
if err != nil && err != ErrPathNotExists {
return
remotesChan := g.rem.FindByPathM(relToRoot)
iterCount := uint64(0)
noClashThreshold := uint64(1)

for rem := range remotesChan {
if rem != nil && anyMatch(g.opts.IgnoreRegexp, rem.Name) {
return
}

iterCount++

ccl, cclashes, cErr := g.byRemoteResolve(relToRoot, fsPath, rem, push)

cl = append(cl, ccl...)
clashes = append(clashes, cclashes...)
if false && cErr != nil {
err = reComposeError(err, cErr.Error())
}
}

if r != nil && anyMatch(g.opts.IgnoreRegexp, r.Name) {
return
if iterCount > noClashThreshold && len(clashes) < 1 {
clashes = append(clashes, cl...)
// err = reComposeError(err, ErrClashesDetected.Error())
}

return g.byRemoteResolve(relToRoot, fsPath, r, push)
return
}

func (g *Commands) doChangeListRecv(relToRoot, fsPath string, l, r *File, push bool) (cl, clashes []*Change, err error) {
Expand Down
19 changes: 17 additions & 2 deletions src/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,34 @@ func (g *Commands) Diff() (err error) {
spin.play()
defer spin.stop()

clashes := []*Change{}
for _, relToRootPath := range g.opts.Sources {
fsPath := g.context.AbsPathOf(relToRootPath)
ccl, _, cErr := g.changeListResolve(relToRootPath, fsPath, true)
ccl, cclashes, cErr := g.changeListResolve(relToRootPath, fsPath, true)
// TODO: Show the conflicts if any

clashes = append(clashes, cclashes...)
if cErr != nil {
return cErr
if cErr != ErrClashesDetected {
return cErr
} else {
err = reComposeError(err, cErr.Error())
}
}

if len(ccl) > 0 {
cl = append(cl, ccl...)
}
}

if !g.opts.IgnoreNameClashes && len(clashes) >= 1 {
warnClashesPersist(g.log, clashes)
if err != nil {
return err
}
return ErrClashesDetected
}

spin.stop()

var diffUtilPath string
Expand Down
1 change: 1 addition & 0 deletions src/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var (
const (
MimeTypeJoiner = "-"
RemoteDriveRootPath = "My Drive"
RemoteSeparator = "/"

FmtTimeString = "2006-01-02T15:04:05.000Z"
MsgClashesFixedNowRetry = "Clashes were fixed, please retry the operation"
Expand Down
34 changes: 15 additions & 19 deletions src/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,25 +342,24 @@ func (g *Commands) pullLikeMatchesResolver(pt pullType) (cl, clashes []*Change,
}

func (g *Commands) PullPiped(byId bool) (err error) {
resolver := g.rem.FindByPath
resolver := g.rem.FindByPathM
if byId {
resolver = g.rem.FindById
resolver = g.rem.FindByIdM
}

// TODO: (@odeke-em) allow pull-trashed

for _, relToRootPath := range g.opts.Sources {
rem, err := resolver(relToRootPath)
if err != nil {
return fmt.Errorf("%s: %v", relToRootPath, err)
}
if rem == nil {
continue
}
matches := resolver(relToRootPath)
for rem := range matches {
if rem == nil {
continue
}

err = g.pullAndDownload(relToRootPath, os.Stdout, rem, true)
if err != nil {
return err
err = g.pullAndDownload(relToRootPath, os.Stdout, rem, true)
if err != nil {
return err
}
}
}
return nil
Expand Down Expand Up @@ -407,12 +406,9 @@ func (g *Commands) pullByPath() (cl, clashes []*Change, err error) {
for _, relToRootPath := range g.opts.Sources {
fsPath := g.context.AbsPathOf(relToRootPath)
ccl, cclashes, cErr := g.changeListResolve(relToRootPath, fsPath, false)
if cErr != nil {
if cErr != ErrClashesDetected {
return cl, clashes, cErr
} else {
clashes = append(clashes, cclashes...)
}
clashes = append(clashes, cclashes...)
if cErr != nil && cErr != ErrClashesDetected {
return cl, clashes, cErr
}
if len(ccl) > 0 {
cl = append(cl, ccl...)
Expand Down Expand Up @@ -484,7 +480,7 @@ func (g *Commands) playPullChanges(cl []*Change, exports []string, opMap *map[Op

fn := localOpToChangerTranslator(g, c)
conformingFn := func(c *Change) error {
return fn(c, exports)
return fn(c, exports)
}

if fn == nil {
Expand Down
61 changes: 38 additions & 23 deletions src/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,30 @@ func (g *Commands) Push() (err error) {
var cl []*Change

g.log.Logln("Resolving...")
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)

spin := g.playabler()
spin.play()

// To Ensure mount points are cleared in the event of external exceptions
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
go func() {
_ = <-c
spin.stop()
g.clearMountPoints()
os.Exit(1)
}()

// TODO: Look at clashes?
clashes := []*Change{}

for _, relToRootPath := range g.opts.Sources {
fsPath := g.context.AbsPathOf(relToRootPath)
ccl, cclashes, cErr := g.changeListResolve(relToRootPath, fsPath, true)
if cErr != nil {
if cErr == ErrClashesDetected {
clashes = append(clashes, cclashes...)
continue
} else {
spin.stop()
return cErr
}

clashes = append(clashes, cclashes...)
if cErr != nil && cErr != ErrClashesDetected {
spin.stop()
return cErr
}
if len(ccl) > 0 {
cl = append(cl, ccl...)
Expand Down Expand Up @@ -330,27 +326,46 @@ func (g *Commands) playPushChanges(cl []*Change, opMap *map[Operation]sizeCounte
}

func lonePush(g *Commands, parent, absPath, path string) (cl, clashes []*Change, err error) {
r, err := g.rem.FindByPath(absPath)
if err != nil && err != ErrPathNotExists {
return
}
remotesChan := g.rem.FindByPathM(absPath)

iterCount := uint64(0)
noClashThreshold := uint64(1)
var l *File
localinfo, _ := os.Stat(path)
if localinfo != nil {
l = NewLocalFile(path, localinfo)
}

clr := &changeListResolve{
push: true,
dir: parent,
base: absPath,
remote: r,
local: l,
depth: g.opts.Depth,
for r := range remotesChan {
if r == nil {
continue
}

iterCount++

clr := &changeListResolve{
push: true,
dir: parent,
base: absPath,
remote: r,
local: l,
depth: g.opts.Depth,
}

ccl, cclashes, cErr := g.resolveChangeListRecv(clr)
cl = append(cl, ccl...)
clashes = append(clashes, cclashes...)
if cErr != nil {
err = reComposeError(err, cErr.Error())
}
}

return g.resolveChangeListRecv(clr)
if iterCount > noClashThreshold && len(clashes) < 1 {
clashes = append(clashes, cl...)
err = reComposeError(err, ErrClashesDetected.Error())
}

return
}

func (g *Commands) pathSplitter(absPath string) (dir, base string) {
Expand Down
Loading