Skip to content

Commit b9933ce

Browse files
committed
fix: multiple cp improvements
- Write UID/GID to tar archive for archive mode support - Use path.Base for guest paths (Windows compatibility) - Close HTTP response body on WebSocket dial failure - Update hypeman-go dependency
1 parent dc84be3 commit b9933ce

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/gorilla/websocket v1.5.3
1313
github.com/itchyny/json2yaml v0.1.4
1414
github.com/muesli/reflow v0.3.0
15-
github.com/onkernel/hypeman-go v0.7.1-0.20251223015448-3fc21a9216cf
15+
github.com/onkernel/hypeman-go v0.7.1-0.20251223024018-6970d69a9e1e
1616
github.com/tidwall/gjson v1.18.0
1717
github.com/tidwall/pretty v1.2.1
1818
github.com/urfave/cli-docs/v3 v3.0.0-alpha6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
105105
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
106106
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
107107
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
108-
github.com/onkernel/hypeman-go v0.7.1-0.20251223015448-3fc21a9216cf h1:vGNpWu/QZcBXqzeRx1qV/jN8JPGqveWn/xsqbrlQv1A=
109-
github.com/onkernel/hypeman-go v0.7.1-0.20251223015448-3fc21a9216cf/go.mod h1:Wtm4ewVGGPZc2ySeeuQISQyJxujyQuyDjXyksVkIyy8=
108+
github.com/onkernel/hypeman-go v0.7.1-0.20251223024018-6970d69a9e1e h1:XY7ZZOqyYfSVhGOtx+Z7rK4RyvqYWgfseTmqGTXIGMI=
109+
github.com/onkernel/hypeman-go v0.7.1-0.20251223024018-6970d69a9e1e/go.mod h1:Wtm4ewVGGPZc2ySeeuQISQyJxujyQuyDjXyksVkIyy8=
110110
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
111111
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
112112
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=

pkg/cmd/cp.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)