Skip to content

Read newly created file timestamps for touch -a and -m - #1287

Open
FanWu-ai wants to merge 1 commit into
shelljs:mainfrom
FanWu-ai:fix-touch-create-selected-times-oct13
Open

FanWu-ai wants to merge 1 commit into
shelljs:mainfrom
FanWu-ai:fix-touch-create-selected-times-oct13

Conversation

@FanWu-ai

Copy link
Copy Markdown

touch('-a', path) and touch('-m', path) throw ShellJSInternalError when path does not exist, after already creating the empty file. The pre-creation stat is still null when the code reads the timestamp it should preserve. This also affects selective timestamp updates with a date/reference file and dangling symlink targets.

Read the new file's stat after creation when no original stat was available. Existing files retain their original stat, and -c still returns without creating a file.

Validation on Linux / Node.js 24.19.0:

  • Fresh baseline: 640 passed, 6 existing skips, including post-test lint.
  • 13 added cases: 10 fail against unchanged production code; 3 controls pass. Final focused suite: 29 passed.
  • Complete npm test and coverage runs: 653 passed, 6 existing skips each; touch.js has 100% statement/branch/function/line coverage.
  • Separate lint, check-node-support, generated-documentation consistency and git diff --check pass.
  • 24 additional comparisons with GNU touch pass across existing/new files, direct paths/symlinks, and current/date/reference timestamps.

The six existing explicit skips are in cmd.js: five async cases and the missing-exec-path case. Native Windows/macOS and other Node versions were not run locally; the two new symlink cases use the project's existing Windows skip helper.

Prepared and tested with AI assistance (OpenAI Codex). No human review is claimed.

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 12, 2026 21:53
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.

1 participant