Skip to content

Commit

Permalink
refactor: Move where we open cache file
Browse files Browse the repository at this point in the history
  • Loading branch information
caffeine-addictt committed Apr 14, 2024
1 parent eb57871 commit f553d61
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ var getCommand = &cobra.Command{
}
Info("Read " + fmt.Sprint(len(args)-preURLCount) + " url(s) from " + getFlags.inputFile)
}
Debug("Valid URL(s): " + fmt.Sprint(argSet))
Debug("Non URL(s): " + fmt.Sprint(nonURLSet))

// Open cache file
Debug("Opening cache file at " + cacheFile)
file, err := os.OpenFile(cacheFile, os.O_RDWR|os.O_APPEND, 0o600)
if err != nil {
fmt.Println("Failed to open cache file at " + cacheFile)
Debug(err.Error())
return
}
defer file.Close()

// Ensure a URL was passed
if len(argSet) == 0 {
Expand All @@ -128,14 +140,6 @@ var getCommand = &cobra.Command{
defer waitGroup.Done()
fmt.Println("Writing URLs to cache file...")

file, err := os.OpenFile(cacheFile, os.O_RDWR|os.O_APPEND, 0o600)
if err != nil {
fmt.Println("Failed to open cache file at " + cacheFile)
Debug(err.Error())
return
}
defer file.Close()

// Buffer writer
buffer := bufio.NewWriter(file)
for downloadURL := range argSet {
Expand Down

0 comments on commit f553d61

Please sign in to comment.