Skip to content

Commit

Permalink
refactor(resolver): moved to 'pspiagicw/fs' for file system functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pspiagicw committed Apr 12, 2024
1 parent c78bf42 commit a977026
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 21 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
23 changes: 2 additions & 21 deletions pkg/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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()
Expand Down

0 comments on commit a977026

Please sign in to comment.