Skip to content

Commit 0d77d5a

Browse files
committed
fix: pass archive flag to copyFromInstanceToStdout
- Add archive parameter to copyFromInstanceToStdout - Only preserve UID/GID in tar headers when archive mode is enabled - Update hypeman-go dependency
1 parent ca45e2a commit 0d77d5a

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
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.20251223025630-30d438f9919f
15+
github.com/onkernel/hypeman-go v0.7.1-0.20251223031652-14904a03ecca
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.20251223025630-30d438f9919f h1:5Tnk4IxErhHxg1D2z+OSfpC2RtISoqRlZEsPsvyZVLk=
109-
github.com/onkernel/hypeman-go v0.7.1-0.20251223025630-30d438f9919f/go.mod h1:Wtm4ewVGGPZc2ySeeuQISQyJxujyQuyDjXyksVkIyy8=
108+
github.com/onkernel/hypeman-go v0.7.1-0.20251223031652-14904a03ecca h1:wGYuHtNqniugAm655MU4xN+SwIGbuK3FLGq9psXXtDE=
109+
github.com/onkernel/hypeman-go v0.7.1-0.20251223031652-14904a03ecca/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: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func handleCp(ctx context.Context, cmd *cli.Command) error {
179179
if srcIsRemote {
180180
// Copy from instance to local (or stdout if dstPath is "-")
181181
if dstPath == "-" {
182-
return copyFromInstanceToStdout(ctx, baseURL, apiKey, instanceID, srcPath, followLinks)
182+
return copyFromInstanceToStdout(ctx, baseURL, apiKey, instanceID, srcPath, followLinks, archive)
183183
}
184184
return copyFromInstance(ctx, baseURL, apiKey, instanceID, srcPath, dstPath, followLinks, quiet, archive)
185185
} else {
@@ -851,7 +851,7 @@ func copyTarFileToInstance(ctx context.Context, baseURL, apiKey, instanceID stri
851851
}
852852

853853
// copyFromInstanceToStdout copies files from the instance and writes a tar archive to stdout
854-
func copyFromInstanceToStdout(ctx context.Context, baseURL, apiKey, instanceID, srcPath string, followLinks bool) error {
854+
func copyFromInstanceToStdout(ctx context.Context, baseURL, apiKey, instanceID, srcPath string, followLinks, archive bool) error {
855855
wsURL, err := buildCpWsURL(baseURL, instanceID)
856856
if err != nil {
857857
return err
@@ -912,7 +912,7 @@ func copyFromInstanceToStdout(ctx context.Context, baseURL, apiKey, instanceID,
912912
case "header":
913913
// Flush previous file if any (but not symlinks - they have no data)
914914
if currentHeader != nil && !currentHeader.IsDir && !currentHeader.IsSymlink {
915-
if err := writeTarEntry(tw, currentHeader, fileData); err != nil {
915+
if err := writeTarEntry(tw, currentHeader, fileData, archive); err != nil {
916916
return err
917917
}
918918
fileData = nil
@@ -931,8 +931,11 @@ func copyFromInstanceToStdout(ctx context.Context, baseURL, apiKey, instanceID,
931931
Name: header.Path + "/",
932932
Mode: int64(header.Mode),
933933
ModTime: time.Unix(header.Mtime, 0),
934-
Uid: int(header.Uid),
935-
Gid: int(header.Gid),
934+
}
935+
// Only preserve UID/GID in archive mode
936+
if archive {
937+
tarHeader.Uid = int(header.Uid)
938+
tarHeader.Gid = int(header.Gid)
936939
}
937940
if err := tw.WriteHeader(tarHeader); err != nil {
938941
return fmt.Errorf("write tar dir header: %w", err)
@@ -945,8 +948,11 @@ func copyFromInstanceToStdout(ctx context.Context, baseURL, apiKey, instanceID,
945948
Linkname: header.LinkTarget,
946949
Mode: int64(header.Mode),
947950
ModTime: time.Unix(header.Mtime, 0),
948-
Uid: int(header.Uid),
949-
Gid: int(header.Gid),
951+
}
952+
// Only preserve UID/GID in archive mode
953+
if archive {
954+
tarHeader.Uid = int(header.Uid)
955+
tarHeader.Gid = int(header.Gid)
950956
}
951957
if err := tw.WriteHeader(tarHeader); err != nil {
952958
return fmt.Errorf("write tar symlink header: %w", err)
@@ -956,7 +962,7 @@ func copyFromInstanceToStdout(ctx context.Context, baseURL, apiKey, instanceID,
956962
case "end":
957963
// Write final file data if any
958964
if currentHeader != nil && !currentHeader.IsDir && !currentHeader.IsSymlink {
959-
if err := writeTarEntry(tw, currentHeader, fileData); err != nil {
965+
if err := writeTarEntry(tw, currentHeader, fileData, archive); err != nil {
960966
return err
961967
}
962968
fileData = nil
@@ -989,15 +995,18 @@ func copyFromInstanceToStdout(ctx context.Context, baseURL, apiKey, instanceID,
989995
}
990996

991997
// writeTarEntry writes a file entry to the tar archive
992-
func writeTarEntry(tw *tar.Writer, header *cpFileHeader, data []byte) error {
998+
func writeTarEntry(tw *tar.Writer, header *cpFileHeader, data []byte, archive bool) error {
993999
tarHeader := &tar.Header{
9941000
Typeflag: tar.TypeReg,
9951001
Name: header.Path,
9961002
Size: int64(len(data)),
9971003
Mode: int64(header.Mode),
9981004
ModTime: time.Unix(header.Mtime, 0),
999-
Uid: int(header.Uid),
1000-
Gid: int(header.Gid),
1005+
}
1006+
// Only preserve UID/GID in archive mode
1007+
if archive {
1008+
tarHeader.Uid = int(header.Uid)
1009+
tarHeader.Gid = int(header.Gid)
10011010
}
10021011
if err := tw.WriteHeader(tarHeader); err != nil {
10031012
return fmt.Errorf("write tar header: %w", err)

0 commit comments

Comments
 (0)