Skip to content

Commit

Permalink
fix: govc: import.ovf remote support regression
Browse files Browse the repository at this point in the history
- Fix regression introduced in 36ee9a1 / PR #3596
- Add test for remote import.ovf

Signed-off-by: Doug MacEachern <dougm@broadcom.com>
  • Loading branch information
dougm committed Jan 7, 2025
1 parent 95396cd commit 1de5fbf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
8 changes: 7 additions & 1 deletion govc/test/import.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
29 changes: 12 additions & 17 deletions ovf/importer/archive.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1de5fbf

Please sign in to comment.