Skip to content

Commit ac1c771

Browse files
committedJan 6, 2025·
fix: govc: import.ovf remote support regression
- Fix regression introduced in 36ee9a1 / PR #3596 - Add test for remote import.ovf Signed-off-by: Doug MacEachern <dougm@broadcom.com>
1 parent 4eab163 commit ac1c771

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed
 

‎govc/test/import.bats

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ load test_helper
1717

1818
# link ovf/ova to datastore so we can test with an http source
1919
dir=$(govc datastore.info -json | jq -r .datastores[].info.url)
20-
ln -s "$GOVC_IMAGES/$TTYLINUX_NAME."* "$dir"
20+
ln -s "$GOVC_IMAGES/$TTYLINUX_NAME"* "$dir"
2121

2222
run govc import.spec "https://$(govc env GOVC_URL)/folder/$TTYLINUX_NAME.ovf"
2323
assert_success
@@ -28,6 +28,12 @@ load test_helper
2828
proto=$(jq -r .IPProtocol <<<"$output")
2929
assert_equal IPv4 "$proto"
3030

31+
run govc import.ovf "https://$(govc env GOVC_URL)/folder/$TTYLINUX_NAME.ovf"
32+
assert_success
33+
34+
run govc vm.destroy "$TTYLINUX_NAME"
35+
assert_success
36+
3137
run govc import.ova -verbose "https://$(govc env GOVC_URL)/folder/$TTYLINUX_NAME.ova"
3238
assert_success
3339

‎ovf/importer/archive.go

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package importer
186

@@ -112,8 +100,15 @@ type FileArchive struct {
112100

113101
func (t *FileArchive) Open(name string) (io.ReadCloser, int64, error) {
114102
fpath := name
115-
if name != t.Path && !filepath.IsAbs(name) {
116-
fpath = filepath.Join(filepath.Dir(t.Path), name)
103+
if name != t.Path {
104+
if IsRemotePath(t.Path) {
105+
index := strings.LastIndex(t.Path, "/")
106+
if index != -1 {
107+
fpath = t.Path[:index] + "/" + name
108+
}
109+
} else if !filepath.IsAbs(name) {
110+
fpath = filepath.Join(filepath.Dir(t.Path), name)
111+
}
117112
}
118113

119114
return t.OpenFile(fpath)

0 commit comments

Comments
 (0)
Please sign in to comment.