Skip to content

Commit 26bd83a

Browse files
committed
Add BaseDir field and use it for paths
1 parent 3915161 commit 26bd83a

3 files changed

Lines changed: 9 additions & 12 deletions

File tree

acquisition/acquisition.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Acquisition struct {
2929
UUID string `json:"uuid"`
3030
AndroidQFVersion string `json:"androidqf_version"`
3131
StoragePath string `json:"storage_path"`
32+
BaseDir string `json:"base_dir"`
3233
Started time.Time `json:"started"`
3334
Completed time.Time `json:"completed"`
3435
Collector *adb.Collector `json:"collector"`
@@ -55,6 +56,7 @@ func New(path string) (*Acquisition, error) {
5556
} else {
5657
acq.StoragePath = path
5758
}
59+
acq.BaseDir = filepath.Dir(acq.StoragePath)
5860
// Check if the path exist
5961
stat, err := os.Stat(acq.StoragePath)
6062
if os.IsNotExist(err) {
@@ -82,7 +84,7 @@ func New(path string) (*Acquisition, error) {
8284
acq.Collector = coll
8385

8486
// Try to initialize encrypted streaming mode
85-
encWriter, err := NewEncryptedZipWriter(acq.UUID)
87+
encWriter, err := NewEncryptedZipWriter(acq.UUID, acq.BaseDir)
8688
if err != nil {
8789
// No key file or encryption setup failed, use normal mode
8890
log.Debug("Encrypted streaming not available, using normal mode")

acquisition/encrypted_stream.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"time"
1717

1818
"filippo.io/age"
19-
saveRuntime "github.com/botherder/go-savetime/runtime"
2019
"github.com/mvt-project/androidqf/log"
2120
)
2221

@@ -30,9 +29,8 @@ type EncryptedZipWriter struct {
3029
}
3130

3231
// NewEncryptedZipWriter creates a new encrypted zip writer if key.txt exists
33-
func NewEncryptedZipWriter(uuid string) (*EncryptedZipWriter, error) {
34-
cwd := saveRuntime.GetExecutableDirectory()
35-
keyFilePath := filepath.Join(cwd, "key.txt")
32+
func NewEncryptedZipWriter(uuid, baseDir string) (*EncryptedZipWriter, error) {
33+
keyFilePath := filepath.Join(baseDir, "key.txt")
3634

3735
// Check if key file exists
3836
if _, err := os.Stat(keyFilePath); os.IsNotExist(err) {
@@ -55,7 +53,7 @@ func NewEncryptedZipWriter(uuid string) (*EncryptedZipWriter, error) {
5553

5654
// Create output file
5755
encFileName := fmt.Sprintf("%s.zip.age", uuid)
58-
outputPath := filepath.Join(cwd, encFileName)
56+
outputPath := filepath.Join(baseDir, encFileName)
5957

6058
file, err := os.OpenFile(outputPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
6159
if err != nil {

acquisition/secure.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"strings"
1515

1616
"filippo.io/age"
17-
saveRuntime "github.com/botherder/go-savetime/runtime"
1817
"github.com/mvt-project/androidqf/log"
1918
)
2019

@@ -44,17 +43,15 @@ func (a *Acquisition) StoreSecurely() error {
4443
return nil
4544
}
4645

47-
cwd := saveRuntime.GetExecutableDirectory()
48-
49-
keyFilePath := filepath.Join(cwd, "key.txt")
46+
keyFilePath := filepath.Join(a.BaseDir, "key.txt")
5047
if _, err := os.Stat(keyFilePath); os.IsNotExist(err) {
5148
return nil
5249
}
5350

5451
log.Info("You provided an age public key, storing the acquisition securely.")
5552

5653
zipFileName := fmt.Sprintf("%s.zip", a.UUID)
57-
zipFilePath := filepath.Join(cwd, zipFileName)
54+
zipFilePath := filepath.Join(a.BaseDir, zipFileName)
5855

5956
log.Info("Compressing the acquisition folder. This might take a while...")
6057

@@ -83,7 +80,7 @@ func (a *Acquisition) StoreSecurely() error {
8380
defer zipFile.Close()
8481

8582
encFileName := fmt.Sprintf("%s.age", zipFileName)
86-
encFilePath := filepath.Join(cwd, encFileName)
83+
encFilePath := filepath.Join(a.BaseDir, encFileName)
8784
encFile, err := os.OpenFile(encFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o600)
8885
if err != nil {
8986
return fmt.Errorf("unable to create encrypted file: %v", err)

0 commit comments

Comments
 (0)