Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrige la comparaison des dates de dernière modification des fichiers selon les systèmes d'exploitation #125

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions geotribu_cli/utils/file_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import logging
from datetime import datetime, timedelta
from pathlib import Path
from sys import platform as opersys
from typing import Literal

# ############################################################################
Expand All @@ -27,7 +28,7 @@
def is_file_older_than(
local_file_path: Path,
expiration_rotating_hours: int = 24,
dt_reference_mode: Literal["c", "m"] = "c",
dt_reference_mode: Literal["auto", "creation", "modification"] = "auto",
) -> bool:
"""Check if the creation/modification date of the specified file is older than the \
mount of hours.
Expand All @@ -36,14 +37,25 @@ def is_file_older_than(
local_file_path (Path): local path to the index file
expiration_rotating_hours (int, optional): number in hours to consider the \
local file outdated. Defaults to 24.
dt_reference_mode (Literal['c', 'm'], optional): reference date type: c for \
creation date, m for modification. Defaults to "c".
dt_reference_mode (Literal['auto', 'creation', 'modification'], optional):
reference date type: auto to handle differences between operating systems,
creation for creation date, modification for last modification date.
Defaults to "auto".

Returns:
bool: True if the creation/modification date of the file is older than the \
specified number of hours.
"""
# modification date varies depending on operating system: on some systems (like
# Unix) creation date is the time of the last metadata change, and, on others
# (like Windows), is the creation time for path.
if dt_reference_mode == "auto" and opersys == "win32":
dt_reference_mode = "modification"
else:
dt_reference_mode = "creation"

# get file reference datetime - modification or creation
if dt_reference_mode == "m":
if dt_reference_mode == "modification":
f_ref_dt = datetime.fromtimestamp(local_file_path.stat().st_mtime)
dt_type = "modified"
else:
Expand Down