Skip to content

Commit

Permalink
some ideas
Browse files Browse the repository at this point in the history
  • Loading branch information
letFunny committed Jan 21, 2025
1 parent 717fecd commit ab4ad2a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/deb/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ func extractData(pkgReader io.ReadSeeker, options *ExtractOptions) error {
delete(tarDirMode, path)

createOptions := &fsutil.CreateOptions{
Path: filepath.Join(options.TargetDir, path),
Root: options.TargetDir,
Path: path,
Mode: mode,
MakeParents: true,
}
Expand All @@ -237,7 +238,8 @@ func extractData(pkgReader io.ReadSeeker, options *ExtractOptions) error {

// Create the entry itself.
createOptions := &fsutil.CreateOptions{
Path: filepath.Join(options.TargetDir, targetPath),
Root: options.TargetDir,
Path: targetPath,
Mode: tarHeader.FileInfo().Mode(),
Data: pathReader,
Link: link,
Expand Down Expand Up @@ -342,7 +344,8 @@ func extractHardLinks(pkgReader io.ReadSeeker, opts *extractHardLinkOptions) err
absLink := filepath.Join(opts.TargetDir, links[0].path)
// Extract the content to the first hard link path.
createOptions := &fsutil.CreateOptions{
Path: absLink,
Root: opts.TargetDir,
Path: links[0].path,
Mode: tarHeader.FileInfo().Mode(),
Data: tarReader,
}
Expand All @@ -354,6 +357,9 @@ func extractHardLinks(pkgReader io.ReadSeeker, opts *extractHardLinkOptions) err
// Create the remaining hard links.
for _, link := range links[1:] {
createOptions := &fsutil.CreateOptions{
// TODO should Root also be taken into account for Link? How do
// we create relative symlinks then. We can validate that it is
// inside though and preserve Link.
Path: filepath.Join(opts.TargetDir, link.path),
Mode: tarHeader.FileInfo().Mode(),
// Link to the first file extracted for the hard links.
Expand Down
19 changes: 19 additions & 0 deletions internal/fsutil/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import (
"io/fs"
"os"
"path/filepath"
"strings"
)

type CreateOptions struct {
// Root defaults to "/" if empty.
Root string
// Path is relative to Root.
Path string
Mode fs.FileMode
Data io.Reader
Expand Down Expand Up @@ -45,6 +49,21 @@ func Create(options *CreateOptions) (*Entry, error) {
optsCopy.Data = rp
o := &optsCopy

if o.Root == "" {
o.Root = "/"
}
o.Path = filepath.Clean(filepath.Join(o.Root, o.Path))
if !strings.HasPrefix(o.Path, o.Root) {
return nil, fmt.Errorf("TODO")
}
o.Link = filepath.Clean(o.Link)
if filepath.IsAbs(o.Link) {
if !strings.HasPrefix(o.Link) {

Check failure on line 61 in internal/fsutil/create.go

View workflow job for this annotation

GitHub Actions / Spread tests

not enough arguments in call to strings.HasPrefix

Check failure on line 61 in internal/fsutil/create.go

View workflow job for this annotation

GitHub Actions / Spread tests

not enough arguments in call to strings.HasPrefix

Check failure on line 61 in internal/fsutil/create.go

View workflow job for this annotation

GitHub Actions / Unit Tests

not enough arguments in call to strings.HasPrefix

Check failure on line 61 in internal/fsutil/create.go

View workflow job for this annotation

GitHub Actions / Real Archive Tests

not enough arguments in call to strings.HasPrefix

Check failure on line 61 in internal/fsutil/create.go

View workflow job for this annotation

GitHub Actions / Real Archive Tests

not enough arguments in call to strings.HasPrefix
return nil, fmt.Errorf("TODO")
}
}
// TODO check for relative?

var err error
var hash string
if o.MakeParents {
Expand Down

0 comments on commit ab4ad2a

Please sign in to comment.