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

sys.FileStat.ctime is not accurate on Linux/macOS #619

Open
joshtynjala opened this issue Sep 11, 2023 · 0 comments
Open

sys.FileStat.ctime is not accurate on Linux/macOS #619

joshtynjala opened this issue Sep 11, 2023 · 0 comments

Comments

@joshtynjala
Copy link

joshtynjala commented Sep 11, 2023

Code to reproduce:

var filePath = "path/to/test.txt";
sys.io.File.saveContent(filePath, "hello");
trace("created:", sys.FileSystem.stat(filePath).ctime);
trace("modified:", sys.FileSystem.stat(filePath).mtime);
haxe.Timer.delay(() -> {
  sys.io.File.saveContent(filePath, "goodbye");
  trace("created:", sys.FileSystem.stat(filePath).ctime);
  trace("modified:", sys.FileSystem.stat(filePath).mtime);
}, 2000);

The creation time should not change, but it does.

The relevant code:

*i++ = s.st_ctime;

The value of st_ctime from stat() does not actually refer to the file creation time. It may be accurate when a file is first created, but this value may be updated after the file is modified in certain ways (apparently, including the file size changing, which is very common).

On Linux, the value of stx_btime.tv_sec from a separate statx() call may be used to get the actual file creation time.

On macOS, the value of st_birthtime from the existing stat() call may be used to get the actual file creation time.

I created a pull request for hxcpp with the necessary change, but I wasn't able to successfully build HashLink on macOS, so I'm simply reporting the issue instead.

Related hxpp pull: HaxeFoundation/hxcpp#1063

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

No branches or pull requests

1 participant