From f12462250ac22f1bdb1d460346d0a6eec3005b83 Mon Sep 17 00:00:00 2001 From: Samuel Lorch Date: Thu, 11 Jul 2024 19:24:15 +0200 Subject: [PATCH] Set Correct Mod Time for New Files --- server/scan.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/scan.go b/server/scan.go index fe9bddb..4eaf9c7 100644 --- a/server/scan.go +++ b/server/scan.go @@ -218,6 +218,10 @@ func scanLibrary(ctx context.Context, id int) { var fileID int var oldSize uint var oldModTime time.Time + + // Remove Timezone and Round to nearest Second + newModTime := info.ModTime().UTC().Round(time.Second) + err = db.QueryRow(ctx, "SELECT id, size, mod_time FROM files WHERE library_id = $1 AND path = $2", id, fPath).Scan(&fileID, &oldSize, &oldModTime) if errors.Is(err, pgx.ErrNoRows) { // File Does not Exist Yet @@ -230,7 +234,7 @@ func scanLibrary(ctx context.Context, id int) { } slog.InfoContext(ctx, "ffprobe Done", "path", fullPath) - _, err = db.Exec(ctx, "INSERT INTO files (library_id, path, size, status, health, ffprobe_data) VALUES ($1, $2, $3, $4, $5, $6)", id, fPath, info.Size(), constants.FILE_STATUS_NEW, constants.FILE_HEALTH_UNKNOWN, ffprobeData) + _, err = db.Exec(ctx, "INSERT INTO files (library_id, path, size, status, health, ffprobe_data, mod_time) VALUES ($1, $2, $3, $4, $5, $6, $7)", id, fPath, info.Size(), constants.FILE_STATUS_NEW, constants.FILE_HEALTH_UNKNOWN, ffprobeData, newModTime) if err != nil { slog.ErrorContext(ctx, "Add New File to DB", "err", err) } @@ -240,9 +244,6 @@ func scanLibrary(ctx context.Context, id int) { return fmt.Errorf("Getting File: %w", err) } - // Remove Timezone and Round to nearest Second - newModTime := info.ModTime().UTC().Round(time.Second) - // File Already Exists, Check if it has been changed if newModTime.Equal(oldModTime) && uint(info.Size()) == oldSize { slog.Debug("File stayed the same", "id", fileID)