fix: check copy dir with filename suffix

pull/138/head
ᴍᴏᴏɴD4ʀᴋ 3 years ago
parent 54ad02f7b1
commit b7821d4024
  1. 5
      internal/browser/chromium/chromium.go
  2. 14
      internal/utils/fileutil/filetutil.go

@ -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

Loading…
Cancel
Save