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