Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Sync fails if path leading to remoteDir doesn't already exist #49

Merged
merged 1 commit into from
Jun 19, 2020
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
2 changes: 1 addition & 1 deletion cmd/coder/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (cmd *syncCmd) Spec() cli.CommandSpec {
}

func (cmd *syncCmd) RegisterFlags(fl *pflag.FlagSet) {
fl.BoolVarP(&cmd.init, "init", "i", false, "do inititial transfer and exit")
fl.BoolVarP(&cmd.init, "init", "i", false, "do initial transfer and exit")
}

// See https://lxadm.com/Rsync_exit_codes#List_of_standard_rsync_exit_codes.
Expand Down
15 changes: 10 additions & 5 deletions internal/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s Sync) syncPaths(delete bool, local, remote string) error {
return nil
}

func (s Sync) remoteRm(ctx context.Context, remote string) error {
func (s Sync) remoteCmd(ctx context.Context, prog string, args ...string) error {
conn, err := s.Client.DialWsep(ctx, s.Env)
if err != nil {
return err
Expand All @@ -80,8 +80,8 @@ func (s Sync) remoteRm(ctx context.Context, remote string) error {

execer := wsep.RemoteExecer(conn)
process, err := execer.Start(ctx, wsep.Command{
Command: "rm",
Args: []string{"-rf", remote},
Command: prog,
Args: args,
})
if err != nil {
return err
Expand All @@ -91,7 +91,7 @@ func (s Sync) remoteRm(ctx context.Context, remote string) error {

err = process.Wait()
if code, ok := err.(wsep.ExitError); ok {
return fmt.Errorf("rm exit status: %v", code)
return fmt.Errorf("%s exit status: %v", prog, code)
}
if err != nil {
return xerrors.Errorf("execution failure: %w", err)
Expand Down Expand Up @@ -144,7 +144,7 @@ func (s Sync) handleDelete(localPath string) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

return s.remoteRm(ctx, s.convertPath(localPath))
return s.remoteCmd(ctx, "rm", "-rf", s.convertPath(localPath))
}

func (s Sync) handleRename(localPath string) error {
Expand Down Expand Up @@ -260,6 +260,11 @@ func (s Sync) Run() error {
}
defer notify.Stop(events)

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

s.remoteCmd(ctx, "mkdir", "-p", s.RemoteDir)

ap := activity.NewPusher(s.Client, s.Env.ID, activityName)
ap.Push()

Expand Down