[WIP] Remove updater index filename setting

This commit is contained in:
Vladimir Stoilov
2024-10-18 16:45:47 +03:00
parent 68f5bf73e1
commit d6812bb4ef
6 changed files with 17 additions and 23 deletions

View File

@@ -22,7 +22,6 @@ import (
type Downloader struct {
dir string
indexFile string
indexURLs []string
bundle *Bundle
version *semver.Version
@@ -33,7 +32,6 @@ type Downloader struct {
func CreateDownloader(index UpdateIndex) Downloader {
return Downloader{
dir: index.DownloadDirectory,
indexFile: index.IndexFile,
indexURLs: index.IndexURLs,
}
}
@@ -78,7 +76,7 @@ func (d *Downloader) downloadIndexFile(ctx context.Context) error {
}
// Write the content into a file.
indexFilepath := filepath.Join(d.dir, d.indexFile)
indexFilepath := filepath.Join(d.dir, indexFilename)
err = os.WriteFile(indexFilepath, []byte(content), defaultFileMode)
if err != nil {
return fmt.Errorf("failed to write index file: %w", err)
@@ -98,7 +96,7 @@ func (d *Downloader) Verify() error {
}
func (d *Downloader) parseBundle() error {
indexFilepath := filepath.Join(d.dir, d.indexFile)
indexFilepath := filepath.Join(d.dir, indexFilename)
var err error
d.bundle, err = LoadBundle(indexFilepath)
if err != nil {

View File

@@ -18,6 +18,8 @@ const (
updateFailedNotificationID = "updates:update-failed"
corruptInstallationNotificationID = "updates:corrupt-installation"
indexFilename = "index.json"
// ResourceUpdateEvent is emitted every time the
// updater successfully performed a resource update.
ResourceUpdateEvent = "resource update"
@@ -39,7 +41,6 @@ type UpdateIndex struct {
PurgeDirectory string
Ignore []string
IndexURLs []string
IndexFile string
AutoApply bool
NeedsRestart bool
}
@@ -176,7 +177,6 @@ func (u *Updates) UpdateFromURL(url string) error {
index := UpdateIndex{
DownloadDirectory: u.downloader.dir,
IndexURLs: []string{url},
IndexFile: u.downloader.indexFile,
}
// Initialize with proper values and download the index file.
@@ -214,7 +214,7 @@ func (u *Updates) applyUpdates(downloader Downloader, force bool) error {
log.Infof("update: starting update: %s %s -> %s", currentBundle.Name, currentBundle.Version, downloadBundle.Version)
}
err := u.registry.performRecoverableUpgrade(downloader.dir, downloader.indexFile)
err := u.registry.performRecoverableUpgrade(downloader.dir, indexFilename)
if err != nil {
// Notify the user that update failed.
notifications.NotifyPrompt(updateFailedNotificationID, "Failed to apply update.", err.Error())

View File

@@ -36,7 +36,7 @@ func CreateRegistry(index UpdateIndex) (Registry, error) {
}
// Parse bundle
var err error
registry.bundle, err = LoadBundle(filepath.Join(index.Directory, index.IndexFile))
registry.bundle, err = LoadBundle(filepath.Join(index.Directory, indexFilename))
if err != nil {
return Registry{}, err
}