diff --git a/govc/test/import.bats b/govc/test/import.bats index 40979fa5d..2ea00e5f1 100755 --- a/govc/test/import.bats +++ b/govc/test/import.bats @@ -17,7 +17,7 @@ load test_helper # link ovf/ova to datastore so we can test with an http source dir=$(govc datastore.info -json | jq -r .datastores[].info.url) - ln -s "$GOVC_IMAGES/$TTYLINUX_NAME."* "$dir" + ln -s "$GOVC_IMAGES/$TTYLINUX_NAME"* "$dir" run govc import.spec "https://$(govc env GOVC_URL)/folder/$TTYLINUX_NAME.ovf" assert_success @@ -28,6 +28,12 @@ load test_helper proto=$(jq -r .IPProtocol <<<"$output") assert_equal IPv4 "$proto" + run govc import.ovf "https://$(govc env GOVC_URL)/folder/$TTYLINUX_NAME.ovf" + assert_success + + run govc vm.destroy "$TTYLINUX_NAME" + assert_success + run govc import.ova -verbose "https://$(govc env GOVC_URL)/folder/$TTYLINUX_NAME.ova" assert_success diff --git a/ovf/importer/archive.go b/ovf/importer/archive.go index ee76b1940..a6cc9ef1c 100644 --- a/ovf/importer/archive.go +++ b/ovf/importer/archive.go @@ -1,18 +1,6 @@ -/* -Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ +// © Broadcom. All Rights Reserved. +// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +// SPDX-License-Identifier: Apache-2.0 package importer @@ -112,8 +100,15 @@ type FileArchive struct { func (t *FileArchive) Open(name string) (io.ReadCloser, int64, error) { fpath := name - if name != t.Path && !filepath.IsAbs(name) { - fpath = filepath.Join(filepath.Dir(t.Path), name) + if name != t.Path { + if IsRemotePath(t.Path) { + index := strings.LastIndex(t.Path, "/") + if index != -1 { + fpath = t.Path[:index] + "/" + name + } + } else if !filepath.IsAbs(name) { + fpath = filepath.Join(filepath.Dir(t.Path), name) + } } return t.OpenFile(fpath)