Skip to content

Commit 72eff15

Browse files
author
Russtopia
committed
coder sync fails if all dirs leading to sync remoteDir don't already exist
1 parent 045145b commit 72eff15

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

cmd/coder/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (cmd *syncCmd) Spec() cli.CommandSpec {
2727
}
2828

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

3333
// See https://lxadm.com/Rsync_exit_codes#List_of_standard_rsync_exit_codes.

internal/sync/sync.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (s Sync) syncPaths(delete bool, local, remote string) error {
7171
return nil
7272
}
7373

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

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

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

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

150150
func (s Sync) handleRename(localPath string) error {
@@ -260,6 +260,11 @@ func (s Sync) Run() error {
260260
}
261261
defer notify.Stop(events)
262262

263+
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
264+
defer cancel()
265+
266+
s.remoteCmd(ctx, "mkdir", "-p", s.RemoteDir)
267+
263268
ap := activity.NewPusher(s.Client, s.Env.ID, activityName)
264269
ap.Push()
265270

0 commit comments

Comments
 (0)