Skip to content

Commit

Permalink
renamed ctime and mtime to creation_time and modification_time for mo…
Browse files Browse the repository at this point in the history
…re clarification
  • Loading branch information
Barakudum committed Feb 8, 2024
1 parent 67cf103 commit 36af62b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/jarklin/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ._cache_generator import CacheGenerator
from .video import VideoCacheGenerator
from .gallery import GalleryCacheGenerator
from .util import is_video_file, is_gallery, is_deprecated, is_incomplete, get_ctime, get_mtime
from .util import is_video_file, is_gallery, is_deprecated, is_incomplete, get_creation_time, get_modification_time


__all__ = ['Cache']
Expand Down Expand Up @@ -121,8 +121,8 @@ def generate_info_file():
path=str(source.relative_to(self.root)),
name=source.stem,
ext=source.suffix,
ctime=get_ctime(source),
mtime=get_mtime(source),
creation_time=get_creation_time(source),
modification_time=get_modification_time(source),
meta=json.loads(dest.joinpath("meta.json").read_bytes()),
))
except FileNotFoundError:
Expand Down
20 changes: 11 additions & 9 deletions src/jarklin/cache/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import logging
import mimetypes
import os.path as p
from pathlib import Path
from ..common.types import PathSource
try:
Expand Down Expand Up @@ -52,33 +53,34 @@ def is_deprecated(source: PathSource, dest: PathSource) -> bool:
if not dest.exists():
return True
if source.is_dir(): # gallery
source_mtime = max(fp.stat().st_mtime for fp in source.iterdir() if fp.is_file())
source_mtime = max(p.getmtime(fp) for fp in source.iterdir() if fp.is_file())
else:
source_mtime = source.stat().st_mtime
return source_mtime > dest.stat().st_mtime
source_mtime = p.getmtime(source)
return source_mtime > p.getmtime(dest)


def is_incomplete(dest: PathSource) -> bool:
dest = Path(dest)
return next(dest.glob("*.type"), None) is None


def get_ctime(path: PathSource) -> float:
def get_creation_time(path: PathSource) -> float:
# fixme: ctime != creation-time on unix
path = Path(path)
if path.is_file():
return path.stat().st_ctime
return int(p.getctime(path))
elif path.is_dir():
return min(p.stat().st_ctime for p in path.iterdir() if p.is_file())
return min(int(p.getctime(fp)) for fp in path.iterdir() if fp.is_file())
else:
raise ValueError(f"can't get ctime for {str(path)!r}")


def get_mtime(path: PathSource) -> float:
def get_modification_time(path: PathSource) -> float:
path = Path(path)
if path.is_file():
return path.stat().st_mtime
return int(p.getmtime(path))
elif path.is_dir():
times = [p.stat().st_mtime for p in path.iterdir() if p.is_file()]
times = [int(p.getmtime(fp)) for fp in path.iterdir() if fp.is_file()]
minimum = min(times)
maximum = max(times)
# assume that it took at least one hour for the gallery to be created (e.g. download-time)
Expand Down
4 changes: 2 additions & 2 deletions src/jarklin/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class InfoEntry(_t.TypedDict):
path: str
name: str
ext: str
ctime: float
mtime: float
creation_time: float
modification_time: float
meta: _t.Union['GalleryMeta', 'VideoMeta']


Expand Down

0 comments on commit 36af62b

Please sign in to comment.