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

JS file system: distinguish between atime, mtime, and ctime #22998

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

hoodmane
Copy link
Contributor

@hoodmane hoodmane commented Nov 25, 2024

This improves posix compliance of the file system.

Consider the following file:

#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>

static void create_file(const char *path, const char *buffer, int mode) {
  printf("creating: %s\n", path);
  int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
  assert(fd >= 0);

  int err = write(fd, buffer, sizeof(char) * strlen(buffer));
  assert(err ==  (sizeof(char) * strlen(buffer)));

  close(fd);
}

int main() {
    create_file("file", "test", 0555);
    struct stat buf1;
    stat("file", &buf1);
    sleep(1);
    chmod("file", 0777);
    struct stat buf2;
    stat("file", &buf2);
    printf("delta mtime: %ld\n", buf2.st_atim.tv_sec - buf1.st_atim.tv_sec);
    unlink("file");
}

Compiling and running with gcc vs emcc gives different output because the chmod updated the mtime of the file in Emscripten but not in linux:

$ gcc a.c
$ ./a.c
creating: file
delta mtime: 0
$ emcc a.c
$ node a.out.js
creating: file
delta mtime: 1

@hoodmane
Copy link
Contributor Author

@sbc100 the tests assert that ctime changed. But mtime and atime should not change. These are all a single property in the memfs, so without recording distinct times for them we can't satisfy both requirements at once...

@hoodmane
Copy link
Contributor Author

I guess I'll just remove the assertions that say the time did change then.

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

lgtm!

Perhaps that change description needs updating?

Also, the codesize tests might need updating test/runner other.*code_size* other.*codesize* --rebase.

src/library_lz4.js Outdated Show resolved Hide resolved
src/library_lz4.js Outdated Show resolved Hide resolved
src/library_lz4.js Show resolved Hide resolved
src/library_nodefs.js Outdated Show resolved Hide resolved
src/library_noderawfs.js Outdated Show resolved Hide resolved
@hoodmane hoodmane changed the title Make chmod not update file access/modification time JS file system: distinguish between atime, mtime, and ctime Nov 26, 2024
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

I wonder if this warrants a Changelog entry?

@hoodmane
Copy link
Contributor Author

Probably this merits a changelog entry yes.

src/library_fs.js Outdated Show resolved Hide resolved
src/tmp.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for working on this.

@@ -24,6 +24,9 @@ See docs/process.md for more on how version tagging works.
3.1.73 - 11/28/24
-----------------
- libunwind was updated to LLVM 19.1.4. (#22394)
- mimalloc was updated to 2.1.7. (#21548)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder how this line ended up here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I managed to remove it in #23017 and add it here...

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.

3 participants