Skip to content
Snippets Groups Projects
Commit 83114af2 authored by Florent Gluck's avatar Florent Gluck
Browse files

Files exported from a VMs are now exported as a compressed archive (.tar.gz) instead of .tar

parent d98f5639
No related branches found
No related tags found
No related merge requests found
......@@ -43,9 +43,9 @@ func CopyToVM(vmDiskFile, tarFile, vmDir string) error {
return nil
}
// Recursively copies a directory in the VM's filesystem (vmDir) into a tar archive.
// Recursively copies a directory in the VM's filesystem (vmDir) into a compressed archive.
func CopyFromVM(vmDiskFile, vmDir, tarFile string) error {
cmd := exec.Command(guestfishBinary, "--ro", "-i", "tar-out", "-a", vmDiskFile, vmDir, tarFile)
cmd := exec.Command(guestfishBinary, "--ro", "-i", "tar-out", "-a", vmDiskFile, vmDir, tarFile, "compress:gzip")
stdoutStderr, err := cmd.CombinedOutput()
if err != nil {
output := fmt.Sprintf("[%s]", stdoutStderr)
......
......@@ -378,7 +378,7 @@ func (r *RouterVMs)DeleteVMAccessForUser(c echo.Context) error {
return c.JSONPretty(http.StatusOK, jsonMsg("OK"), " ")
}
// Exports a VM's directory into a .tar archive.
// Exports a VM's directory into a compressed archive.
// Requires either capability:
// User cap: VM_READFS_ANY: any VM can have their filesystem read.
// VM access cap: VM_READFS: any of the VMs with this cap for the logged user can have their filesystem read.
......@@ -396,7 +396,7 @@ func (r *RouterVMs)ExportVMDir(c echo.Context) error {
// Creates a unique tar filename.
tmpDir := paths.GetInstance().TmpDir
tarFile := filepath.Join(tmpDir, "exportdir_"+vm.ID.String()+".tar")
tarFile := filepath.Join(tmpDir, "exportdir_"+vm.ID.String()+".tar.gz")
// Extracts VM's p.Dir directory into tarFile on the host.
if err := r.vms.ExportVMFiles(vm, p.Dir, tarFile); err != nil {
......
......@@ -7,7 +7,7 @@ import (
const (
major = 1
minor = 2
bugfix = 0
bugfix = 1
)
type Version struct {
......
......@@ -389,14 +389,14 @@ func (vms *VMs)DeleteVMAccess(vmID uuid.UUID, loggedUserEmail, userEmail string)
return nil
}
// Exports a VM's directory and its subdirectories into a tar archive on the host.
// Exports a VM's directory and its subdirectories into a compressed archive on the host.
func (vms *VMs)ExportVMFiles(vm *VM, vmDir, tarFile string) error {
vmDisk := vm.getDiskPath()
return exec.CopyFromVM(vmDisk, vmDir, tarFile)
}
// Import files into a VM's filesystem, in a specified directory.
func (vms *VMs)ImportFilesToVM(vm *VM, hostDir, vmDir string) error {
func (vms *VMs)ImportFilesToVM(vm *VM, tarFile, vmDir string) error {
// Marks the VM to copy from as being busy.
if err := vms.setDiskBusy(vm); err != nil {
return errors.New("Failed setting disk busy flag during VM files import: "+err.Error())
......@@ -405,7 +405,7 @@ func (vms *VMs)ImportFilesToVM(vm *VM, hostDir, vmDir string) error {
defer vms.clearDiskBusy(vm)
vmDisk := vm.getDiskPath()
return exec.CopyToVM(vmDisk, hostDir, vmDir)
return exec.CopyToVM(vmDisk, tarFile, vmDir)
}
// Marks a VM as "busy", meaning its disk file is being accessed for a possibly long time.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment