Skip to content

Commit b7821d4

Browse files
committed
fix: check copy dir with filename suffix
1 parent 54ad02f commit b7821d4

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

internal/browser/chromium/chromium.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"hack-browser-data/internal/browingdata"
99
"hack-browser-data/internal/item"
10-
"hack-browser-data/internal/log"
1110
"hack-browser-data/internal/utils/fileutil"
1211
"hack-browser-data/internal/utils/typeutil"
1312
)
@@ -70,7 +69,7 @@ func (c *chromium) copyItemToLocal() error {
7069
err = fileutil.CopyDir(path, filename, "lock")
7170
}
7271
if i == item.ChromiumExtension {
73-
err = fileutil.CopyDirContains(path, filename, "manifest.json")
72+
err = fileutil.CopyDirHasSuffix(path, filename, "manifest.json")
7473
}
7574
default:
7675
err = fileutil.CopyFile(path, filename)
@@ -86,8 +85,6 @@ func (c *chromium) getItemPath(profilePath string, items []item.Item) (map[item.
8685
var itemPaths = make(map[item.Item]string)
8786
parentDir := fileutil.ParentDir(profilePath)
8887
baseDir := fileutil.BaseDir(profilePath)
89-
log.Infof("%s profile parentDir: %s", c.name, parentDir)
90-
log.Infof("%s profile baseDir: %s", c.name, baseDir)
9188
err := filepath.Walk(parentDir, chromiumWalkFunc(items, itemPaths, baseDir))
9289
if err != nil {
9390
return itemPaths, err

internal/utils/fileutil/filetutil.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ func FolderExists(foldername string) bool {
3838
return info.IsDir()
3939
}
4040

41-
// FilesInFolder returns the files contains in the provided folder
41+
// FilesInFolder returns the filepath contains in the provided folder
4242
func FilesInFolder(dir, filename string) ([]string, error) {
4343
if !FolderExists(dir) {
4444
return nil, errors.New(dir + " folder does not exist")
4545
}
4646
var files []string
4747
err := filepath.Walk(dir, func(path string, f os.FileInfo, err error) error {
48-
if !f.IsDir() && strings.Contains(path, filename) {
48+
if !f.IsDir() && strings.HasSuffix(path, filename) {
4949
files = append(files, path)
5050
}
5151
return err
@@ -63,17 +63,17 @@ func ReadFile(filename string) (string, error) {
6363
// skip the file if you don't want to copy
6464
func CopyDir(src, dst, skip string) error {
6565
s := cp.Options{Skip: func(src string) (bool, error) {
66-
return strings.Contains(strings.ToLower(src), skip), nil
66+
return strings.HasSuffix(strings.ToLower(src), skip), nil
6767
}}
6868
return cp.Copy(src, dst, s)
6969
}
7070

71-
// CopyDirContains copies the directory from the source to the destination
72-
// contain is the file if you want to copy
73-
func CopyDirContains(src, dst, contain string) error {
71+
// CopyDirHasSuffix copies the directory from the source to the destination
72+
// contain is the file if you want to copy, and rename copied filename with dir/index_filename
73+
func CopyDirHasSuffix(src, dst, suffix string) error {
7474
var filelist []string
7575
err := filepath.Walk(src, func(path string, f os.FileInfo, err error) error {
76-
if !f.IsDir() && strings.Contains(strings.ToLower(f.Name()), contain) {
76+
if !f.IsDir() && strings.HasSuffix(strings.ToLower(f.Name()), suffix) {
7777
filelist = append(filelist, path)
7878
}
7979
return err

0 commit comments

Comments
 (0)