From d2ff20d85ac795e3957ab0ac2e44cec64a7d33e3 Mon Sep 17 00:00:00 2001 From: Ben Garrett Date: Tue, 2 Jul 2024 14:34:20 +1000 Subject: [PATCH] typo and minor fixes. --- internal/config/repair.go | 20 ++++++++------------ model/fix/fix.go | 6 +++++- server.go | 5 +++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/internal/config/repair.go b/internal/config/repair.go index 031034e5..9c912d4e 100644 --- a/internal/config/repair.go +++ b/internal/config/repair.go @@ -42,15 +42,11 @@ type contextKey string const LoggerKey contextKey = "logger" // TODO: complete. -func (c Config) pkzips(ctx context.Context, ce boil.ContextExecutor) error { //nolint:funlen,gocognit +func (c Config) pkzips(ctx context.Context, ce boil.ContextExecutor, logger *zap.SugaredLogger) error { //nolint:funlen,gocognit if ce == nil { return nil } tick := time.Now() - logger, useLogger := ctx.Value(LoggerKey).(*zap.SugaredLogger) - if !useLogger { - return fmt.Errorf("config repair uuids %w", ErrCtxLog) - } mods := []qm.QueryMod{} mods = append(mods, qm.Select("uuid")) mods = append(mods, qm.Where("platform = ?", tags.DOS.String())) @@ -162,15 +158,15 @@ func (c Config) pkzips(ctx context.Context, ce boil.ContextExecutor) error { //n // to the orphaned directory without warning. // // There are no checks on the 3 directories that get scanned. -func (c Config) assets(ctx context.Context, ce boil.ContextExecutor) error { +func (c Config) assets(ctx context.Context, ce boil.ContextExecutor, logger *zap.SugaredLogger) error { if ce == nil { return nil } tick := time.Now() - logger, useLogger := ctx.Value(LoggerKey).(*zap.SugaredLogger) - if !useLogger { - return fmt.Errorf("config repair uuids %w", ErrCtxLog) - } + // logger, useLogger := ctx.Value(LoggerKey).(*zap.SugaredLogger) + // if !useLogger { + // return fmt.Errorf("config repair uuids %w", ErrCtxLog) + // } mods := []qm.QueryMod{} mods = append(mods, qm.Select("uuid")) files, err := models.Files(mods...).All(ctx, ce) @@ -257,10 +253,10 @@ func (c Config) RepairFS(ctx context.Context, exec boil.ContextExecutor, logger if err := DownloadFS(logger, c.AbsDownload, c.AbsOrphaned, c.AbsExtra); err != nil { return fmt.Errorf("repair fs downloads %w", err) } - if err := c.assets(ctx, exec); err != nil { + if err := c.assets(ctx, exec, logger); err != nil { return fmt.Errorf("repair fs assets %w", err) } - if err := c.pkzips(ctx, exec); err != nil { + if err := c.pkzips(ctx, exec, logger); err != nil { return fmt.Errorf("repair fs pkzips %w", err) } return nil diff --git a/model/fix/fix.go b/model/fix/fix.go index 80f14e37..aec0d7de 100644 --- a/model/fix/fix.go +++ b/model/fix/fix.go @@ -61,7 +61,11 @@ const ( // In the future we may want to add a Debug or TestRun func. // Run the database repair based on the repair option. -func (r Repair) Run(ctx context.Context, db *sql.DB, tx *sql.Tx, logger *zap.SugaredLogger) error { +func (r Repair) Run(ctx context.Context, db *sql.DB, tx *sql.Tx) error { + logger, loggerExists := ctx.Value(LoggerKey).(*zap.SugaredLogger) + if loggerExists { + logger.Infof("Checking for records with invalid UUID values") + } logger.Infoln("Running a cleanup of the database", r) if r < None || r > Releaser { return fmt.Errorf("%w: %d", ErrRepair, r) diff --git a/server.go b/server.go index 3b01faba..49726236 100644 --- a/server.go +++ b/server.go @@ -141,7 +141,7 @@ func newInstance(ctx context.Context, exec boil.ContextExecutor, configs config. if c.Version == "" { c.Version = cmd.Commit("") } - if ctx == nil || exec == nil { + if ctx != nil && exec != nil { c.RecordCount = recordCount(ctx, exec) } return c @@ -262,7 +262,8 @@ func repairDatabase(ctx context.Context, db *sql.DB, tx *sql.Tx, logger *zap.Sug return fmt.Errorf("%w: %s", ErrPointer, "the repair database is missing a required parameter") } - if err := fix.Artifacts.Run(ctx, db, tx, logger); err != nil { + ctx = context.WithValue(ctx, fix.LoggerKey, logger) + if err := fix.Artifacts.Run(ctx, db, tx); err != nil { defer func() { if err := tx.Rollback(); err != nil { logger.Error(err)