Compare commits

..

No commits in common. 'master' and 'static/update-logo' have entirely different histories.

  1. 17
      CONTRIBUTORS.svg
  2. 6
      browser/browser.go
  3. 29
      browser/firefox/firefox.go
  4. 1
      cmd/hack-browser-data/main.go

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 2.7 MiB

After

Width:  |  Height:  |  Size: 2.7 MiB

@ -87,13 +87,11 @@ func pickFirefox(name, profile string) []Browser {
} else {
profile = fileutil.ParentDir(profile)
}
if !fileutil.IsDirExists(filepath.Clean(profile)) {
log.Noticef("find browser firefox %s failed, profile folder does not exist", v.name)
continue
}
if multiFirefox, err := firefox.New(profile, v.items); err == nil {
if multiFirefox, err := firefox.New(v.name, v.storage, profile, v.items); err == nil {
for _, b := range multiFirefox {
log.Noticef("find browser firefox %s success", b.Name())
browsers = append(browsers, b)
@ -102,10 +100,8 @@ func pickFirefox(name, profile string) []Browser {
log.Error(err)
}
}
return browsers
}
return nil
}

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

@ -53,7 +53,6 @@ func Execute() {
data, err := b.BrowsingData(isFullExport)
if err != nil {
log.Error(err)
continue
}
data.Output(outputDir, b.Name(), outputFormat)
}

Loading…
Cancel
Save