From ef70166e821eaa5e706ab2540347b24d821dc7f5 Mon Sep 17 00:00:00 2001 From: tek Date: Thu, 25 Jan 2024 14:22:47 +0100 Subject: [PATCH] Formatting --- acquisition/acquisition.go | 80 +++++++++++++++++++------------------- assets/assets.go | 4 +- modules/bugreport.go | 1 - modules/files.go | 4 +- utils/build.go | 2 +- 5 files changed, 45 insertions(+), 46 deletions(-) diff --git a/acquisition/acquisition.go b/acquisition/acquisition.go index e2801d5..86bc38f 100644 --- a/acquisition/acquisition.go +++ b/acquisition/acquisition.go @@ -25,42 +25,42 @@ import ( // Acquisition is the main object containing all phone information type Acquisition struct { - UUID string `json:"uuid"` - AndroidQFVersion string `json:"androidqf_version"` - StoragePath string `json:"storage_path"` - Started time.Time `json:"started"` - Completed time.Time `json:"completed"` - Collector *adb.Collector `json:"collector"` - TmpDir string `json:"tmp_dir"` - SdCard string `json:"sdcard"` - Cpu string `json:"cpu"` + UUID string `json:"uuid"` + AndroidQFVersion string `json:"androidqf_version"` + StoragePath string `json:"storage_path"` + Started time.Time `json:"started"` + Completed time.Time `json:"completed"` + Collector *adb.Collector `json:"collector"` + TmpDir string `json:"tmp_dir"` + SdCard string `json:"sdcard"` + Cpu string `json:"cpu"` } // New returns a new Acquisition instance. func New(path string) (*Acquisition, error) { acq := Acquisition{ - UUID: uuid.New().String(), - Started: time.Now().UTC(), + UUID: uuid.New().String(), + Started: time.Now().UTC(), AndroidQFVersion: utils.Version, } - if path == "" { - acq.StoragePath = filepath.Join(rt.GetExecutableDirectory(), acq.UUID) - } else { - acq.StoragePath = path - } - // Check if the path exist - stat, err := os.Stat(acq.StoragePath) - if os.IsNotExist(err) { - err := os.Mkdir(acq.StoragePath, 0o755) - if err != nil { - return nil, fmt.Errorf("failed to create acquisition folder: %v", err) - } - } else { - if !stat.IsDir() { - return nil, fmt.Errorf("path exist and is not a folder") - } - } + if path == "" { + acq.StoragePath = filepath.Join(rt.GetExecutableDirectory(), acq.UUID) + } else { + acq.StoragePath = path + } + // Check if the path exist + stat, err := os.Stat(acq.StoragePath) + if os.IsNotExist(err) { + err := os.Mkdir(acq.StoragePath, 0o755) + if err != nil { + return nil, fmt.Errorf("failed to create acquisition folder: %v", err) + } + } else { + if !stat.IsDir() { + return nil, fmt.Errorf("path exist and is not a folder") + } + } // Get system information first to get tmp folder err = acq.GetSystemInformation() @@ -109,25 +109,25 @@ func (a *Acquisition) GetSystemInformation() error { return fmt.Errorf("failed to run `adb shell env`: %v", err) } a.TmpDir = "/data/local/tmp/" - a.SdCard = "/sdcard/" + a.SdCard = "/sdcard/" for _, line := range strings.Split(out, "\n") { line = strings.TrimSpace(line) if strings.HasPrefix(line, "TMPDIR=") { a.TmpDir = strings.TrimPrefix(line, "TMPDIR=") } - if strings.HasPrefix(line, "EXTERNAL_STORAGE=") { - a.SdCard = strings.TrimPrefix(line, "EXTERNAL_STORAGE=") - } - } - if !strings.HasSuffix(a.TmpDir, "/") { - a.TmpDir = a.TmpDir + "/" - } - if !strings.HasSuffix(a.SdCard, "/") { - a.SdCard = a.SdCard + "/" - } + if strings.HasPrefix(line, "EXTERNAL_STORAGE=") { + a.SdCard = strings.TrimPrefix(line, "EXTERNAL_STORAGE=") + } + } + if !strings.HasSuffix(a.TmpDir, "/") { + a.TmpDir = a.TmpDir + "/" + } + if !strings.HasSuffix(a.SdCard, "/") { + a.SdCard = a.SdCard + "/" + } log.Debugf("Found temp folder at %s", a.TmpDir) - log.Debugf("Found sdcard at %s", a.SdCard) + log.Debugf("Found sdcard at %s", a.SdCard) return nil } diff --git a/assets/assets.go b/assets/assets.go index 10fdfbc..addafa7 100644 --- a/assets/assets.go +++ b/assets/assets.go @@ -7,8 +7,8 @@ package assets import ( "embed" - "os" "errors" + "os" "path/filepath" saveRuntime "github.com/botherder/go-savetime/runtime" @@ -32,7 +32,7 @@ func DeployAssets() error { assetFile, err := os.OpenFile(assetPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o755) if err != nil { // Asset file already exists. Do not try overwriting - if (errors.Is(err, os.ErrExist)) { + if errors.Is(err, os.ErrExist) { continue } else { return err diff --git a/modules/bugreport.go b/modules/bugreport.go index b74f6a3..9f92127 100644 --- a/modules/bugreport.go +++ b/modules/bugreport.go @@ -32,7 +32,6 @@ func (b *Bugreport) InitStorage(storagePath string) error { } func (b *Bugreport) Run(acq *acquisition.Acquisition, fast bool) error { - log.Info( "Generating a bugreport for the device...", ) diff --git a/modules/files.go b/modules/files.go index d5cda13..a4c3a31 100644 --- a/modules/files.go +++ b/modules/files.go @@ -58,9 +58,9 @@ func (f *Files) Run(acq *acquisition.Acquisition, fast bool) error { if acq.TmpDir != "/data/local/tmp/" { folders = append(folders, acq.TmpDir) } - if acq.SdCard != "/sdcard/" { + if acq.SdCard != "/sdcard/" { folders = append(folders, acq.SdCard) - } + } for _, folder := range folders { var out []adb.FileInfo diff --git a/utils/build.go b/utils/build.go index f6ab608..5e59699 100644 --- a/utils/build.go +++ b/utils/build.go @@ -1,4 +1,4 @@ package utils // Store the build verion information; set by linker flag -var Version string \ No newline at end of file +var Version string