Skip to content

Commit 68d4e18

Browse files
committed
fix: add defer cleanup for file handles, fix symlink permissions with followLinks
1 parent 1c65795 commit 68d4e18

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/guest/client.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,13 @@ func CopyFromInstance(ctx context.Context, vsockSocketPath string, opts CopyFrom
467467
var currentFile *os.File
468468
var currentHeader *CopyFromGuestHeader
469469

470+
// Ensure file is closed on error paths
471+
defer func() {
472+
if currentFile != nil {
473+
currentFile.Close()
474+
}
475+
}()
476+
470477
for {
471478
resp, err := stream.Recv()
472479
if err == io.EOF {

lib/system/guest_agent/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,14 @@ func (s *guestServer) copyFromGuestDir(rootPath string, followLinks bool, stream
640640
return nil
641641
}
642642

643-
info, err := d.Info()
643+
// Use os.Stat when followLinks is true to get the target's info
644+
// Use d.Info() (same as os.Lstat) when followLinks is false to get symlink's info
645+
var info os.FileInfo
646+
if followLinks {
647+
info, err = os.Stat(path)
648+
} else {
649+
info, err = d.Info()
650+
}
644651
if err != nil {
645652
stream.Send(&pb.CopyFromGuestResponse{
646653
Response: &pb.CopyFromGuestResponse_Error{

0 commit comments

Comments
 (0)