Skip to content

Commit

Permalink
Fix a few lingering uses of os for files
Browse files Browse the repository at this point in the history
  • Loading branch information
trgeiger committed Apr 19, 2024
1 parent 5885fd3 commit 82034aa
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
copr-cli
copr-tool
2 changes: 2 additions & 0 deletions cmd/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func enableRepo(r *app.CoprRepo, fs afero.Fs, out io.Writer) error {
if r.LocalFileExists(fs) {
err := app.ToggleRepo(r, fs, out, app.Enabled)
if err != nil {
app.SudoMessage(err, out)

return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewListCmd(fs afero.Fs, out io.Writer) *cobra.Command {
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
repos, err := app.GetAllRepos(fs)
repos, err := app.GetAllRepos(fs, out)
if err != nil {
fmt.Fprintf(out, "Error when retrieving locally installed repositories: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewPruneCmd(fs afero.Fs, out io.Writer) *cobra.Command {
Use: "prune",
Short: "Remove duplicate repository configurations.",
Run: func(cmd *cobra.Command, args []string) {
repos, err := app.GetAllRepos(fs)
repos, err := app.GetAllRepos(fs, out)
if err != nil {
fmt.Fprintf(out, "Error when retrieving locally installed repositories: %s", err)
os.Exit(1)
Expand Down
11 changes: 5 additions & 6 deletions internal/app/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io"
"io/fs"
"net/http"
"os"
"slices"
"strings"

Expand Down Expand Up @@ -105,7 +104,7 @@ func AddRepo(r *CoprRepo, fs afero.Fs, out io.Writer) error {

func DeleteRepo(r *CoprRepo, fs afero.Fs, out io.Writer) error {
if r.LocalFileExists(fs) {
err := os.Remove(r.LocalFilePath())
err := fs.Remove(r.LocalFilePath())
if err != nil {
return err
}
Expand All @@ -116,16 +115,16 @@ func DeleteRepo(r *CoprRepo, fs afero.Fs, out io.Writer) error {
return nil
}

func GetAllRepos(fs afero.Fs) ([]*CoprRepo, error) {
files, err := os.ReadDir(ReposDir)
func GetAllRepos(fs afero.Fs, out io.Writer) ([]*CoprRepo, error) {
files, err := afero.ReadDir(fs, ReposDir)
if err != nil {
return nil, err
}
var reposStrings []string
var repos []*CoprRepo
for _, file := range files {
if !file.IsDir() {
ioFile, err := os.Open(ReposDir + file.Name())
ioFile, err := fs.Open(ReposDir + file.Name())

if err != nil {
return nil, err
Expand All @@ -149,7 +148,7 @@ func GetAllRepos(fs afero.Fs) ([]*CoprRepo, error) {
}
}
if err := scanner.Err(); err != nil {
fmt.Fprintln(os.Stderr, "Issue reading repo files: ", err)
fmt.Fprintln(out, "Issue reading repo files: ", err)
}
}
}
Expand Down

0 comments on commit 82034aa

Please sign in to comment.