diff --git a/src/server/router/routerVMs.go b/src/server/router/routerVMs.go index 51d59d42215879574fb97054e0d4b846ecfa5369..2ba356b8fb28ba73b81e996019c685cf34b262d8 100644 --- a/src/server/router/routerVMs.go +++ b/src/server/router/routerVMs.go @@ -581,10 +581,14 @@ func (r *RouterVMs) DeleteVMAccessForUser(c echo.Context) error { // curl --cacert ca.pem -X GET https://localhost:1077/vms/e41f3556-ca24-4658-bd79-8c85bd6bff59/exportdir -H 'Content-Type: application/json' -d '{"dir":"absolute_path_to_dir"}' -H "Authorization: Bearer <AccessToken>" --output dir.tar func (r *RouterVMs) ExportVMDir(c echo.Context) error { return r.applyOnFilteredVMs(c, caps.CAP_VM_READFS_ANY, caps.CAP_VM_READFS, func(c echo.Context, vm *vms.VM) error { + vmID := vm.GetID().String() + // Deserializes and validates the client's parameter. p := new(params.VMExportDir) if err := decodeJson(c, &p); err != nil { - return echo.NewHTTPError(http.StatusBadRequest, err.Error()) + msg := "Failed extracting VM " + vmID + "'s dir: " + err.Error() + log.Error(msg) + return echo.NewHTTPError(http.StatusBadRequest, msg) } // Creates a unique tar filename. @@ -592,13 +596,15 @@ func (r *RouterVMs) ExportVMDir(c echo.Context) error { // Extracts VM's p.Dir directory into tarGzFile on the host. if err := r.vms.ExportVMFiles(vm, p.Dir, tarGzFile); err != nil { - return echo.NewHTTPError(http.StatusBadRequest, "Failed extracting VM's dir") + msg := "Failed extracting VM " + vmID + "'s dir: " + err.Error() + log.Error(msg) + return echo.NewHTTPError(http.StatusBadRequest, msg) } // Sends the archive back to the client and once completed, deletes it. defer func(file string) { 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 " + vmID + "'s dir: " + err.Error()) } }(tarGzFile) return c.File(tarGzFile) @@ -645,7 +651,7 @@ func (r *RouterVMs) ImportFilesToVM(c echo.Context) error { } // Copy the archive's files into the VM - // IMPORTANT: check the VM is NOT running! + // IMPORTANT: the VM cannot have its disk busy if err = r.vms.ImportFilesToVM(vm, uploadedtarGzFile, vmDir); err != nil { return echo.NewHTTPError(http.StatusBadRequest, err.Error()) }