mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-08-17 23:57:12 +02:00
fix: check copy dir with filename suffix
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"hack-browser-data/internal/browingdata"
|
"hack-browser-data/internal/browingdata"
|
||||||
"hack-browser-data/internal/item"
|
"hack-browser-data/internal/item"
|
||||||
"hack-browser-data/internal/log"
|
|
||||||
"hack-browser-data/internal/utils/fileutil"
|
"hack-browser-data/internal/utils/fileutil"
|
||||||
"hack-browser-data/internal/utils/typeutil"
|
"hack-browser-data/internal/utils/typeutil"
|
||||||
)
|
)
|
||||||
@@ -70,7 +69,7 @@ func (c *chromium) copyItemToLocal() error {
|
|||||||
err = fileutil.CopyDir(path, filename, "lock")
|
err = fileutil.CopyDir(path, filename, "lock")
|
||||||
}
|
}
|
||||||
if i == item.ChromiumExtension {
|
if i == item.ChromiumExtension {
|
||||||
err = fileutil.CopyDirContains(path, filename, "manifest.json")
|
err = fileutil.CopyDirHasSuffix(path, filename, "manifest.json")
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
err = fileutil.CopyFile(path, filename)
|
err = fileutil.CopyFile(path, filename)
|
||||||
@@ -86,8 +85,6 @@ func (c *chromium) getItemPath(profilePath string, items []item.Item) (map[item.
|
|||||||
var itemPaths = make(map[item.Item]string)
|
var itemPaths = make(map[item.Item]string)
|
||||||
parentDir := fileutil.ParentDir(profilePath)
|
parentDir := fileutil.ParentDir(profilePath)
|
||||||
baseDir := fileutil.BaseDir(profilePath)
|
baseDir := fileutil.BaseDir(profilePath)
|
||||||
log.Infof("%s profile parentDir: %s", c.name, parentDir)
|
|
||||||
log.Infof("%s profile baseDir: %s", c.name, baseDir)
|
|
||||||
err := filepath.Walk(parentDir, chromiumWalkFunc(items, itemPaths, baseDir))
|
err := filepath.Walk(parentDir, chromiumWalkFunc(items, itemPaths, baseDir))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return itemPaths, err
|
return itemPaths, err
|
||||||
|
|||||||
@@ -38,14 +38,14 @@ func FolderExists(foldername string) bool {
|
|||||||
return info.IsDir()
|
return info.IsDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FilesInFolder returns the files contains in the provided folder
|
// FilesInFolder returns the filepath contains in the provided folder
|
||||||
func FilesInFolder(dir, filename string) ([]string, error) {
|
func FilesInFolder(dir, filename string) ([]string, error) {
|
||||||
if !FolderExists(dir) {
|
if !FolderExists(dir) {
|
||||||
return nil, errors.New(dir + " folder does not exist")
|
return nil, errors.New(dir + " folder does not exist")
|
||||||
}
|
}
|
||||||
var files []string
|
var files []string
|
||||||
err := filepath.Walk(dir, func(path string, f os.FileInfo, err error) error {
|
err := filepath.Walk(dir, func(path string, f os.FileInfo, err error) error {
|
||||||
if !f.IsDir() && strings.Contains(path, filename) {
|
if !f.IsDir() && strings.HasSuffix(path, filename) {
|
||||||
files = append(files, path)
|
files = append(files, path)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -63,17 +63,17 @@ func ReadFile(filename string) (string, error) {
|
|||||||
// skip the file if you don't want to copy
|
// skip the file if you don't want to copy
|
||||||
func CopyDir(src, dst, skip string) error {
|
func CopyDir(src, dst, skip string) error {
|
||||||
s := cp.Options{Skip: func(src string) (bool, error) {
|
s := cp.Options{Skip: func(src string) (bool, error) {
|
||||||
return strings.Contains(strings.ToLower(src), skip), nil
|
return strings.HasSuffix(strings.ToLower(src), skip), nil
|
||||||
}}
|
}}
|
||||||
return cp.Copy(src, dst, s)
|
return cp.Copy(src, dst, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CopyDirContains copies the directory from the source to the destination
|
// CopyDirHasSuffix copies the directory from the source to the destination
|
||||||
// contain is the file if you want to copy
|
// contain is the file if you want to copy, and rename copied filename with dir/index_filename
|
||||||
func CopyDirContains(src, dst, contain string) error {
|
func CopyDirHasSuffix(src, dst, suffix string) error {
|
||||||
var filelist []string
|
var filelist []string
|
||||||
err := filepath.Walk(src, func(path string, f os.FileInfo, err error) error {
|
err := filepath.Walk(src, func(path string, f os.FileInfo, err error) error {
|
||||||
if !f.IsDir() && strings.Contains(strings.ToLower(f.Name()), contain) {
|
if !f.IsDir() && strings.HasSuffix(strings.ToLower(f.Name()), suffix) {
|
||||||
filelist = append(filelist, path)
|
filelist = append(filelist, path)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user