Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Commit

Permalink
Add checking of unhandled errors
Browse files Browse the repository at this point in the history
  • Loading branch information
BuJo committed Nov 1, 2019
1 parent bd41c9b commit 819764a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,3 @@ linters:
- unused
- varcheck
- whitespace
disable:
- errcheck
9 changes: 7 additions & 2 deletions rpm/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ func (r *yumRepository) PackageWithNameAndVersion(name string, version string) (
return repos.Package{}, err
}
var repomd RepoMd
xml.Unmarshal(repomdData, &repomd)

if err = xml.Unmarshal(repomdData, &repomd); err != nil {
return repos.Package{}, err
}

filelist := filepath.Join(r.path(), filelist(repomd))

Expand All @@ -144,7 +147,9 @@ func (r *yumRepository) PackageWithNameAndVersion(name string, version string) (

var filelistsContent Filelists

xml.Unmarshal(filelistData, &filelistsContent)
if err = xml.Unmarshal(filelistData, &filelistsContent); err != nil {
return repos.Package{}, err
}

return findPackageWithVersion(filelistsContent, name, version)
}
Expand Down
4 changes: 3 additions & 1 deletion rpm/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ func TestPath(t *testing.T) {
}

func TestEnsureExists(t *testing.T) {
repo.store.ensureExists(repo.name)
if _, err := repo.store.ensureExists(repo.name); err != nil {
t.Error(err)
}
file, err := os.Open(path)
if err != nil {
t.Errorf("%s", err)
Expand Down
17 changes: 12 additions & 5 deletions rpm/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ func (store *yumRepoStore) Get(name string) repos.AnyRepository {

func (store *yumRepoStore) Initialize(name string) error {
log.Printf("Initializing repository %s", name)
path := store.ensureExists(name)

path, err := store.ensureExists(name)
if err != nil {
return err
}

log.Printf("Executing `createrepo --database %s`", path)
cmd := exec.Command("createrepo", "--database", path)
return cmd.Run()
Expand All @@ -44,11 +49,13 @@ func (store *yumRepoStore) ListRepositories() []repos.Repository {
return reps
}

func (store *yumRepoStore) ensureExists(name string) string {
func (store *yumRepoStore) ensureExists(name string) (string, error) {
path := filepath.Join(store.base, name)
if _, err := os.Stat(path); os.IsNotExist(err) {

_, err := os.Stat(path)
if os.IsNotExist(err) {
log.Printf("Creating repository directory %s", path)
os.MkdirAll(path, 0755)
err = os.MkdirAll(path, 0755)
}
return path
return path, err
}

0 comments on commit 819764a

Please sign in to comment.