From a9770263574f2ea91bebdb09b66067cd39e4a472 Mon Sep 17 00:00:00 2001 From: pspiagicw Date: Fri, 12 Apr 2024 05:43:09 +0000 Subject: [PATCH] refactor(resolver): moved to 'pspiagicw/fs' for file system functions --- go.mod | 1 + go.sum | 2 ++ pkg/resolver/resolver.go | 23 ++--------------------- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 6e3ea53..9440da7 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/kkdai/youtube/v2 v2.10.1 github.com/mattn/go-sqlite3 v1.14.22 github.com/mitchellh/go-homedir v1.1.0 + github.com/pspiagicw/fs v0.0.0-20240412053716-83196aadc37c github.com/pspiagicw/goreland v0.0.0-20231129143657-4b9ff8ac7ad5 github.com/pspiagicw/pelp v0.0.0-20240318161701-7448ea2e376e ) diff --git a/go.sum b/go.sum index 3c56a8b..8ed57f7 100644 --- a/go.sum +++ b/go.sum @@ -86,6 +86,8 @@ github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1n github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pspiagicw/fs v0.0.0-20240412053716-83196aadc37c h1:aStvB+j8eO/VyPxP3jbZVK7HCm4YEA+dAaa0l+l1oPw= +github.com/pspiagicw/fs v0.0.0-20240412053716-83196aadc37c/go.mod h1:36S2s+6McEuewyXRbbkbbyOR4zSdzpmv12PD+NJrKyQ= github.com/pspiagicw/goreland v0.0.0-20231129143657-4b9ff8ac7ad5 h1:vtXgJQnlbnQLdA2FvtdZ5CEeex9+oj8Db5SgcZW807c= github.com/pspiagicw/goreland v0.0.0-20231129143657-4b9ff8ac7ad5/go.mod h1:w9C97TNLperGU930lN/hc2XuWUlYzPbBUW1OA1ka4DM= github.com/pspiagicw/pelp v0.0.0-20240318161701-7448ea2e376e h1:N0ZhzS8AdPstCIV7eti5BOXhen73DjGj0+d393GXWcU= diff --git a/pkg/resolver/resolver.go b/pkg/resolver/resolver.go index 566ca40..1dc5d86 100644 --- a/pkg/resolver/resolver.go +++ b/pkg/resolver/resolver.go @@ -2,11 +2,11 @@ package resolver import ( "errors" - "io/fs" "os" "path/filepath" "github.com/adrg/xdg" + "github.com/pspiagicw/fs" "github.com/pspiagicw/goreland" ) @@ -16,29 +16,10 @@ func HomeDir() string { func DataDir() string { location := filepath.Join(xdg.DataHome, "sinister") - ensureExists(location) + fs.EnsurePathExists(location) return location } -func ensureExists(location string) { - if !dirExists(location) { - err := os.MkdirAll(location, 0755) - if err != nil { - goreland.LogFatal("Error creating directory: %s, %v", location, err) - } - } -} - -func dirExists(dir string) bool { - _, err := os.Stat(dir) - if errors.Is(err, fs.ErrNotExist) { - return false - } else if err != nil { - goreland.LogFatal("Error stating directory: %v", err) - } - return true -} - func DatabasePath() string { d := DataDir()