Skip to content

Commit

Permalink
teereader test
Browse files Browse the repository at this point in the history
Signed-off-by: Bella Khizgiyaev <[email protected]>
  • Loading branch information
bkhizgiy committed May 20, 2024
1 parent b95bd5f commit be9cc05
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions virt-v2v/cold/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,45 +209,46 @@ func executeVirtV2v(source string, args []string) (err error) {
virtV2vMonitorCmd.Stdout = os.Stdout
virtV2vMonitorCmd.Stderr = os.Stderr

var teeErr io.Reader
if source == OVA {
virtV2vStderrPipe, err := virtV2vMonitorCmd.StderrPipe()
if err != nil {
fmt.Printf("Error setting up stdout pipe: %v\n", err)
return err
}
teeErr = io.TeeReader(virtV2vStderrPipe, os.Stdout)
}

if err = virtV2vMonitorCmd.Start(); err != nil {
fmt.Printf("Error executing monitor command: %v\n", err)
return
}

done := make(chan error, 1)
go func() {
if source == OVA {
scanner := bufio.NewScanner(r)
const maxCapacity = 1024 * 1024
buf := make([]byte, 0, 64*1024)
scanner.Buffer(buf, maxCapacity)

for scanner.Scan() {
line := scanner.Bytes()
if match := UEFI_RE.FindSubmatch(line); match != nil {
fmt.Println("UEFI firmware detected")
firmware = "efi"
}
if source == OVA {
scanner := bufio.NewScanner(teeErr)
const maxCapacity = 1024 * 1024
buf := make([]byte, 0, 64*1024)
scanner.Buffer(buf, maxCapacity)

for scanner.Scan() {
line := scanner.Bytes()
if match := UEFI_RE.FindSubmatch(line); match != nil {
fmt.Println("UEFI firmware detected")
firmware = "efi"
}
}

if err := scanner.Err(); err != nil {
fmt.Println("Output query failed:", err)
done <- err
return
}
if err = scanner.Err(); err != nil {
fmt.Println("Output query failed:", err)
return
}
done <- nil
}()
}

if err = virtV2vCmd.Wait(); err != nil {
fmt.Printf("Error waiting for virt-v2v to finish: %v\n", err)
return
}
w.Close()

if err = <-done; err != nil {
return err
}
return
}

Expand Down

0 comments on commit be9cc05

Please sign in to comment.