Skip to content

Commit

Permalink
typo and minor fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Jul 2, 2024
1 parent 7b59ee5 commit d2ff20d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
20 changes: 8 additions & 12 deletions internal/config/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion model/fix/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d2ff20d

Please sign in to comment.