Thanks to visit codestin.com
Credit goes to github.com

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

Commit e481b2a

Browse files
author
Russtopia
committed
coder sync fails if all dirs leading to sync remoteDir don't already exist
1 parent c2eda4a commit e481b2a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

internal/sync/sync.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,37 @@ func (s Sync) syncPaths(delete bool, local, remote string) error {
6767
return nil
6868
}
6969

70+
func (s Sync) remoteMkDir() error {
71+
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
72+
defer cancel()
73+
74+
conn, err := s.Client.DialWsep(ctx, s.Environment)
75+
if err != nil {
76+
return err
77+
}
78+
defer conn.Close(websocket.CloseNormalClosure, "")
79+
80+
execer := wsep.RemoteExecer(conn)
81+
process, err := execer.Start(ctx, wsep.Command{
82+
Command: "mkdir",
83+
Args: []string{"-p", s.RemoteDir},
84+
})
85+
if err != nil {
86+
return err
87+
}
88+
go io.Copy(os.Stdout, process.Stderr())
89+
go io.Copy(os.Stderr, process.Stdout())
90+
91+
err = process.Wait()
92+
if code, ok := err.(wsep.ExitError); ok {
93+
return fmt.Errorf("mkdir exit status: %v", code)
94+
}
95+
if err != nil {
96+
return xerrors.Errorf("execution failure: %w", err)
97+
}
98+
return nil
99+
}
100+
70101
func (s Sync) remoteRm(ctx context.Context, remote string) error {
71102
conn, err := s.Client.DialWsep(ctx, s.Environment)
72103
if err != nil {
@@ -252,6 +283,7 @@ func (s Sync) Run() error {
252283
}
253284
defer notify.Stop(events)
254285

286+
s.remoteMkDir()
255287
setConsoleTitle("⏳ syncing project")
256288
err = s.initSync()
257289
if err != nil {

0 commit comments

Comments
 (0)