@@ -297,6 +297,7 @@ func statGuestPath(ctx context.Context, baseURL, apiKey, instanceID, guestPath s
297297 ws , resp , err := dialer .DialContext (ctx , wsURL , headers )
298298 if err != nil {
299299 if resp != nil {
300+ defer resp .Body .Close ()
300301 body , _ := io .ReadAll (resp .Body )
301302 return nil , fmt .Errorf ("websocket connect failed (HTTP %d): %s" , resp .StatusCode , string (body ))
302303 }
@@ -593,6 +594,7 @@ func createDirOnInstanceWithUidGid(ctx context.Context, baseURL, apiKey, instanc
593594 ws , resp , err := dialer .DialContext (ctx , wsURL , headers )
594595 if err != nil {
595596 if resp != nil {
597+ defer resp .Body .Close ()
596598 body , _ := io .ReadAll (resp .Body )
597599 return fmt .Errorf ("websocket connect failed (HTTP %d): %s" , resp .StatusCode , string (body ))
598600 }
@@ -673,7 +675,8 @@ func copyFromInstance(ctx context.Context, baseURL, apiKey, instanceID, srcPath,
673675 // Will create file at dstPath
674676 } else if dstIsDir {
675677 // Copy into directory using basename
676- resolvedDst = filepath .Join (dstPath , filepath .Base (srcPath ))
678+ // Use path.Base for guest srcPath (always forward slashes)
679+ resolvedDst = filepath .Join (dstPath , path .Base (srcPath ))
677680 }
678681 // else: overwrite existing file
679682 } else {
@@ -866,6 +869,7 @@ func copyFromInstanceToStdout(ctx context.Context, baseURL, apiKey, instanceID,
866869 ws , resp , err := dialer .DialContext (ctx , wsURL , headers )
867870 if err != nil {
868871 if resp != nil {
872+ defer resp .Body .Close ()
869873 body , _ := io .ReadAll (resp .Body )
870874 return fmt .Errorf ("websocket connect failed (HTTP %d): %s" , resp .StatusCode , string (body ))
871875 }
@@ -931,6 +935,8 @@ func copyFromInstanceToStdout(ctx context.Context, baseURL, apiKey, instanceID,
931935 Name : header .Path + "/" ,
932936 Mode : int64 (header .Mode ),
933937 ModTime : time .Unix (header .Mtime , 0 ),
938+ Uid : int (header .Uid ),
939+ Gid : int (header .Gid ),
934940 }
935941 if err := tw .WriteHeader (tarHeader ); err != nil {
936942 return fmt .Errorf ("write tar dir header: %w" , err )
@@ -943,6 +949,8 @@ func copyFromInstanceToStdout(ctx context.Context, baseURL, apiKey, instanceID,
943949 Linkname : header .LinkTarget ,
944950 Mode : int64 (header .Mode ),
945951 ModTime : time .Unix (header .Mtime , 0 ),
952+ Uid : int (header .Uid ),
953+ Gid : int (header .Gid ),
946954 }
947955 if err := tw .WriteHeader (tarHeader ); err != nil {
948956 return fmt .Errorf ("write tar symlink header: %w" , err )
@@ -987,6 +995,8 @@ func writeTarEntry(tw *tar.Writer, header *cpFileHeader, data []byte) error {
987995 Size : int64 (len (data )),
988996 Mode : int64 (header .Mode ),
989997 ModTime : time .Unix (header .Mtime , 0 ),
998+ Uid : int (header .Uid ),
999+ Gid : int (header .Gid ),
9901000 }
9911001 if err := tw .WriteHeader (tarHeader ); err != nil {
9921002 return fmt .Errorf ("write tar header: %w" , err )
0 commit comments