Skip to content

Comments

feat: auto-update parent directory mtime on content changes (#186)#198

Open
Koan-Bot wants to merge 2 commits intocpanel:masterfrom
atoomic:koan.atoomic/dir-mtime-auto-update
Open

feat: auto-update parent directory mtime on content changes (#186)#198
Koan-Bot wants to merge 2 commits intocpanel:masterfrom
atoomic:koan.atoomic/dir-mtime-auto-update

Conversation

@Koan-Bot
Copy link
Contributor

Summary

Fixes #186. When files or directories are created or removed inside a mocked directory, the parent directory's mtime and ctime are now automatically updated to match real Linux filesystem behavior.

What changed

Added _update_parent_dir_times($path) helper that finds the mocked parent directory and bumps its mtime/ctime to time().

Instrumented these operations:

  • file() constructor — when file has defined contents
  • symlink() constructor — when symlink has defined target
  • unlink() method — when file/symlink is removed
  • __open() — when opening for write creates a new file (contents was previously undef)
  • __sysopen() — with O_CREAT on non-existent file
  • __mkdir() / __rmdir() — directory creation/removal

What didn't change

  • Writing to an existing file does not update parent dir mtime (matches real FS)
  • Files created with undef contents (nonexistent mocks) don't update parent mtime
  • No crash when parent directory isn't mocked

Test coverage

New test file t/dir_mtime.t with 10 subtests covering all instrumented operations, edge cases (no parent mock, existing file writes), and ctime co-update.


🤖 Generated with Claude Code

@atoomic
Copy link
Contributor

atoomic commented Feb 22, 2026

Failure from CI

    # Failed test 'directory has mtime'
    # at t/dir_mtime.t line 21.
    # Failed test 'Unexpected warning: Use of uninitialized value $dir_mtime_before in numeric gt (>) at t/dir_mtime.t line 27.'
    # [No trace info available]

# Failed test 'file creation updates parent dir mtime'
# at t/dir_mtime.t line 28.
    # Failed test 'Unexpected warning: Use of uninitialized value $parent_mtime_before in numeric gt (>) at t/dir_mtime.t line 73.'
    # [No trace info available]
    # Failed test 'Unexpected warning: Use of uninitialized value $parent_mtime_after in numeric gt (>) at t/dir_mtime.t line 73.'
    # [No trace info available]
    # Failed test 'parent dir mtime updated after mkdir'
    # at t/dir_mtime.t line 73.

# Failed test 'mkdir updates parent dir mtime'
# at t/dir_mtime.t line 75.
    # Failed test 'Unexpected warning: Use of uninitialized value $parent_mtime_before in numeric gt (>) at t/dir_mtime.t line 89.'
    # [No trace info available]
    # Failed test 'Unexpected warning: Use of uninitialized value $parent_mtime_after in numeric gt (>) at t/dir_mtime.t line 89.'
    # [No trace info available]
    # Failed test 'parent dir mtime updated after rmdir'
    # at t/dir_mtime.t line 89.

# Failed test 'rmdir updates parent dir mtime'
# at t/dir_mtime.t line 91.
    # Failed test 'Unexpected warning: Use of uninitialized value $dir_mtime_before in numeric gt (>) at t/dir_mtime.t line 108.'
    # [No trace info available]
    # Failed test 'Unexpected warning: Use of uninitialized value $dir_mtime_after in numeric gt (>) at t/dir_mtime.t line 108.'
    # [No trace info available]
    # Failed test 'dir mtime updated when open creates new file'
    # at t/dir_mtime.t line 108.

# Failed test 'open for write creates file and updates parent dir mtime'
# at t/dir_mtime.t line 110.
    # Failed test 'directory has ctime'
    # at t/dir_mtime.t line 150.
    # Failed test 'Unexpected warning: Use of uninitialized value $dir_ctime_before in numeric gt (>) at t/dir_mtime.t line 156.'
    # [No trace info available]

# Failed test 'ctime also updates alongside mtime'
# at t/dir_mtime.t line 157.
# Seeded srand with seed '20260222' from local date.
t/dir_mtime.t ....................... 

@atoomic
Copy link
Contributor

atoomic commented Feb 22, 2026

@Koan-Bot rebase

@Koan-Bot
Copy link
Contributor Author

The new_dir() fix (8c996cb) is already on this branch and addresses all the reported test failures. The tests were using dir() which creates a non-existent placeholder — stat returns empty for those. Changed to new_dir() which calls __mkdir internally, so directories exist immediately with proper stat values.

Branch is up to date with master (7d115e8). The CI failure was from before the fix was pushed — needs a fresh CI run.

@atoomic atoomic marked this pull request as ready for review February 22, 2026 16:43
Koan-Bot and others added 2 commits February 24, 2026 14:31
When files or directories are created/removed inside a mocked directory,
the parent directory's mtime and ctime are now updated to match real
filesystem behavior.

Instrumented operations:
- file() constructor (with defined contents)
- symlink() constructor (with defined target)
- unlink() method
- __open() when creating a new file (contents was undef)
- __sysopen() with O_CREAT on non-existent file
- __mkdir() and __rmdir()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dir() creates a mock placeholder that doesn't "exist" yet (has_content=0,
stat returns empty). Tests that stat the parent dir before creating
children need new_dir() which calls mkdir() to make the dir exist.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Koan-Bot Koan-Bot force-pushed the koan.atoomic/dir-mtime-auto-update branch from 8c996cb to 43e713c Compare February 24, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

When a mocked directories contents change the mocked parent directly mtime should also be updated.

2 participants