Skip to content

Commit c6def72

Browse files
committed
small refactor: used *paths.Path if possible; moved some lines
1 parent f77d895 commit c6def72

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Diff for: commands/core/update_index.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,26 @@ func updateIndexes() {
5858
// TODO: This should be in packagemanager......
5959
func updateIndex(URL *url.URL) {
6060
logrus.WithField("url", URL).Print("Updating index")
61-
indexDirPath := commands.Config.IndexesDir()
62-
coreIndexPath := indexDirPath.Join(path.Base(URL.Path))
6361

6462
tmpFile, err := ioutil.TempFile("", "")
6563
if err != nil {
6664
formatter.PrintError(err, "Error creating temp file for download")
6765
os.Exit(commands.ErrGeneric)
6866
}
69-
defer os.Remove(tmpFile.Name())
70-
tmpFile.Close()
67+
if err := tmpFile.Close(); err != nil {
68+
formatter.PrintError(err, "Error creating temp file for download")
69+
os.Exit(commands.ErrGeneric)
70+
}
71+
tmp := paths.New(tmpFile.Name())
72+
defer tmp.Remove()
7173

72-
d, err := downloader.Download(tmpFile.Name(), URL.String())
74+
d, err := downloader.Download(tmp.String(), URL.String())
7375
if err != nil {
7476
formatter.PrintError(err, "Error downloading index "+URL.String())
7577
os.Exit(commands.ErrNetwork)
7678
}
79+
indexDirPath := commands.Config.IndexesDir()
80+
coreIndexPath := indexDirPath.Join(path.Base(URL.Path))
7781
formatter.DownloadProgressBar(d, "Updating index: "+coreIndexPath.Base())
7882
if d.Error() != nil {
7983
formatter.PrintError(d.Error(), "Error downloading index "+URL.String())
@@ -85,7 +89,7 @@ func updateIndex(URL *url.URL) {
8589
os.Exit(commands.ErrGeneric)
8690
}
8791

88-
if err := paths.New(tmpFile.Name()).CopyTo(coreIndexPath); err != nil {
92+
if err := tmp.CopyTo(coreIndexPath); err != nil {
8993
formatter.PrintError(err, "Error saving downloaded index "+URL.String())
9094
os.Exit(commands.ErrGeneric)
9195
}

0 commit comments

Comments
 (0)