mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
feat: improve extension parsing (#235)
* feat: improve extension parsing * refactor: Refactor extension parsing and update file names. - Refactor extension parsing function for clarity and DRYness - Update name of a file to "Secure Preferences" - Add TODO comment for future work on extension files and folders - Remove unnecessary file write operation and import statement --------- Co-authored-by: moonD4rk <moond4rk13@gmail.com>
This commit is contained in:
@@ -3,7 +3,6 @@ package fileutil
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
@@ -37,21 +36,6 @@ func IsDirExists(folder string) bool {
|
||||
return info.IsDir()
|
||||
}
|
||||
|
||||
// FilesInFolder returns the filepath contains in the provided folder
|
||||
func FilesInFolder(dir, filename string) ([]string, error) {
|
||||
if !IsDirExists(dir) {
|
||||
return nil, errors.New(dir + "folder does not exist")
|
||||
}
|
||||
var files []string
|
||||
err := filepath.Walk(dir, func(path string, f os.FileInfo, err error) error {
|
||||
if !f.IsDir() && strings.HasSuffix(path, filename) {
|
||||
files = append(files, path)
|
||||
}
|
||||
return err
|
||||
})
|
||||
return files, err
|
||||
}
|
||||
|
||||
// ReadFile reads the file from the provided path
|
||||
func ReadFile(filename string) (string, error) {
|
||||
s, err := os.ReadFile(filename)
|
||||
@@ -67,33 +51,6 @@ func CopyDir(src, dst, skip string) error {
|
||||
return cp.Copy(src, dst, s)
|
||||
}
|
||||
|
||||
// CopyDirHasSuffix copies the directory from the source to the destination
|
||||
// contain is the file if you want to copy, and rename copied filename with dir/index_filename
|
||||
func CopyDirHasSuffix(src, dst, suffix string) error {
|
||||
var files []string
|
||||
err := filepath.Walk(src, func(path string, f os.FileInfo, err error) error {
|
||||
if !f.IsDir() && strings.HasSuffix(strings.ToLower(f.Name()), suffix) {
|
||||
files = append(files, path)
|
||||
}
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.MkdirAll(dst, 0o700); err != nil {
|
||||
return err
|
||||
}
|
||||
for index, file := range files {
|
||||
// p = dir/index_file
|
||||
p := fmt.Sprintf("%s/%d_%s", dst, index, BaseDir(file))
|
||||
err = CopyFile(file, p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CopyFile copies the file from the source to the destination
|
||||
func CopyFile(src, dst string) error {
|
||||
s, err := os.ReadFile(src)
|
||||
|
||||
Reference in New Issue
Block a user