Fixed packages not removing properly when not assigned to a repository

This commit is contained in:
Arzumify 2024-09-17 19:30:39 +01:00
parent 791b3a5fb9
commit d2d6fcc8dd
3 changed files with 17 additions and 20 deletions

BIN
cmd/cmd

Binary file not shown.

View file

@ -61,7 +61,9 @@ type Plugin struct {
}
var conn *sql.DB
var dbVersion = semver.MustParse("1.0.0")
// Database is no longer compatible with version 1.0.0
var dbVersion = semver.MustParse("2.0.0")
var DefaultLogger = lib.Logger{
LogFunc: func(log lib.Log) string {
@ -513,11 +515,13 @@ func InitDB(conn *sql.DB) error {
return err
}
_, err = conn.Exec("CREATE TABLE repositories (url TEXT NOT NULL UNIQUE, name TEXT NOT NULL UNIQUE, owner TEXT NOT NULL, description TEXT NOT NULL)")
_, err = conn.Exec("CREATE TABLE repositories (url TEXT NOT NULL UNIQUE, name TEXT NOT NULL UNIQUE, owner TEXT NOT NULL, description TEXT NOT NULL, ignore BOOLEAN NOT NULL DEFAULT false)")
if err != nil {
return err
}
_, err = conn.Exec("INSERT INTO repositories (url, name, owner, description, ignore) VALUES ('None', 'Local file', 'eon', 'This is a placeholder repository for local files to be registered to. Do not attempt to use this repository.', true)")
// Way to big. Blame IntelliJ.
_, err = conn.Exec("CREATE TABLE remotePackages (name TEXT NOT NULL UNIQUE, author TEXT NOT NULL, description TEXT NOT NULL, version TEXT NOT NULL, architecture TEXT NOT NULL, size BLOB NOT NULL, dependencies TEXT NOT NULL, path TEXT NOT NULL, arch TEXT NOT NULL, hash TEXT NOT NULL, repository TEXT NOT NULL)")
if err != nil {
@ -655,7 +659,7 @@ func EstablishDBConnection(logger *lib.Logger) error {
return nil
}
func DefaultAddEPKToDB(metadata *lib.Metadata, installedPaths []string, removeScript []byte, dependency bool, hasRemoveScript bool, size int64, decompressedSize *big.Int, repository ...string) error {
func DefaultAddEPKToDB(metadata *lib.Metadata, installedPaths []string, removeScript []byte, dependency bool, hasRemoveScript bool, size int64, decompressedSize *big.Int, repository string) error {
// If it already exists, delete it. This may happen in a force-install scenario.
_, err := conn.Exec("DELETE FROM packages WHERE name = ?", metadata.Name)
if err != nil {
@ -687,17 +691,10 @@ func DefaultAddEPKToDB(metadata *lib.Metadata, installedPaths []string, removeSc
// Not that I'm complaining or anything.
// - Arzumify
if len(repository) > 0 {
_, err = conn.Exec("INSERT INTO packages (name, description, longDescription, version, author, license, architecture, size, dependencies, removeScript, hasRemoveScript, isDependency, repository, installedPaths, decompressedSize) VALUES (?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
metadata.Name, metadata.Description, metadata.LongDescription, metadata.Version.String(), metadata.Author,
metadata.License, metadata.Architecture, size, dependencies, string(removeScript), hasRemoveScript, dependency,
repository[0], installedPathsString, decompressedSize.Bytes())
} else {
_, err = conn.Exec("INSERT INTO packages (name, description, longDescription, version, author, license, architecture, size, dependencies, removeScript, hasRemoveScript, isDependency, installedPaths, decompressedSize) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
metadata.Name, metadata.Description, metadata.LongDescription, metadata.Version.String(), metadata.Author,
metadata.License, metadata.Architecture, size, dependencies, string(removeScript), hasRemoveScript, dependency,
installedPathsString, decompressedSize.Bytes())
}
_, err = conn.Exec("INSERT INTO packages (name, description, longDescription, version, author, license, architecture, size, dependencies, removeScript, hasRemoveScript, isDependency, repository, installedPaths, decompressedSize) VALUES (?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
metadata.Name, metadata.Description, metadata.LongDescription, metadata.Version.String(), metadata.Author,
metadata.License, metadata.Architecture, size, dependencies, string(removeScript), hasRemoveScript, dependency,
repository, installedPathsString, decompressedSize.Bytes())
if err != nil {
return err
}
@ -928,7 +925,7 @@ func DefaultCheckRepositoryInDB(repository string) (bool, error) {
}
func DefaultListRepositoriesInDB() ([]lib.Repository, error) {
rows, err := conn.Query("SELECT url, name, owner, description FROM repositories")
rows, err := conn.Query("SELECT url, name, owner, description FROM repositories WHERE ignore = false")
if err != nil {
return []lib.Repository{}, err
}

View file

@ -849,7 +849,7 @@ func (writer *ProgressWriter) Write(p []byte) (n int, err error) {
}
// InstallEPK installs an EPK file
func InstallEPK(epkBytes StreamOrBytes, metadata *Metadata, preMap *EPKPreMap, addEPKToDB func(*Metadata, []string, []byte, bool, bool, int64, *big.Int, ...string) error, logger *Logger) (string, error, error) {
func InstallEPK(epkBytes StreamOrBytes, metadata *Metadata, preMap *EPKPreMap, addEPKToDB func(*Metadata, []string, []byte, bool, bool, int64, *big.Int, string) error, logger *Logger) (string, error, error) {
// Create the temporary directory
tempDir, err := os.MkdirTemp("/tmp", "eon-install-")
if err != nil {
@ -1190,22 +1190,22 @@ func InstallEPK(epkBytes StreamOrBytes, metadata *Metadata, preMap *EPKPreMap, a
file, err := os.ReadFile(filepath.Join(tempDir, "hooks", "remove.sh"))
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
return tempDir, err, ErrInstallEPKCouldNotAddEPKToDB
} else {
var err error
if !epkBytes.IsRemote {
err = addEPKToDB(metadata, installedFiles, []byte{}, preMap.DisplayData.IsDependency, false, metadata.Size, metadata.DecompressedSize)
err = addEPKToDB(metadata, installedFiles, []byte{}, preMap.DisplayData.IsDependency, false, metadata.Size, metadata.DecompressedSize, "Local file")
} else {
err = addEPKToDB(metadata, installedFiles, []byte{}, preMap.DisplayData.IsDependency, false, metadata.Size, metadata.DecompressedSize, epkBytes.RepositoryName)
}
if err != nil {
return tempDir, err, ErrInstallEPKCouldNotAddEPKToDB
}
} else {
return tempDir, err, ErrInstallEPKCouldNotAddEPKToDB
}
} else {
var err error
if !epkBytes.IsRemote {
err = addEPKToDB(metadata, installedFiles, file, preMap.DisplayData.IsDependency, true, metadata.Size, metadata.DecompressedSize)
err = addEPKToDB(metadata, installedFiles, file, preMap.DisplayData.IsDependency, true, metadata.Size, metadata.DecompressedSize, "Local file")
} else {
err = addEPKToDB(metadata, installedFiles, file, preMap.DisplayData.IsDependency, true, metadata.Size, metadata.DecompressedSize, epkBytes.RepositoryName)
}