Skip to content

Commit

Permalink
simplify naming terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
letFunny committed Jan 16, 2024
1 parent c1eb773 commit 1441994
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion internal/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func (s *S) testOpenArchiveArch(c *C, release ubuntuRelease, arch string) {
{Path: "/hostname"},
},
},
FileCreator: fsutil.NewFileCreator(),
FileCreator: fsutil.NewCreator(),
})
c.Assert(err, IsNil)

Expand Down
2 changes: 1 addition & 1 deletion internal/deb/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ExtractOptions struct {
TargetDir string
Extract map[string][]ExtractInfo
Globbed map[string][]string
FileCreator *fsutil.FileCreator
FileCreator *fsutil.Creator
}

type ExtractInfo struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/deb/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (s *S) TestExtract(c *C) {
options := test.options
options.Package = "base-files"
options.TargetDir = dir
options.FileCreator = fsutil.NewFileCreator()
options.FileCreator = fsutil.NewCreator()

if test.globbed != nil {
options.Globbed = make(map[string][]string)
Expand Down
18 changes: 9 additions & 9 deletions internal/fsutil/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ type CreateOptions struct {
MakeParents bool
}

type FileInfo struct {
type Info struct {
Path string
Mode fs.FileMode
Hash string
Size uint
Link string
}

type FileCreator struct {
// Files keeps track of information about the files created. If a file
type Creator struct {
// Created keeps track of information about the files created. If a file
// is created several times it only tracks the latest one.
Files map[string]FileInfo
Created map[string]Info
}

func NewFileCreator() *FileCreator {
return &FileCreator{Files: make(map[string]FileInfo)}
func NewCreator() *Creator {
return &Creator{Created: make(map[string]Info)}
}

// Creates a filesystem entry according to the provided options.
func (fc FileCreator) Create(o *CreateOptions) error {
func (fc Creator) Create(o *CreateOptions) error {
rp := readerProxy{inner: o.Data, h: sha256.New()}
o.Data = &rp

Expand All @@ -64,14 +64,14 @@ func (fc FileCreator) Create(o *CreateOptions) error {
return err
}

fr := FileInfo{
fr := Info{
Path: o.Path,
Mode: o.Mode,
Hash: hex.EncodeToString(rp.h.Sum(nil)),
Size: rp.size,
Link: o.Link,
}
fc.Files[o.Path] = fr
fc.Created[o.Path] = fr
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions internal/fsutil/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *S) TestCreate(c *C) {
dir := c.MkDir()
options := test.options
options.Path = filepath.Join(dir, options.Path)
fileCreator := fsutil.NewFileCreator()
fileCreator := fsutil.NewCreator()
err := fileCreator.Create(&options)
if test.error != "" {
c.Assert(err, ErrorMatches, test.error)
Expand All @@ -103,9 +103,9 @@ func (s *S) TestCreate(c *C) {
}
}

func treeDumpFileCreator(fc *fsutil.FileCreator, root string) map[string]string {
func treeDumpFileCreator(fc *fsutil.Creator, root string) map[string]string {
result := make(map[string]string)
for _, file := range fc.Files {
for _, file := range fc.Created {
path := strings.TrimPrefix(file.Path, root)
fperm := file.Mode.Perm()
if file.Mode&fs.ModeSticky != 0 {
Expand Down
2 changes: 1 addition & 1 deletion internal/setup/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func extractTar(dataReader io.Reader, targetDir string) error {

//debugf("Extracting header: %#v", tarHeader)

err = fsutil.NewFileCreator().Create(&fsutil.CreateOptions{
err = fsutil.NewCreator().Create(&fsutil.CreateOptions{
Path: filepath.Join(targetDir, sourcePath),
Mode: tarHeader.FileInfo().Mode(),
Data: tarReader,
Expand Down
5 changes: 2 additions & 3 deletions internal/slicer/slicer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func Run(options *RunOptions) error {
archives := make(map[string]archive.Archive)
extract := make(map[string]map[string][]deb.ExtractInfo)
pathInfos := make(map[string]setup.PathInfo)

knownPaths := make(map[string]bool)

knownPaths["/"] = true
Expand Down Expand Up @@ -154,7 +153,7 @@ func Run(options *RunOptions) error {
if reader == nil {
continue
}
fileCreator := fsutil.NewFileCreator()
fileCreator := fsutil.NewCreator()
err := deb.Extract(reader, &deb.ExtractOptions{
Package: slice.Package,
Extract: extract[slice.Package],
Expand Down Expand Up @@ -214,7 +213,7 @@ func Run(options *RunOptions) error {
return fmt.Errorf("internal error: cannot extract path of kind %q", pathInfo.Kind)
}

fileCreator := fsutil.NewFileCreator()
fileCreator := fsutil.NewCreator()
err := fileCreator.Create(&fsutil.CreateOptions{
Path: targetPath,
Mode: tarHeader.FileInfo().Mode(),
Expand Down

0 comments on commit 1441994

Please sign in to comment.