Set Correct Mod Time for New Files
This commit is contained in:
parent
bae1112074
commit
f12462250a
1 changed files with 5 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue