Skip to content
Snippets Groups Projects
Select Git revision
  • 5095f63a9fab5e8becc2c4d5f13ec4059e9cf109
  • master default protected
2 results

HepialLexer.java

Blame
  • VirtTarOut.go 1.31 KiB
    package exec
    
    import (
    	"fmt"
    	"os/exec"
    	"strings"
    	"errors"
    )
    
    const (
    	virtTarOutBinary = "virt-tar-out"
    )
    
    // Checks virt-tar-out is available.
    func CheckVirtCopyOut() error {
    	output, err := exec.Command(virtTarOutBinary, "--version").Output()
        if err != nil {
            return errors.New(virtTarOutBinary+" is required but not found. On Ubuntu/Debian, it can be installed with \"sudo apt-get install guestfish\".")
    	}
    	out := string(output)
    	lines := strings.Split(out, "\n")
    	fields := strings.Split(lines[0], " ")
    	if len(fields) < 2 {
    		return errors.New("Failed extracting "+virtTarOutBinary+" version number!")
    	}
    	cmd := fields[0]
    	if cmd != virtTarOutBinary {
    		return errors.New(virtTarOutBinary+" is required, but not found.")
    	}
    	return nil
    }
    
    // Runs virt-tar-in which unarchive a local archive into a directory (vmDir) inside the VM disk.
    
    // Runs virt-copy-out which recursively extract a directory from the VM's
    // filesystem (vmDir) into a tar archive.
    func CopyFromVM(vmDiskFile, vmDir, tarFile string) error {
    	cmd := exec.Command(virtTarOutBinary, "-a", vmDiskFile, vmDir, tarFile)
    	stdoutStderr, err := cmd.CombinedOutput()
    	if err != nil {
    		output := fmt.Sprintf("[%s]", stdoutStderr)
    		msg := "Failed reading \""+vmDir+"\" in qcow ("+vmDiskFile+"): "+output
    		log.Error(msg)
    		return errors.New(msg)
    	}
    	return nil
    }