Skip to content

Commit

Permalink
Merge pull request #37 from bravetools/issue-35
Browse files Browse the repository at this point in the history
address #35
  • Loading branch information
Aleks Drozdov committed Apr 16, 2021
2 parents 84477cb + a978ea9 commit 764b892
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion commands/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var braveImportImage = &cobra.Command{
Use: "import NAME",
Short: "Import a tarball into local Bravetools image repository",
Short: "Import an LXD image tarball into local Bravetools image repository",
Long: ``,
Run: importImage,
}
Expand Down
17 changes: 10 additions & 7 deletions platform/host_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,25 @@ func (bh *BraveHost) AddRemote() error {
}

// ImportLocalImage import tarball into local images folder
func (bh *BraveHost) ImportLocalImage(name string) error {
func (bh *BraveHost) ImportLocalImage(sourcePath string) error {
home, _ := os.UserHomeDir()

_, imageName := filepath.Split(sourcePath)

imagePath := home + shared.ImageStore
hashFile := imagePath + name + ".md5"
hashFile := imagePath + imageName + ".md5"

_, err := os.Stat(home + shared.ImageStore + name)
_, err := os.Stat(home + shared.ImageStore + imageName)
if !os.IsNotExist(err) {
return errors.New("Image " + name + " already exists in local image storage")
return errors.New("Image " + imageName + " already exists in local image store")
}

err = shared.CopyFile(name, imagePath+name)
err = shared.CopyFile(sourcePath, imagePath+imageName)
if err != nil {
return errors.New("Failed to copy image archive to local image storage: " + err.Error())
return errors.New("Failed to copy image archive to local image store: " + err.Error())
}

imageHash, err := shared.FileHash(name)
imageHash, err := shared.FileHash(sourcePath)
if err != nil {
return errors.New("Failed to generate image hash: " + err.Error())
}
Expand Down

0 comments on commit 764b892

Please sign in to comment.