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

Codechange: Replace platform-specific calls with std::filesystem::last_write_time. #12487

Merged
merged 1 commit into from Apr 15, 2024

Conversation

PeterN
Copy link
Member

@PeterN PeterN commented Apr 12, 2024

Motivation / Problem

fios.cpp has Windows and Unix specific code to determine the modification date of a file.

Description

Use std::filesystem::last_write_time instead. The modification time doesn't ever seem to be displayed, it is only used in sorting, so the values don't need to match their previous values.

Limitations

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@glx22
Copy link
Contributor

glx22 commented Apr 12, 2024

Master:
image

This PR:
image

The order is messed up.

In file explorer:
image

@PeterN
Copy link
Member Author

PeterN commented Apr 12, 2024

So this call just doesn't work on Windows?

Using milliseconds causes the uint64_t - uint64_t operation which is then placed into a int to behave differently. Worked around by using seconds instead of milliseconds.

@rubidium42
Copy link
Contributor

Using milliseconds causes the uint64_t - uint64_t operation which is then placed into a int to behave differently. Worked around by using seconds instead of milliseconds.

How is converting to seconds make it not have the same issues? Okay, maybe after 49 thousand instead of 49 days, but still not a completely insane timescale to think about. Especially when the solution is relatively trivial.

Before the epoch there are issues because we use a uint64_t instead of just int64_t which my 64 bit Linux uses. So the type of mtime should probably be changed to int64_t to prevent any issues with pre-(undefined-)epoch times.
Then milliseconds or seconds will be just fine if you use ClampTo<int32_t> like we do when comparing for example engine costs.

Copy link
Contributor

@rubidium42 rubidium42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me with saves from 1969, 1970, 1972, today, 2038, 2039 and 2300.

@PeterN PeterN enabled auto-merge (squash) April 15, 2024 17:53
@PeterN PeterN merged commit a1b03ee into OpenTTD:master Apr 15, 2024
15 checks passed
@PeterN PeterN deleted the file-mtime branch April 15, 2024 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants