Compare commits

...

3 Commits

Author SHA1 Message Date
github-actions[bot] ecb8db1854
chore: update contributors [skip ci] 1 year ago
Andrii Ursulenko ab4d3e14db
fix: nil browsing data in case error and walkdir instead of walk (#229) 1 year ago
ᴍᴏᴏɴD4ʀᴋ a2c3cd1090
Merge pull request #227 from moonD4rk/static/update-logo 1 year ago
  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,11 +87,13 @@ func pickFirefox(name, profile string) []Browser {
} else { } else {
profile = fileutil.ParentDir(profile) profile = fileutil.ParentDir(profile)
} }
if !fileutil.IsDirExists(filepath.Clean(profile)) { if !fileutil.IsDirExists(filepath.Clean(profile)) {
log.Noticef("find browser firefox %s failed, profile folder does not exist", v.name) log.Noticef("find browser firefox %s failed, profile folder does not exist", v.name)
continue continue
} }
if multiFirefox, err := firefox.New(v.name, v.storage, profile, v.items); err == nil {
if multiFirefox, err := firefox.New(profile, v.items); err == nil {
for _, b := range multiFirefox { for _, b := range multiFirefox {
log.Noticef("find browser firefox %s success", b.Name()) log.Noticef("find browser firefox %s success", b.Name())
browsers = append(browsers, b) browsers = append(browsers, b)
@ -100,8 +102,10 @@ func pickFirefox(name, profile string) []Browser {
log.Error(err) log.Error(err)
} }
} }
return browsers return browsers
} }
return nil return nil
} }

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

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

Loading…
Cancel
Save