fix: Improve error handling if walk browser profile dir

- Implement error handling for path permission errors in `chromiumWalkFunc`
- Refactor `firefoxWalkFunc` to handle permission errors and log warnings
- Add import statement for `log/slog` in `firefox/firefox.go`
This commit is contained in:
moonD4rk
2024-07-15 18:05:01 +08:00
committed by ᴍᴏᴏɴD4ʀᴋ
parent 940e960932
commit 5dcf1e163b
2 changed files with 18 additions and 2 deletions
+9 -1
View File
@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io/fs"
"log/slog"
"os"
"path/filepath"
@@ -59,6 +60,13 @@ func (f *Firefox) copyItemToLocal() error {
func firefoxWalkFunc(items []types.DataType, multiItemPaths map[string]map[types.DataType]string) fs.WalkDirFunc {
return func(path string, info fs.DirEntry, err error) error {
if err != nil {
if os.IsPermission(err) {
slog.Warn("skipping walk firefox path permission error", "path", path, "err", err)
return nil
}
return err
}
for _, v := range items {
if info.Name() == v.Filename() {
parentBaseDir := fileutil.ParentBaseDir(path)
@@ -70,7 +78,7 @@ func firefoxWalkFunc(items []types.DataType, multiItemPaths map[string]map[types
}
}
return err
return nil
}
}