Skip to content

Commit ad7a6b3

Browse files
committed
push/mounted: fix unload of paths in root + no return catch
Fixes #641. + Refactored push mounted, removing/generalizing code for mounts to use same as ordinary pushes. + Ensure that in cmd/drive/main.go, after a mounted push we return appropriately otherwise we were erraneously falling to start an ordinary push which would trigger a bug with a bad context. This is akin to the common C-style switch bug in which one forgets to break/return. + Fixed up a bug with mounted push where if the user specified a single mounted path, the current working directory wouldn't be added to the arguments that needed to be processed. It was an error comparison mismatch.
1 parent e43d850 commit ad7a6b3

File tree

2 files changed

+13
-53
lines changed

2 files changed

+13
-53
lines changed

cmd/drive/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ func (cmd *pushCmd) Flags(fs *flag.FlagSet) *flag.FlagSet {
851851
func (cmd *pushCmd) Run(args []string, definedFlags map[string]*flag.Flag) {
852852
if *cmd.MountedPush {
853853
exitWithError(cmd.pushMounted(args, definedFlags))
854+
return
854855
}
855856

856857
sources, context, path := preprocessArgs(args)
@@ -1056,7 +1057,7 @@ func (cmd *pushCmd) pushMounted(args []string, definedFlags map[string]*flag.Fla
10561057
// Expectation is that at least one path has to be passed in
10571058
if argc < 2 {
10581059
cwd, cerr := os.Getwd()
1059-
if cerr != nil {
1060+
if cerr == nil {
10601061
contextArgs = append(contextArgs, cwd)
10611062
}
10621063
rest = args

src/push.go

+11-52
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ func (g *Commands) Push() error {
8181
}
8282
}
8383

84+
mount := g.opts.Mount
85+
if mount != nil {
86+
for _, mt := range mount.Points {
87+
ccl, cclashes, cerr := g.changeListResolve(mt.Name, mt.MountPath, true)
88+
if cerr == nil {
89+
cl = append(cl, ccl...)
90+
}
91+
clashes = append(clashes, cclashes...)
92+
}
93+
}
94+
8495
if len(clashes) >= 1 {
8596
if g.opts.FixClashes {
8697
err := autoRenameClashes(g, clashes)
@@ -94,16 +105,6 @@ func (g *Commands) Push() error {
94105
return ErrClashesDetected
95106
}
96107

97-
mount := g.opts.Mount
98-
if mount != nil {
99-
for _, mt := range mount.Points {
100-
ccl, _, cerr := lonePush(g, rootAbsPath, mt.Name, mt.MountPath)
101-
if cerr == nil {
102-
cl = append(cl, ccl...)
103-
}
104-
}
105-
}
106-
107108
spin.stop()
108109

109110
nonConflictsPtr, conflictsPtr := g.resolveConflicts(cl, true)
@@ -319,48 +320,6 @@ func (g *Commands) playPushChanges(cl []*Change, opMap *map[Operation]sizeCounte
319320
return err
320321
}
321322

322-
func lonePush(g *Commands, parent, absPath, path string) (cl, clashes []*Change, err error) {
323-
remotesChan := g.rem.FindByPathM(absPath)
324-
325-
var l *File
326-
localinfo, _ := os.Stat(path)
327-
if localinfo != nil {
328-
l = NewLocalFile(path, localinfo)
329-
}
330-
331-
iterCount := uint64(0)
332-
noClashThreshold := uint64(1)
333-
334-
for r := range remotesChan {
335-
if r != nil {
336-
iterCount++
337-
}
338-
339-
clr := &changeListResolve{
340-
remote: r,
341-
local: l,
342-
push: true,
343-
dir: parent,
344-
localBase: absPath,
345-
depth: g.opts.Depth,
346-
}
347-
348-
ccl, cclashes, cErr := g.resolveChangeListRecv(clr)
349-
cl = append(cl, ccl...)
350-
clashes = append(clashes, cclashes...)
351-
if cErr != nil {
352-
err = combineErrors(err, cErr)
353-
}
354-
}
355-
356-
if iterCount > noClashThreshold && len(clashes) < 1 {
357-
clashes = append(clashes, cl...)
358-
err = combineErrors(err, ErrClashesDetected)
359-
}
360-
361-
return
362-
}
363-
364323
func (g *Commands) pathSplitter(absPath string) (dir, base string) {
365324
p := strings.Split(absPath, "/")
366325
pLen := len(p)

0 commit comments

Comments
 (0)