From e2f45e1b220fadd3da71a1f9044507d3ec75f858 Mon Sep 17 00:00:00 2001 From: GreyXor Date: Fri, 20 Jan 2023 19:59:22 +0100 Subject: [PATCH 1/4] upgrade deps --- go.mod | 10 ++++++++-- go.sum | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 946be96..d27bc92 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 55ae0e5..fd085fb 100644 --- a/go.sum +++ b/go.sum @@ -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= From 38d3a4a0b03274dc1b20407ee11b89d1afba9082 Mon Sep 17 00:00:00 2001 From: GreyXor Date: Fri, 20 Jan 2023 20:01:12 +0100 Subject: [PATCH 2/4] sort imports --- internal/pathutil/pathutil_test.go | 3 ++- internal/pathutil/pathutil_unix_test.go | 3 ++- paths_unix_test.go | 3 ++- xdg_test.go | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/pathutil/pathutil_test.go b/internal/pathutil/pathutil_test.go index 04fc18c..af03625 100644 --- a/internal/pathutil/pathutil_test.go +++ b/internal/pathutil/pathutil_test.go @@ -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) { diff --git a/internal/pathutil/pathutil_unix_test.go b/internal/pathutil/pathutil_unix_test.go index ad52ddb..5fe1c13 100644 --- a/internal/pathutil/pathutil_unix_test.go +++ b/internal/pathutil/pathutil_unix_test.go @@ -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) { diff --git a/paths_unix_test.go b/paths_unix_test.go index e2e2dd2..055a79f 100644 --- a/paths_unix_test.go +++ b/paths_unix_test.go @@ -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) { diff --git a/xdg_test.go b/xdg_test.go index e1f6290..b29044e 100644 --- a/xdg_test.go +++ b/xdg_test.go @@ -5,8 +5,9 @@ import ( "path/filepath" "testing" - "github.com/adrg/xdg" "github.com/stretchr/testify/require" + + "github.com/adrg/xdg" ) type envSample struct { From 7a2612b2e04fc071118a0ec3c051ffcf6ac2b854 Mon Sep 17 00:00:00 2001 From: GreyXor Date: Fri, 20 Jan 2023 20:06:25 +0100 Subject: [PATCH 3/4] fix: prealloc string path array --- internal/pathutil/pathutil.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/pathutil/pathutil.go b/internal/pathutil/pathutil.go index 7422342..d3bc124 100644 --- a/internal/pathutil/pathutil.go +++ b/internal/pathutil/pathutil.go @@ -40,7 +40,8 @@ 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) @@ -48,7 +49,7 @@ func Create(name string, paths []string) (string, error) { 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 } @@ -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) { From bba8b7d61bbfecd3645ca48b3c3fa6d303d6ae1a Mon Sep 17 00:00:00 2001 From: GreyXor Date: Fri, 20 Jan 2023 20:06:38 +0100 Subject: [PATCH 4/4] typo: in doc --- xdg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xdg.go b/xdg.go index 3d33ca6..24683bc 100644 --- a/xdg.go +++ b/xdg.go @@ -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