diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c22a8b4 --- /dev/null +++ b/go.mod @@ -0,0 +1,11 @@ +module github.com/sigmonsays/go-apt-client + +go 1.20 + +require github.com/stretchr/testify v1.8.4 + +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 new file mode 100644 index 0000000..fa4b6e6 --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/repos.go b/repos.go index 67db3be..1b56918 100644 --- a/repos.go +++ b/repos.go @@ -150,7 +150,13 @@ func parseAPTConfigFile(configPath string) (RepositoryList, error) { // get information about all configured repositories, it scans also // "source.list.d" subfolder to find all the "*.list" files. func ParseAPTConfigFolder(folderPath string) (RepositoryList, error) { - sources := []string{filepath.Join(folderPath, "sources.list")} + sources := make([]string, 0) + + + sourcesFile := filepath.Join(folderPath, "sources.list") + if FileExists(sourcesFile) { + sources = append(sources, sourcesFile) + } sourcesFolder := filepath.Join(folderPath, "sources.list.d") list, err := ioutil.ReadDir(sourcesFolder) diff --git a/util.go b/util.go new file mode 100644 index 0000000..b24ea6b --- /dev/null +++ b/util.go @@ -0,0 +1,14 @@ +package apt + +import "os" + +func FileExists(path string) bool { + st, err := os.Stat(path) + if err != nil && os.IsNotExist(err) { + return false + } + if st.IsDir() == true { + return false + } + return true +}