Skip to content

Commit 19c001c

Browse files
fix: allow o.PullPath to pull paths with sub directories (#175)
## Description There is currently an issue in `o.pullPath` that forces users to create the entire path ahead of time before pulling an image. This can be problematic for layers that define a multi directory path such as `components/baseline.tar`. The caller would have to know to create the `components` directory ahead of time. Signed-off-by: Austin Abro <[email protected]>
1 parent a5dcbb3 commit 19c001c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

oci/oci_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ func (suite *OCISuite) TestCopyToTarget() {
143143
func (suite *OCISuite) TestPulledPaths() {
144144
ctx := context.TODO()
145145
srcTempDir := suite.T().TempDir()
146-
files := []string{"firstFile", "secondFile"}
146+
err := helpers.CreateDirectory(filepath.Join(srcTempDir, "subdir"), helpers.ReadExecuteAllWriteUser)
147+
suite.NoError(err)
148+
files := []string{"firstFile", filepath.Join("subdir", "secondFile")}
147149

148150
var descs []ocispec.Descriptor
149151
src, err := file.New(srcTempDir)

oci/pull.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ func (o *OrasRemote) PullPath(ctx context.Context, destinationDir string, desc o
9696
return errors.New("failed to pull layer: layer is not a file")
9797
}
9898

99-
return os.WriteFile(filepath.Join(destinationDir, rel), b, helpers.ReadWriteUser)
99+
fullPath := filepath.Join(destinationDir, rel)
100+
dirPath := filepath.Dir(fullPath)
101+
if err := helpers.CreateDirectory(dirPath, helpers.ReadExecuteAllWriteUser); err != nil {
102+
return err
103+
}
104+
105+
return os.WriteFile(fullPath, b, helpers.ReadWriteUser)
100106
}
101107

102108
// PullPaths pulls multiple files from the remote repository and saves them to `destinationDir`.

0 commit comments

Comments
 (0)