From 83114af2685848a2a3644aea3a9f3a910e8792e3 Mon Sep 17 00:00:00 2001 From: Florent Gluck <florent.gluck@hesge.ch> Date: Thu, 10 Nov 2022 16:45:45 +0100 Subject: [PATCH] Files exported from a VMs are now exported as a compressed archive (.tar.gz) instead of .tar --- src/exec/Guestfish.go | 4 ++-- src/router/routerVMs.go | 4 ++-- src/version/version.go | 2 +- src/vms/vms.go | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/exec/Guestfish.go b/src/exec/Guestfish.go index 7597494..22d1c77 100644 --- a/src/exec/Guestfish.go +++ b/src/exec/Guestfish.go @@ -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) diff --git a/src/router/routerVMs.go b/src/router/routerVMs.go index 3ff8641..d8e95f9 100644 --- a/src/router/routerVMs.go +++ b/src/router/routerVMs.go @@ -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 { diff --git a/src/version/version.go b/src/version/version.go index c46ce8a..d3e7707 100644 --- a/src/version/version.go +++ b/src/version/version.go @@ -7,7 +7,7 @@ import ( const ( major = 1 minor = 2 - bugfix = 0 + bugfix = 1 ) type Version struct { diff --git a/src/vms/vms.go b/src/vms/vms.go index 109180d..278fc0b 100644 --- a/src/vms/vms.go +++ b/src/vms/vms.go @@ -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. -- GitLab