-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify reader code to work on unzipped results as well
The code for the results reader was made to read the tarball without opening it but it should also work on unzipped results. This allows more reuse of the methods, a centralized place to put results structure information, and will allow us to expand `results` to process an unzipped directory as well. Since the extra work was minimal and it served as a good test, I also modified the results command to accept a directory. Signed-off-by: John Schnake <jschnake@vmware.com>
- Loading branch information
1 parent
6cf7519
commit 0138be0
Showing
7 changed files
with
279 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//go:build aix || darwin || dragonfly || freebsd || (js && wasm) || linux || nacl || netbsd || openbsd || solaris | ||
// +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris | ||
|
||
/* | ||
Copyright 2018 Heptio Inc. | ||
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. | ||
*/ | ||
|
||
package results | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"syscall" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
// fileInfoToReader takes the given FileInfo object and tries to return a reader | ||
// for the data. In the case of normal FileInfo objects (e.g. from os.Stat()) | ||
// you need to provide the full path to the file so it can be opened since the | ||
// FileInfo object only contains the name but not the directory. | ||
func fileInfoToReader(info os.FileInfo, path string) (io.Reader, error) { | ||
switch v := info.Sys().(type) { | ||
case io.Reader: | ||
return info.Sys().(io.Reader), nil | ||
case syscall.Stat_t, *syscall.Stat_t: | ||
f, err := os.Open(path) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "unable to open path %v", path) | ||
} | ||
return f, nil | ||
default: | ||
return nil, fmt.Errorf("info.Sys() (name=%v) is type %v and unable to be used as an io.Reader", info.Name(), v) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
/* | ||
Copyright 2018 Heptio Inc. | ||
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. | ||
*/ | ||
|
||
package results | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
) | ||
|
||
// fileInfoToReader takes the given FileInfo object and tries to return a reader | ||
// for the data. In the case of normal FileInfo objects (e.g. from os.Stat()) | ||
// you need to provide the full path to the file so it can be opened since the | ||
// FileInfo object only contains the name but not the directory. | ||
func fileInfoToReader(info os.FileInfo, path string) (io.Reader, error) { | ||
switch v := info.Sys().(type) { | ||
case io.Reader: | ||
return info.Sys().(io.Reader), nil | ||
default: | ||
return nil, fmt.Errorf("info.Sys() (name=%v) is type %v and unable to be used as an io.Reader", info.Name(), v) | ||
} | ||
} |
Oops, something went wrong.