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

Commit 92f3c77

Browse files
author
Russtopia
committed
coder sync fails if all dirs leading to sync remoteDir don't already exist
1 parent 01cd4c5 commit 92f3c77

File tree

1 file changed

+9
-37
lines changed

1 file changed

+9
-37
lines changed

internal/sync/sync.go

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

74-
func (s Sync) remoteMkDir() error {
75-
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
76-
defer cancel()
77-
78-
conn, err := s.Client.DialWsep(ctx, s.Environment)
79-
if err != nil {
80-
return err
81-
}
82-
defer conn.Close(websocket.CloseNormalClosure, "")
83-
84-
execer := wsep.RemoteExecer(conn)
85-
process, err := execer.Start(ctx, wsep.Command{
86-
Command: "mkdir",
87-
Args: []string{"-p", s.RemoteDir},
88-
})
89-
if err != nil {
90-
return err
91-
}
92-
go io.Copy(os.Stdout, process.Stderr())
93-
go io.Copy(os.Stderr, process.Stdout())
94-
95-
err = process.Wait()
96-
if code, ok := err.(wsep.ExitError); ok {
97-
return fmt.Errorf("mkdir exit status: %v", code)
98-
}
99-
if err != nil {
100-
return xerrors.Errorf("execution failure: %w", err)
101-
}
102-
return nil
103-
}
104-
105-
func (s Sync) remoteRm(ctx context.Context, remote string) error {
74+
func (s Sync) remoteCmd(ctx context.Context, prog string, args ...string) error {
10675
conn, err := s.Client.DialWsep(ctx, s.Env)
10776
if err != nil {
10877
return err
@@ -111,8 +80,8 @@ func (s Sync) remoteRm(ctx context.Context, remote string) error {
11180

11281
execer := wsep.RemoteExecer(conn)
11382
process, err := execer.Start(ctx, wsep.Command{
114-
Command: "rm",
115-
Args: []string{"-rf", remote},
83+
Command: prog,
84+
Args: args,
11685
})
11786
if err != nil {
11887
return err
@@ -122,7 +91,7 @@ func (s Sync) remoteRm(ctx context.Context, remote string) error {
12291

12392
err = process.Wait()
12493
if code, ok := err.(wsep.ExitError); ok {
125-
return fmt.Errorf("rm exit status: %v", code)
94+
return fmt.Errorf("%s exit status: %v", prog, code)
12695
}
12796
if err != nil {
12897
return xerrors.Errorf("execution failure: %w", err)
@@ -175,7 +144,7 @@ func (s Sync) handleDelete(localPath string) error {
175144
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
176145
defer cancel()
177146

178-
return s.remoteRm(ctx, s.convertPath(localPath))
147+
return s.remoteCmd(ctx, "rm", "-rf", s.convertPath(localPath))
179148
}
180149

181150
func (s Sync) handleRename(localPath string) error {
@@ -291,7 +260,10 @@ func (s Sync) Run() error {
291260
}
292261
defer notify.Stop(events)
293262

294-
s.remoteMkDir()
263+
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
264+
defer cancel()
265+
266+
s.remoteCmd(ctx, "mkdir", "-p", s.RemoteDir)
295267

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

0 commit comments

Comments
 (0)