Skip to content

[CHANGE] Fully enable customization of install directory #50

@ross-spencer

Description

@ross-spencer

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Install allows a user to specify an installation directory but filetrove uses hard-coded paths to determine locations, e.g. in the diff below I have tried to demonstrate each affected path on application startup with my own tmp path (the list isn't exhaustive):

diff --git a/cmd/ftrove/main.go b/cmd/ftrove/main.go
index ebbd0c5..f1c05f5 100644
--- a/cmd/ftrove/main.go
+++ b/cmd/ftrove/main.go
@@ -153,7 +153,7 @@ func main() {
 	}
 
 	// Change logger to MultiWriter for output to logfile and os.Stdout
-	logfd, err := os.OpenFile("logs/filetrove.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
+	logfd, err := os.OpenFile("/tmp/filetrove/logs/filetrove.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
 	if err != nil {
 		logger.Error("Could not open filetrove log file.", slog.String("error", err.Error()))
 		os.Exit(1)
@@ -230,7 +230,7 @@ func main() {
 	nsrlcount := 0
 
 	// Prepare BoltDB for reading hashes
-	db, err := ft.ConnectNSRL("db/nsrl.db")
+	db, err := ft.ConnectNSRL("/tmp/filetrove/db/nsrl.db")
 	if err != nil {
 		logger.Error("Could not connect to NSRL database", slog.String("error", err.Error()))
 		err = ftdb.Close()
@@ -343,7 +343,7 @@ func main() {
 	}
 
 	// Initialize siegfried database
-	s, err := siegfried.Load("db/siegfried.sig")
+	s, err := siegfried.Load("/tmp/filetrove/db/siegfried.sig")
 	if err != nil {
 		logger.Error("Could not read siegfried's database.", slog.String("error", err.Error()))
 		err = ftdb.Close()
diff --git a/db.go b/db.go
index cb16074..c7da8d7 100644
--- a/db.go
+++ b/db.go
@@ -234,7 +234,7 @@ func ListSessions(db *sql.DB) error {
 // ExportSessionSessionTSV exports all session metadata from a session to a TSV file.
 // Filtering is done by session UUID.
 func ExportSessionSessionTSV(sessionuuid string) ([]string, error) {
-	db, err := sql.Open("sqlite3", "db/filetrove.db")
+	db, err := sql.Open("sqlite3", "/filetrove/tmp/db/filetrove.db")
 	if err != nil {
 		return nil, err
 	}
@@ -312,7 +312,7 @@ func ExportSessionSessionTSV(sessionuuid string) ([]string, error) {
 // ExportSessionFilesTSV exports all file metadata from a session to a TSV file.
 // Filtering is done by session UUID.
 func ExportSessionFilesTSV(sessionuuid string) error {
-	db, err := sql.Open("sqlite3", "db/filetrove.db")
+	db, err := sql.Open("sqlite3", "/tmp/filetrove/db/filetrove.db")
 	if err != nil {
 		return err
 	}
@@ -389,7 +389,7 @@ func ExportSessionFilesTSV(sessionuuid string) error {
 // ExportSessionDirectoriesTSV exports all directory metadata from a session to a TSV file.
 // Filtering is done by session UUID.
 func ExportSessionDirectoriesTSV(sessionuuid string) error {
-	db, err := sql.Open("sqlite3", "db/filetrove.db")
+	db, err := sql.Open("sqlite3", "/tmp/filetrove/db/filetrove.db")
 	if err != nil {
 		return err
 	}
@@ -465,7 +465,7 @@ func ExportSessionDirectoriesTSV(sessionuuid string) error {
 
 // ExportSessionEXIFTSV exports all exif metadata from a session to a TSV file. Filtering is done by session UUID.
 func ExportSessionEXIFTSV(sessionuuid string) error {
-	db, err := sql.Open("sqlite3", "db/filetrove.db")
+	db, err := sql.Open("sqlite3", "/tmp/filetrove/db/filetrove.db")
 	if err != nil {
 		return err
 	}
@@ -541,7 +541,7 @@ func ExportSessionEXIFTSV(sessionuuid string) error {
 
 // ExportSessionDCTSV exports all exif metadata from a session to a TSV file. Filtering is done by session UUID.
 func ExportSessionDCTSV(sessionuuid string) error {
-	db, err := sql.Open("sqlite3", "db/filetrove.db")
+	db, err := sql.Open("sqlite3", "/tmp/filetrove/db/filetrove.db")
 	if err != nil {
 		return err
 	}

Describe the solution you'd like
A clear and concise description of what you want to happen.

  • Read a root path for filetrove from a single variable/location.
  • Consider a toml file or env file for reading on startup.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Leaving the code as-is will likely break use anywhere that isn't a standalone use of the tool, e.g. installed from /usr/bin where the user probably doesn't also want to install filetrove's static files there.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions