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

- archive uploaded via vmimportdir is now compressed (gz), thus udpated code...

- archive uploaded via vmimportdir is now compressed (gz), thus udpated code to decompress it properly
- bumpped version to 1.4.0
parent daaa50c6
No related branches found
No related tags found
No related merge requests found
...@@ -30,9 +30,9 @@ func CheckGuestfish() error { ...@@ -30,9 +30,9 @@ func CheckGuestfish() error {
return nil return nil
} }
// Copies and unarchives a local archive into a directory (vmDir) inside the VM's filesystem. // Copies and unarchives a local tar.gz archive into a directory (vmDir) inside the VM's filesystem.
func CopyToVM(vmDiskFile, tarFile, vmDir string) error { func CopyToVM(vmDiskFile, tarGzFile, vmDir string) error {
cmd := exec.Command(guestfishBinary, "--rw", "-i", "tar-in", "-a", vmDiskFile, tarFile, vmDir) cmd := exec.Command(guestfishBinary, "--rw", "-i", "tar-in", "-a", vmDiskFile, tarGzFile, vmDir, "compress:gzip")
stdoutStderr, err := cmd.CombinedOutput() stdoutStderr, err := cmd.CombinedOutput()
if err != nil { if err != nil {
output := fmt.Sprintf("[%s]", stdoutStderr) output := fmt.Sprintf("[%s]", stdoutStderr)
...@@ -43,9 +43,9 @@ func CopyToVM(vmDiskFile, tarFile, vmDir string) error { ...@@ -43,9 +43,9 @@ func CopyToVM(vmDiskFile, tarFile, vmDir string) error {
return nil return nil
} }
// Recursively copies a directory in the VM's filesystem (vmDir) into a compressed archive. // Recursively copies a directory in the VM's filesystem (vmDir) into a tar.gz archive.
func CopyFromVM(vmDiskFile, vmDir, tarFile string) error { func CopyFromVM(vmDiskFile, vmDir, tarGzFile string) error {
cmd := exec.Command(guestfishBinary, "--ro", "-i", "tar-out", "-a", vmDiskFile, vmDir, tarFile, "compress:gzip") cmd := exec.Command(guestfishBinary, "--ro", "-i", "tar-out", "-a", vmDiskFile, vmDir, tarGzFile, "compress:gzip")
stdoutStderr, err := cmd.CombinedOutput() stdoutStderr, err := cmd.CombinedOutput()
if err != nil { if err != nil {
output := fmt.Sprintf("[%s]", stdoutStderr) output := fmt.Sprintf("[%s]", stdoutStderr)
......
...@@ -396,10 +396,10 @@ func (r *RouterVMs)ExportVMDir(c echo.Context) error { ...@@ -396,10 +396,10 @@ func (r *RouterVMs)ExportVMDir(c echo.Context) error {
// Creates a unique tar filename. // Creates a unique tar filename.
tmpDir := paths.GetInstance().TmpDir tmpDir := paths.GetInstance().TmpDir
tarFile := filepath.Join(tmpDir, "exportdir_"+vm.ID.String()+".tar.gz") tarGzFile := filepath.Join(tmpDir, "exportdir_"+vm.ID.String()+".tar.gz")
// Extracts VM's p.Dir directory into tarFile on the host. // Extracts VM's p.Dir directory into tarGzFile on the host.
if err := r.vms.ExportVMFiles(vm, p.Dir, tarFile); err != nil { if err := r.vms.ExportVMFiles(vm, p.Dir, tarGzFile); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Failed extracting VM's dir") return echo.NewHTTPError(http.StatusBadRequest, "Failed extracting VM's dir")
} }
...@@ -408,12 +408,12 @@ func (r *RouterVMs)ExportVMDir(c echo.Context) error { ...@@ -408,12 +408,12 @@ func (r *RouterVMs)ExportVMDir(c echo.Context) error {
if err := os.Remove(file); err != nil { if err := os.Remove(file); err != nil {
log.Error("Failed removing archive of extracted VM dir: "+err.Error()) log.Error("Failed removing archive of extracted VM dir: "+err.Error())
} }
}(tarFile) }(tarGzFile)
return c.File(tarFile) return c.File(tarGzFile)
}) })
} }
// Import files into a VM's filesystem, in a specified directory. The file tree is received in a .tar archive. // Import files into a VM's filesystem, in a specified directory. The file tree is received in a tar.gz archive.
// Requires either capability: // Requires either capability:
// User cap: VM_WRITEFS_ANY: any VM can import the file tree. // User cap: VM_WRITEFS_ANY: any VM can import the file tree.
// VM access cap: VM_WRITEFS: any of the VMs with this cap for the logged user can import the file tree. // VM access cap: VM_WRITEFS: any of the VMs with this cap for the logged user can import the file tree.
...@@ -423,13 +423,13 @@ func (r *RouterVMs)ImportFilesToVM(c echo.Context) error { ...@@ -423,13 +423,13 @@ func (r *RouterVMs)ImportFilesToVM(c echo.Context) error {
// Retrieves the various client arguments. // Retrieves the various client arguments.
vmDir := c.FormValue("vmDir") vmDir := c.FormValue("vmDir")
// Retrieves the tar archive (uploadedTarFile). // Retrieves the tar.gz archive (uploadedtarGzFile).
tarFile, err := c.FormFile("file") tarGzFile, err := c.FormFile("file")
if err != nil { if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
} }
src, err := tarFile.Open() src, err := tarGzFile.Open()
if err != nil { if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
} }
...@@ -441,13 +441,13 @@ func (r *RouterVMs)ImportFilesToVM(c echo.Context) error { ...@@ -441,13 +441,13 @@ func (r *RouterVMs)ImportFilesToVM(c echo.Context) error {
log.Error("Failed creating random UUID: "+err.Error()) log.Error("Failed creating random UUID: "+err.Error())
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
} }
uploadedTarFile := filepath.Join(tmpDir, "upload_"+uuid.String()+".tar") uploadedtarGzFile := filepath.Join(tmpDir, "upload_"+uuid.String()+".tar")
dst, err := os.Create(uploadedTarFile) dst, err := os.Create(uploadedtarGzFile)
if err != nil { if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
} }
defer dst.Close() defer dst.Close()
defer os.Remove(uploadedTarFile) defer os.Remove(uploadedtarGzFile)
if _, err = io.Copy(dst, src); err != nil { if _, err = io.Copy(dst, src); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
...@@ -455,7 +455,7 @@ func (r *RouterVMs)ImportFilesToVM(c echo.Context) error { ...@@ -455,7 +455,7 @@ func (r *RouterVMs)ImportFilesToVM(c echo.Context) error {
// Copy the archive's files into the VM // Copy the archive's files into the VM
// IMPORTANT: check the VM is NOT running! // IMPORTANT: check the VM is NOT running!
if err = r.vms.ImportFilesToVM(vm, uploadedTarFile, vmDir); err != nil { if err = r.vms.ImportFilesToVM(vm, uploadedtarGzFile, vmDir); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error()) return echo.NewHTTPError(http.StatusBadRequest, err.Error())
} }
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
const ( const (
major = 1 major = 1
minor = 3 minor = 4
bugfix = 0 bugfix = 0
) )
......
...@@ -389,14 +389,14 @@ func (vms *VMs)DeleteVMAccess(vmID uuid.UUID, loggedUserEmail, userEmail string) ...@@ -389,14 +389,14 @@ func (vms *VMs)DeleteVMAccess(vmID uuid.UUID, loggedUserEmail, userEmail string)
return nil return nil
} }
// Exports a VM's directory and its subdirectories into a compressed archive on the host. // Exports a VM's directory and its subdirectories into a tar.gz archive on the host.
func (vms *VMs)ExportVMFiles(vm *VM, vmDir, tarFile string) error { func (vms *VMs)ExportVMFiles(vm *VM, vmDir, tarGzFile string) error {
vmDisk := vm.getDiskPath() vmDisk := vm.getDiskPath()
return exec.CopyFromVM(vmDisk, vmDir, tarFile) return exec.CopyFromVM(vmDisk, vmDir, tarGzFile)
} }
// Import files into a VM's filesystem, in a specified directory. // Imports files from a tar.gz archive into a VM's filesystem, in a specified directory.
func (vms *VMs)ImportFilesToVM(vm *VM, tarFile, vmDir string) error { func (vms *VMs)ImportFilesToVM(vm *VM, tarGzFile, vmDir string) error {
// Marks the VM to copy from as being busy. // Marks the VM to copy from as being busy.
if err := vms.setDiskBusy(vm); err != nil { if err := vms.setDiskBusy(vm); err != nil {
return errors.New("Failed setting disk busy flag during VM files import: "+err.Error()) return errors.New("Failed setting disk busy flag during VM files import: "+err.Error())
...@@ -405,7 +405,7 @@ func (vms *VMs)ImportFilesToVM(vm *VM, tarFile, vmDir string) error { ...@@ -405,7 +405,7 @@ func (vms *VMs)ImportFilesToVM(vm *VM, tarFile, vmDir string) error {
defer vms.clearDiskBusy(vm) defer vms.clearDiskBusy(vm)
vmDisk := vm.getDiskPath() vmDisk := vm.getDiskPath()
return exec.CopyToVM(vmDisk, tarFile, vmDir) return exec.CopyToVM(vmDisk, tarGzFile, vmDir)
} }
// Marks a VM as "busy", meaning its disk file is being accessed for a possibly long time. // 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