Skip to content

Commit

Permalink
Merge pull request #45 from GreyXor/master
Browse files Browse the repository at this point in the history
Misc package improvements
  • Loading branch information
adrg authored Jan 23, 2023
2 parents 952fa74 + bba8b7d commit d31002f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 12 deletions.
10 changes: 8 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
module github.com/adrg/xdg

go 1.14
go 1.19

require (
github.com/stretchr/testify v1.8.1
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359
golang.org/x/sys v0.4.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 h1:2B5p2L5IfGiD7+b9BOoRMC6DgObAVZV+Fsp050NqXik=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
8 changes: 5 additions & 3 deletions internal/pathutil/pathutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ func Unique(paths []string, home string) []string {
// it can also contain a set of parent directories, which will be created
// relative to the selected parent path.
func Create(name string, paths []string) (string, error) {
var searchedPaths []string
searchedPaths := make([]string, 0, len(paths))

for _, p := range paths {
p = filepath.Join(p, name)

dir := filepath.Dir(p)
if Exists(dir) {
return p, nil
}
if err := os.MkdirAll(dir, os.ModeDir|0700); err == nil {
if err := os.MkdirAll(dir, os.ModeDir|0o700); err == nil {
return p, nil
}

Expand All @@ -63,7 +64,8 @@ func Create(name string, paths []string) (string, error) {
// slice of `paths`. The `name` parameter must contain the name of the file,
// but it can also contain a set of parent directories.
func Search(name string, paths []string) (string, error) {
var searchedPaths []string
searchedPaths := make([]string, 0, len(paths))

for _, p := range paths {
p = filepath.Join(p, name)
if Exists(p) {
Expand Down
3 changes: 2 additions & 1 deletion internal/pathutil/pathutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"path/filepath"
"testing"

"github.com/adrg/xdg/internal/pathutil"
"github.com/stretchr/testify/require"

"github.com/adrg/xdg/internal/pathutil"
)

func TestExists(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion internal/pathutil/pathutil_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"path/filepath"
"testing"

"github.com/adrg/xdg/internal/pathutil"
"github.com/stretchr/testify/require"

"github.com/adrg/xdg/internal/pathutil"
)

func TestExpandHome(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion paths_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
"strconv"
"testing"

"github.com/adrg/xdg"
"github.com/stretchr/testify/require"

"github.com/adrg/xdg"
)

func TestDefaultBaseDirs(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion xdg.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (

// ConfigHome defines the base directory relative to which user-specific
// configuration files should be written. This directory is defined by
// the $XDG_CONFIG_HOME environment variable. If the variable is not
// the $XDG_CONFIG_HOME environment variable. If the variable is
// not set, a default equal to $HOME/.config should be used.
ConfigHome string

Expand Down
3 changes: 2 additions & 1 deletion xdg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"path/filepath"
"testing"

"github.com/adrg/xdg"
"github.com/stretchr/testify/require"

"github.com/adrg/xdg"
)

type envSample struct {
Expand Down

0 comments on commit d31002f

Please sign in to comment.