Commit 2fa46edd authored by Cristian Maglie's avatar Cristian Maglie

Create data dir if not found on 'core update-index'

Fix #6
parent e6559d3c
......@@ -57,7 +57,8 @@ func updateIndexes() {
// TODO: This should be in packagemanager......
func updateIndex(URL *url.URL) {
logrus.WithField("url", URL).Print("Updating index")
coreIndexPath := commands.Config.IndexesDir().Join(path.Base(URL.Path))
indexDirPath := commands.Config.IndexesDir()
coreIndexPath := indexDirPath.Join(path.Base(URL.Path))
tmpFile, err := ioutil.TempFile("", "")
if err != nil {
......@@ -80,6 +81,11 @@ func updateIndex(URL *url.URL) {
os.Exit(commands.ErrNetwork)
}
if err := indexDirPath.MkdirAll(); err != nil {
formatter.PrintError(err, "Can't create data directory "+indexDirPath.String())
os.Exit(commands.ErrGeneric)
}
if err := paths.New(tmpFile.Name()).CopyTo(coreIndexPath); err != nil {
formatter.PrintError(err, "Error saving downloaded index "+URL.String())
os.Exit(commands.ErrGeneric)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment