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

When a file is changed in a memfs volume, its ctime does not update. #901

Closed
thomasperi opened this issue Apr 4, 2023 · 3 comments · Fixed by #891
Closed

When a file is changed in a memfs volume, its ctime does not update. #901

thomasperi opened this issue Apr 4, 2023 · 3 comments · Fixed by #891
Labels

Comments

@thomasperi
Copy link

mtime and atime both seem to behave as expected, but ctime does not.

Seems like it could be related to #891 and #889

Here's a test I wrote that fails when using a memfs volume but passes when using the real 'fs':

const fs = require('fs');
const path = require('path');
const assert = require('assert');
const { Volume } = require('memfs');

describe('memfs ctime', async () => {

  it('should change ctime', async () => {
    const vol = new Volume();
    
    const _fs_ = vol; // test fails
    // const _fs_ = fs; // test passes
    
    const file = '/tmp/test-memfs-ctime.txt';
    
    // Wait 1ms between actions to be sure the times change.
    const sleep = () => new Promise(resolve => setTimeout(resolve, 1));

    // Create the file if it doesn't exist.
    _fs_.mkdirSync(path.dirname(file), {recursive: true});
    _fs_.closeSync(_fs_.openSync(file, 'a'));
    
    // Get the ctime before any changes.
    let initial = _fs_.statSync(file).ctimeMs;
    
    // Get the ctime after writing to the file.
    await sleep();
    _fs_.writeFileSync(file, 'testing memfs ctime', 'utf8');
    let afterWrite = _fs_.statSync(file).ctimeMs;

    // Get the ctime after changing the file's atime and mtime.
    await sleep();
    let oneSecondAgo = new Date(Date.now() - 1000);
    _fs_.utimesSync(file, oneSecondAgo, oneSecondAgo);
    let afterMtimeChange = _fs_.statSync(file).ctimeMs;
    
    assert(afterWrite > initial, 'ctime should be greater after write than before');
    assert(afterMtimeChange > afterWrite, 'ctime should be greater after utimes change than before');
  });

});
@G-Rath
Copy link
Collaborator

G-Rath commented Apr 4, 2023

Would you mind seeing if your test passes with the changes from #891?

@thomasperi
Copy link
Author

Indeed it does!

@streamich
Copy link
Owner

🎉 This issue has been resolved in version 3.5.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants