Skip to content

Commit

Permalink
Use getmtime instead of getctime
Browse files Browse the repository at this point in the history
On Linux getctime doesn't represent a time of a file creation
but rather a time of the latest metadata change. It turns
out it doesn't work well for the NEWA use case and therefore
switching to getmtime.
  • Loading branch information
kkaarreell committed Jan 10, 2025
1 parent e759252 commit 53153c6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions newa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def get_state_dir(use_ppid: bool = False) -> Path:
# return initial value run-1
return STATEDIR_PARENT_DIR / f'run-{counter+1}'
dirs = sorted([d for d in obj if d.is_dir()],
key=lambda d: os.path.getctime(d))
key=lambda d: os.path.getmtime(d))
for statedir in dirs:
# when using ppid find the most recent (using getctime) matching dir
# when using ppid find the most recent (using getmtime) matching dir
if use_ppid:
ppid_file = Path(statedir.path) / ppid_filename
if ppid_file.exists():
Expand Down Expand Up @@ -259,7 +259,7 @@ def cmd_list(ctx: CLIContext, last: int) -> None:
entries = os.scandir(STATEDIR_PARENT_DIR)
except FileNotFoundError as e:
raise Exception(f'{STATEDIR_PARENT_DIR} does not exist') from e
sorted_entries = sorted(entries, key=lambda entry: os.path.getctime(Path(entry)))
sorted_entries = sorted(entries, key=lambda entry: os.path.getmtime(Path(entry)))
state_dirs = [Path(e.path) for e in sorted_entries[-last:]]

def _print(indent: int, s: str, end: str = '\n') -> None:
Expand Down

0 comments on commit 53153c6

Please sign in to comment.