diff --git a/box.go b/box.go index 54b0840..b0b5d34 100644 --- a/box.go +++ b/box.go @@ -32,7 +32,7 @@ type Box interface { } type Iterable interface { - ForEach(common.FilePredicate, func(string, common.FileInfo) error) error + ForEach(common.FilePredicate, func(common.FileInfo) error) error } func OpenBox(base ...string) (Box, error) { diff --git a/box/fs/box.go b/box/fs/box.go index bc3d6cd..9bfc98f 100644 --- a/box/fs/box.go +++ b/box/fs/box.go @@ -83,7 +83,7 @@ func (instance *Box) Info(name string) (common.FileInfo, error) { } } -func (instance *Box) ForEach(predicate common.FilePredicate, callback func(string, common.FileInfo) error) error { +func (instance *Box) ForEach(predicate common.FilePredicate, callback func(common.FileInfo) error) error { base, err := filepath.Abs(instance.base) if err != nil { return fmt.Errorf("cannot iterate over box %s: %v", instance.base, err) @@ -112,7 +112,7 @@ func (instance *Box) ForEach(predicate common.FilePredicate, callback func(strin return nil } } - return callback(p, &fileInfo{info, p}) + return callback(&fileInfo{info, p}) }); err != nil { return fmt.Errorf("cannot iterate over box %s: %v", instance.base, err) } diff --git a/box/packed/box.go b/box/packed/box.go index 41e6039..878404f 100644 --- a/box/packed/box.go +++ b/box/packed/box.go @@ -84,7 +84,7 @@ func (instance *Box) Close() error { return nil } -func (instance *Box) ForEach(predicate common.FilePredicate, callback func(string, common.FileInfo) error) error { +func (instance *Box) ForEach(predicate common.FilePredicate, callback func(common.FileInfo) error) error { for p, e := range instance.Entries { if predicate != nil { if ok, err := predicate(p); err != nil { @@ -93,7 +93,7 @@ func (instance *Box) ForEach(predicate common.FilePredicate, callback func(strin continue } } - if err := callback(p, e); err != nil { + if err := callback(e); err != nil { return err } } diff --git a/combined.go b/combined.go index 9ed7b67..b3eebe2 100644 --- a/combined.go +++ b/combined.go @@ -59,7 +59,7 @@ func (instance CombinedBox) Close() error { } } -func (instance CombinedBox) ForEach(predicate common.FilePredicate, callback func(string, common.FileInfo) error) error { +func (instance CombinedBox) ForEach(predicate common.FilePredicate, callback func(common.FileInfo) error) error { for _, box := range instance { if ib, ok := box.(Iterable); ok { if err := ib.ForEach(predicate, callback); err != nil { diff --git a/main/catCommand.go b/main/catCommand.go index 02d2a9b..8f98be0 100644 --- a/main/catCommand.go +++ b/main/catCommand.go @@ -2,6 +2,7 @@ package main import ( "github.com/echocat/goxr/box/packed" + "github.com/echocat/goxr/common" "github.com/echocat/goxr/log" "github.com/urfave/cli" "io" @@ -52,15 +53,15 @@ func (instance *CatCommand) ExecuteFromCli(_ *cli.Context) error { WithField("builtBy", box.BuiltBy). Infof("Displaying of %s...", instance.Filename) - return box.ForEach(instance.FilePredicate, func(path string, info os.FileInfo) error { - l.Infof(" %s", path) - return instance.displayEntry(path, info, box) + return box.ForEach(instance.FilePredicate, func(info common.FileInfo) error { + l.Infof(" %s", info.Path()) + return instance.displayEntry(info, box) }) }) } -func (instance *CatCommand) displayEntry(path string, _ os.FileInfo, box *packed.Box) error { - f, err := box.Open(path) +func (instance *CatCommand) displayEntry(info common.FileInfo, box *packed.Box) error { + f, err := box.Open(info.Path()) if err != nil { return err } diff --git a/main/listCommand.go b/main/listCommand.go index 5f9c574..09c08c9 100644 --- a/main/listCommand.go +++ b/main/listCommand.go @@ -2,9 +2,9 @@ package main import ( "github.com/echocat/goxr/box/packed" + "github.com/echocat/goxr/common" "github.com/echocat/goxr/log" "github.com/urfave/cli" - "os" "regexp" "time" ) @@ -51,8 +51,8 @@ func (instance *ListCommand) ExecuteFromCli(*cli.Context) error { WithField("builtBy", box.BuiltBy). Infof("Entries of %s...", instance.Filename) - return box.ForEach(instance.FilePredicate, func(path string, info os.FileInfo) error { - l.Infof(" %-30s (size: %10d, modified: %v, mod: %v)", path, info.Size(), info.ModTime().Truncate(time.Second), info.Mode()) + return box.ForEach(instance.FilePredicate, func(info common.FileInfo) error { + l.Infof(" %-30s (size: %10d, modified: %v, mod: %v)", info.Path(), info.Size(), info.ModTime().Truncate(time.Second), info.Mode()) return nil }) })