Skip to content
Snippets Groups Projects
Unverified Commit fa09724d authored by azubieta's avatar azubieta
Browse files

Support updating AppImages outside the collection

parent caa0361a
Branches update_dialog
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"appimage-manager/app/utils" "appimage-manager/app/utils"
...@@ -11,11 +12,11 @@ import ( ...@@ -11,11 +12,11 @@ import (
) )
type UpdateCmd struct { type UpdateCmd struct {
Id string `arg name:"id" help:"Installation id or file name." type:"string"` Target string `arg name:"target" help:"Updates the target application." type:"string"`
} }
func (cmd *UpdateCmd) Run(*Context) (err error) { func (cmd *UpdateCmd) Run(*Context) (err error) {
filePath, err := cmd.getApplicationFilePath() filePath, err := cmd.getBundleFilePath()
if err != nil { if err != nil {
return err return err
} }
...@@ -48,16 +49,24 @@ func (cmd *UpdateCmd) Run(*Context) (err error) { ...@@ -48,16 +49,24 @@ func (cmd *UpdateCmd) Run(*Context) (err error) {
return nil return nil
} }
func (cmd *UpdateCmd) getApplicationFilePath() (string, error) { func (cmd *UpdateCmd) getBundleFilePath() (string, error) {
if strings.HasPrefix(cmd.Target, "file://") {
cmd.Target = cmd.Target[7:]
}
if _, err := os.Stat(cmd.Target); err == nil {
return cmd.Target, nil
}
registry, err := utils.OpenRegistry() registry, err := utils.OpenRegistry()
if err != nil { if err != nil {
return "", err return "", err
} }
registry.Update() registry.Update()
fileName, ok := registry.Lookup(cmd.Id) fileName, ok := registry.Lookup(cmd.Target)
if !ok { if !ok {
fileName = cmd.Id fileName = cmd.Target
} }
applicationsDir, err := utils.MakeApplicationsDirPath() applicationsDir, err := utils.MakeApplicationsDirPath()
...@@ -67,7 +76,7 @@ func (cmd *UpdateCmd) getApplicationFilePath() (string, error) { ...@@ -67,7 +76,7 @@ func (cmd *UpdateCmd) getApplicationFilePath() (string, error) {
filePath := filepath.Join(applicationsDir, fileName) filePath := filepath.Join(applicationsDir, fileName)
if _, err := os.Stat(filePath); os.IsNotExist(err) { if _, err := os.Stat(filePath); os.IsNotExist(err) {
return "", fmt.Errorf("application not found \"" + cmd.Id + "\"") return "", fmt.Errorf("application not found \"" + cmd.Target + "\"")
} }
return filePath, nil return filePath, nil
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment