@ -23,18 +23,11 @@ type Firefox struct {
var ErrProfilePathNotFound = errors . New ( "profile path not found" )
// New returns a new Firefox instance.
func New ( name , storage , profilePath string , items [ ] item . Item ) ( [ ] * Firefox , error ) {
f := & Firefox {
name : name ,
storage : storage ,
profilePath : profilePath ,
items : items ,
}
multiItemPaths , err := f . getMultiItemPath ( f . profilePath , f . items )
if err != nil {
return nil , err
}
// New returns new Firefox instances.
func New ( profilePath string , items [ ] item . Item ) ( [ ] * Firefox , error ) {
multiItemPaths := make ( map [ string ] map [ item . Item ] string )
// ignore walk dir error since it can be produced by a single entry
_ = filepath . WalkDir ( profilePath , firefoxWalkFunc ( items , multiItemPaths ) )
firefoxList := make ( [ ] * Firefox , 0 , len ( multiItemPaths ) )
for name , itemPaths := range multiItemPaths {
@ -44,13 +37,8 @@ func New(name, storage, profilePath string, items []item.Item) ([]*Firefox, erro
itemPaths : itemPaths ,
} )
}
return firefoxList , nil
}
func ( f * Firefox ) getMultiItemPath ( profilePath string , items [ ] item . Item ) ( map [ string ] map [ item . Item ] string , error ) {
multiItemPaths := make ( map [ string ] map [ item . Item ] string )
err := filepath . Walk ( profilePath , firefoxWalkFunc ( items , multiItemPaths ) )
return multiItemPaths , err
return firefoxList , nil
}
func ( f * Firefox ) copyItemToLocal ( ) error {
@ -63,8 +51,8 @@ func (f *Firefox) copyItemToLocal() error {
return nil
}
func firefoxWalkFunc ( items [ ] item . Item , multiItemPaths map [ string ] map [ item . Item ] string ) filepath . WalkFunc {
return func ( path string , info fs . FileInfo , err error ) error {
func firefoxWalkFunc ( items [ ] item . Item , multiItemPaths map [ string ] map [ item . Item ] string ) fs . WalkDir Func {
return func ( path string , info fs . DirEntry , err error ) error {
for _ , v := range items {
if info . Name ( ) == v . FileName ( ) {
parentBaseDir := fileutil . ParentBaseDir ( path )
@ -75,6 +63,7 @@ func firefoxWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]
}
}
}
return err
}
}