Skip to content

Commit

Permalink
Allow the entire filetree of a downloaded archive or OCI image to be …
Browse files Browse the repository at this point in the history
…exported (#208)
  • Loading branch information
ethanjli authored May 15, 2024
1 parent ef081ea commit c5e2b33
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## 0.7.2-alpha.4 - 2024-05-15

### Fixed

- (cli) Allowed the entire filetree in downloaded archives and OCI images to be used as a source for export, by specifying '/' or '.' as the source path.
- (spec) Clarified that, for the `source` field of file export resources with `source-type` `http-archive` and `oci-image`, a value of `/` or `.` will be interpreted as specifying that all files in the archive or OCI image will be exported.

## 0.7.2-alpha.3 - 2024-05-15

Expand Down
4 changes: 2 additions & 2 deletions docs/specs/00-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -1314,9 +1314,9 @@ A file export object consists of the following fields:

- For the `http` source type, the source path is ignored.

- For the `http-archive` source type, the source path is interpreted as being relative to the root of the archive.
- For the `http-archive` source type, the source path is interpreted as being relative to the root of the archive. If the source path is "." or "/", all files in the archive will be exported.

- For the `oci-image` source type, the source path is interpreted as being relative to the root of the container image's filesystem.
- For the `oci-image` source type, the source path is interpreted as being relative to the root of the container image's filesystem. If the source path is "." or "/", all files in the container image will be exported.

- Example:

Expand Down
7 changes: 5 additions & 2 deletions internal/app/forklift/bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@ func determineFileType(
}

func extractFile(tarReader *tar.Reader, sourcePath string, exportPath string) error {
// var sourcefile *fs.File
if sourcePath == "/" || sourcePath == "." {
sourcePath = ""
}
fmt.Printf("exporting into %s...\n", exportPath)
for {
header, err := tarReader.Next()
Expand All @@ -376,7 +378,8 @@ func extractFile(tarReader *tar.Reader, sourcePath string, exportPath string) er
if err != nil {
return err
}
if sourcePath != header.Name && !strings.HasPrefix(header.Name, sourcePath+"/") {
if sourcePath != "" && sourcePath != header.Name &&
!strings.HasPrefix(header.Name, sourcePath+"/") {
continue
}
targetPath := path.Join(exportPath, strings.TrimPrefix(header.Name, sourcePath))
Expand Down

0 comments on commit c5e2b33

Please sign in to comment.