mirror of
https://github.com/safing/portmaster
synced 2025-09-07 21:19:11 +00:00
[WIP] Fix uninstaller deletion bug.
This commit is contained in:
parent
f0272766c1
commit
97ce3c087c
2 changed files with 19 additions and 20 deletions
|
@ -1,6 +1,7 @@
|
||||||
package updates
|
package updates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
@ -22,10 +23,14 @@ const (
|
||||||
ResourceUpdateEvent = "resource update"
|
ResourceUpdateEvent = "resource update"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
// UserAgent is an HTTP User-Agent that is used to add
|
// UserAgent is an HTTP User-Agent that is used to add
|
||||||
// more context to requests made by the registry when
|
// more context to requests made by the registry when
|
||||||
// fetching resources from the update server.
|
// fetching resources from the update server.
|
||||||
var UserAgent = fmt.Sprintf("Portmaster (%s %s)", runtime.GOOS, runtime.GOARCH)
|
UserAgent = fmt.Sprintf("Portmaster (%s %s)", runtime.GOOS, runtime.GOARCH)
|
||||||
|
|
||||||
|
ErrNotFound error = errors.New("file not found")
|
||||||
|
)
|
||||||
|
|
||||||
// UpdateIndex holds the configuration for the updates module.
|
// UpdateIndex holds the configuration for the updates module.
|
||||||
type UpdateIndex struct {
|
type UpdateIndex struct {
|
||||||
|
@ -193,7 +198,7 @@ func (u *Updates) GetRootPath() string {
|
||||||
return u.registry.dir
|
return u.registry.dir
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFile returns the path of a file given the name.
|
// GetFile returns the path of a file given the name. Returns ErrNotFound if file is not found.
|
||||||
func (u *Updates) GetFile(id string) (*File, error) {
|
func (u *Updates) GetFile(id string) (*File, error) {
|
||||||
file, ok := u.registry.files[id]
|
file, ok := u.registry.files[id]
|
||||||
if ok {
|
if ok {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package updates
|
package updates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
@ -71,13 +70,7 @@ func (r *Registry) performUpgrade(downloadDir string, indexFile string) error {
|
||||||
// Make sure purge dir is empty.
|
// Make sure purge dir is empty.
|
||||||
_ = os.RemoveAll(r.purgeDir)
|
_ = os.RemoveAll(r.purgeDir)
|
||||||
|
|
||||||
// Read all files in the current version folder.
|
// Create purge dir.
|
||||||
files, err := os.ReadDir(r.dir)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create purge dir. Calling this after ReadDIr is important.
|
|
||||||
err = os.MkdirAll(r.purgeDir, defaultDirMode)
|
err = os.MkdirAll(r.purgeDir, defaultDirMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create directory: %w", err)
|
return fmt.Errorf("failed to create directory: %w", err)
|
||||||
|
@ -85,12 +78,11 @@ func (r *Registry) performUpgrade(downloadDir string, indexFile string) error {
|
||||||
|
|
||||||
// Move current version files into purge folder.
|
// Move current version files into purge folder.
|
||||||
log.Debugf("updates: removing the old version")
|
log.Debugf("updates: removing the old version")
|
||||||
for _, file := range files {
|
for _, file := range r.files {
|
||||||
currentFilepath := filepath.Join(r.dir, file.Name())
|
purgePath := filepath.Join(r.purgeDir, file.id)
|
||||||
purgePath := filepath.Join(r.purgeDir, file.Name())
|
err := moveFile(file.path, purgePath)
|
||||||
err := moveFile(currentFilepath, purgePath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to move file %s: %w", currentFilepath, err)
|
return fmt.Errorf("failed to move file %s: %w", file.path, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,20 +198,22 @@ type File struct {
|
||||||
sha256 string
|
sha256 string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Identifier return the id of the file witch is the same as the filename.
|
||||||
func (f *File) Identifier() string {
|
func (f *File) Identifier() string {
|
||||||
return f.id
|
return f.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Path returns the path + filename of the file.
|
||||||
func (f *File) Path() string {
|
func (f *File) Path() string {
|
||||||
return f.path
|
return f.path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Version returns the version of the file. (currently not filled).
|
||||||
func (f *File) Version() string {
|
func (f *File) Version() string {
|
||||||
return f.version
|
return f.version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sha256 returns the sha356 sum of the file.
|
||||||
func (f *File) Sha256() string {
|
func (f *File) Sha256() string {
|
||||||
return f.sha256
|
return f.sha256
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrNotFound error = errors.New("file not found")
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue