From b99d16b71261c07bc204b9fcae90c78671e091e0 Mon Sep 17 00:00:00 2001 From: its-josh4 <74079536+its-josh4@users.noreply.github.com> Date: Sun, 22 Oct 2023 14:20:41 -0700 Subject: [PATCH] Some cosmetic fixes from #4106 (#4236) --- internal/desktop/systray_nixes.go | 7 ++++--- internal/desktop/systray_nonlinux.go | 9 ++++----- pkg/sqlite/database.go | 17 ++++++++--------- pkg/sqlite/migrations/45_postmigrate.go | 14 +++++++------- pkg/sqlite/setup_test.go | 6 +++--- 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/internal/desktop/systray_nixes.go b/internal/desktop/systray_nixes.go index b76bcae0c..1252b6759 100644 --- a/internal/desktop/systray_nixes.go +++ b/internal/desktop/systray_nixes.go @@ -1,10 +1,11 @@ -//go:build !windows && !darwin -// +build !windows,!darwin +//go:build (!windows && !darwin) || !cgo package desktop func startSystray(shutdownHandler ShutdownHandler, favicon FaviconProvider) { - // The systray is not available on linux because the required libraries (libappindicator3 and gtk+3.0) + // The systray is not available on Linux because the required libraries (libappindicator3 and gtk+3.0) // are not able to be statically compiled. Technically, the systray works perfectly fine when dynamically // linked, but we cannot distribute it for compatibility reasons. + // Additionally, the systray package requires CGo so the dependency cannot be used if building with + // CGo disabled. } diff --git a/internal/desktop/systray_nonlinux.go b/internal/desktop/systray_nonlinux.go index a565a930c..f454b5cbe 100644 --- a/internal/desktop/systray_nonlinux.go +++ b/internal/desktop/systray_nonlinux.go @@ -1,5 +1,4 @@ -//go:build windows || darwin -// +build windows darwin +//go:build (windows || darwin) && cgo package desktop @@ -7,15 +6,15 @@ import ( "strings" "github.com/kermieisinthehouse/systray" - "github.com/stashapp/stash/internal/manager/config" - "github.com/stashapp/stash/pkg/logger" "golang.org/x/text/cases" "golang.org/x/text/language" + + "github.com/stashapp/stash/internal/manager/config" + "github.com/stashapp/stash/pkg/logger" ) // MUST be run on the main goroutine or will have no effect on macOS func startSystray(shutdownHandler ShutdownHandler, faviconProvider FaviconProvider) { - // Shows a small notification to inform that Stash will no longer show a terminal window, // and instead will be available in the tray. Will only show the first time a pre-desktop integration // system is started from a non-terminal method, e.g. double-clicking an icon. diff --git a/pkg/sqlite/database.go b/pkg/sqlite/database.go index 75a0f42a9..36e6fc206 100644 --- a/pkg/sqlite/database.go +++ b/pkg/sqlite/database.go @@ -145,7 +145,7 @@ func (db *Database) Open(dbPath string) error { if databaseSchemaVersion == 0 { // new database, just run the migrations if err := db.RunMigrations(); err != nil { - return fmt.Errorf("error running initial schema migrations: %v", err) + return fmt.Errorf("error running initial schema migrations: %w", err) } } else { if databaseSchemaVersion > appSchemaVersion { @@ -241,12 +241,12 @@ func (db *Database) Remove() error { err := db.Close() if err != nil { - return errors.New("Error closing database: " + err.Error()) + return fmt.Errorf("error closing database: %w", err) } err = os.Remove(databasePath) if err != nil { - return errors.New("Error removing database: " + err.Error()) + return fmt.Errorf("error removing database: %w", err) } // remove the -shm, -wal files ( if they exist ) @@ -255,7 +255,7 @@ func (db *Database) Remove() error { if exists, _ := fsutil.FileExists(wf); exists { err = os.Remove(wf) if err != nil { - return errors.New("Error removing database: " + err.Error()) + return fmt.Errorf("error removing database: %w", err) } } } @@ -278,21 +278,20 @@ func (db *Database) Reset() error { // Backup the database. If db is nil, then uses the existing database // connection. -func (db *Database) Backup(backupPath string) error { +func (db *Database) Backup(backupPath string) (err error) { thisDB := db.db if thisDB == nil { - var err error thisDB, err = sqlx.Connect(sqlite3Driver, "file:"+db.dbPath+"?_fk=true") if err != nil { - return fmt.Errorf("open database %s failed: %v", db.dbPath, err) + return fmt.Errorf("open database %s failed: %w", db.dbPath, err) } defer thisDB.Close() } logger.Infof("Backing up database into: %s", backupPath) - _, err := thisDB.Exec(`VACUUM INTO "` + backupPath + `"`) + _, err = thisDB.Exec(`VACUUM INTO "` + backupPath + `"`) if err != nil { - return fmt.Errorf("vacuum failed: %v", err) + return fmt.Errorf("vacuum failed: %w", err) } return nil diff --git a/pkg/sqlite/migrations/45_postmigrate.go b/pkg/sqlite/migrations/45_postmigrate.go index ee205788b..dbb45af1e 100644 --- a/pkg/sqlite/migrations/45_postmigrate.go +++ b/pkg/sqlite/migrations/45_postmigrate.go @@ -38,7 +38,7 @@ func post45(ctx context.Context, db *sqlx.DB) error { }, }, }); err != nil { - return err + return fmt.Errorf("failed to migrate images table for tags: %w", err) } if err := m.migrateImagesTable(ctx, migrateImagesTableOptions{ @@ -52,7 +52,7 @@ func post45(ctx context.Context, db *sqlx.DB) error { }, }, }); err != nil { - return err + return fmt.Errorf("failed to migrate images table for studios: %w", err) } if err := m.migrateImagesTable(ctx, migrateImagesTableOptions{ @@ -66,7 +66,7 @@ func post45(ctx context.Context, db *sqlx.DB) error { }, }, }); err != nil { - return err + return fmt.Errorf("failed to migrate images table for performers: %w", err) } if err := m.migrateImagesTable(ctx, migrateImagesTableOptions{ @@ -80,7 +80,7 @@ func post45(ctx context.Context, db *sqlx.DB) error { }, }, }); err != nil { - return err + return fmt.Errorf("failed to migrate images table for scenes: %w", err) } if err := m.migrateImagesTable(ctx, migrateImagesTableOptions{ @@ -98,7 +98,7 @@ func post45(ctx context.Context, db *sqlx.DB) error { }, }, }); err != nil { - return err + return fmt.Errorf("failed to migrate images table for movies: %w", err) } tablesToDrop := []string{ @@ -111,12 +111,12 @@ func post45(ctx context.Context, db *sqlx.DB) error { for _, table := range tablesToDrop { if err := m.dropTable(ctx, table); err != nil { - return err + return fmt.Errorf("failed to drop table %s: %w", table, err) } } if err := m.migrateConfig(ctx); err != nil { - return err + return fmt.Errorf("failed to migrate config: %w", err) } return nil diff --git a/pkg/sqlite/setup_test.go b/pkg/sqlite/setup_test.go index 2ee524f1f..71c64e052 100644 --- a/pkg/sqlite/setup_test.go +++ b/pkg/sqlite/setup_test.go @@ -600,10 +600,10 @@ func runTests(m *testing.M) int { err = populateDB() if err != nil { panic(fmt.Sprintf("Could not populate database: %s", err.Error())) - } else { - // run the tests - return m.Run() } + + // run the tests + return m.Run() } func populateDB() error {