diff --git a/cmd/cmd b/cmd/cmd index 9aa49c5..f2cc74f 100755 Binary files a/cmd/cmd and b/cmd/cmd differ diff --git a/common/main.go b/common/main.go index 2a25a77..eded6c8 100644 --- a/common/main.go +++ b/common/main.go @@ -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 } diff --git a/lib/main.go b/lib/main.go index fc181bb..95b5fa4 100644 --- a/lib/main.go +++ b/lib/main.go @@ -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) }