Skip to content

Commit ea5f83b

Browse files
committed
Fix #4
Fixed The Problem of old AppImage not being removed when updating. The main problem was in the line 182, which caused to return repo name instead of file path.
1 parent e724546 commit ea5f83b

1 file changed

Lines changed: 22 additions & 15 deletions

File tree

src/commands/update.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ func (cmd *UpdateCmd) Run() (err error) {
3030
}
3131

3232
if len(cmd.Targets) == 0 {
33-
fmt.Println("No Application Installed")
33+
if cmd.All {
34+
fmt.Println("No Application Installed")
35+
} else {
36+
fmt.Println("No Application Specified To Update")
37+
}
3438
return nil
3539
}
3640

@@ -100,20 +104,32 @@ func (cmd *UpdateCmd) Run() (err error) {
100104
return err
101105
}
102106

103-
registry, err := utils.OpenRegistry()
104-
registry.Remove(entry.FilePath) // Remove old file from registry
107+
// Integrated The AppImage To Desktop
108+
err = utils.CreateDesktopIntegration(targetFilePath)
109+
if err != nil {
110+
os.Remove(targetFilePath)
111+
return err
112+
}
105113

114+
registry, err := utils.OpenRegistry()
106115
if err != nil {
107116
return err
108117
}
109118

110-
// Integrated The AppImage To Desktop
111-
err = utils.CreateDesktopIntegration(targetFilePath)
119+
// De-Integrate old app from desktop
120+
err = utils.RemoveDesktopIntegration(entry.FilePath)
112121
if err != nil {
113-
os.Remove(targetFilePath)
122+
os.Remove(targetFilePath) // If error, remove the newly downloaded appimage.
114123
return err
124+
} else {
125+
err = os.Remove(entry.FilePath) // Remove the old appimage
126+
if err != nil {
127+
fmt.Println("Cannot Remove The Old AppImage.\n", err.Error())
128+
}
115129
}
116130

131+
registry.Remove(entry.FilePath) // Remove Old File From Registry
132+
117133
sha1hash, _ := utils.GetFileSHA1(targetFilePath)
118134
appImageInfo, _ := utils.GetAppImageInfo(targetFilePath)
119135
err = registry.Add(utils.RegistryEntry{
@@ -129,14 +145,6 @@ func (cmd *UpdateCmd) Run() (err error) {
129145
return err
130146
}
131147

132-
// De-Integrate old app from desktop
133-
err = utils.RemoveDesktopIntegration(entry.FilePath)
134-
if err != nil {
135-
os.Remove(targetFilePath)
136-
return err
137-
}
138-
139-
registry.Remove(entry.FilePath)
140148
err = registry.Close()
141149
if err != nil {
142150
return err
@@ -179,7 +187,6 @@ func (cmd *UpdateCmd) getRegistryEntry(target string) (utils.RegistryEntry, erro
179187
defer registry.Close()
180188

181189
entry, _ := registry.Lookup(target)
182-
entry.FilePath = target
183190

184191
return entry, nil
185192
}

0 commit comments

Comments
 (0)