can1357/oh-my-pi · error · TouchError
Source has invalid access or modification time: {0}
Error message
Source has invalid access or modification time: {0} What it means
This touch builtin error (crates/pi-builtins/src/touch.rs, InvalidFiletime) means the reference file's access or modification timestamp, retrieved for -r/--reference mode, is out of range or otherwise invalid when converted to the internal FileTime representation. Touch cannot propagate a timestamp it cannot represent. The offending value is included in the message.
Source
Thrown at crates/pi-builtins/src/touch.rs:43
use libc::O_NONBLOCK;
#[cfg(unix)]
use rustix::fs::Timestamps;
#[cfg(unix)]
use rustix::fs::futimens;
#[cfg(target_os = "linux")]
use uucore::libc;
use uucore::{display::Quotable, parser::shortcut_value_parser::ShortcutValueParser};
use brush_core::{ShellExtensions, builtins::Registration};
use thiserror::Error as ThisError;
use crate::host::{Host, Utility, format_usage, matches_parser, util};
#[derive(Debug, ThisError)]
enum TouchError {
#[error("Unable to parse date: {0}")]
InvalidDateFormat(String),
#[error("Source has invalid access or modification time: {0}")]
InvalidFiletime(FileTime),
#[error("failed to get attributes of {}: {}", .0.quote(), io_error(.1))]
ReferenceFileInaccessible(PathBuf, std::io::Error),
#[cfg(windows)]
#[error("GetFinalPathNameByHandleW failed with code {0}")]
WindowsStdoutPathError(String),
#[error("{0}")]
Message(String),
}
fn io_error(error: &std::io::Error) -> String {
if error.raw_os_error().is_some() {
match error.kind() {
ErrorKind::NotFound => "No such file or directory".into(),
ErrorKind::PermissionDenied => "Permission denied".into(),
ErrorKind::AlreadyExists => "Already exists".into(),
ErrorKind::WouldBlock => "Would block".into(),
_ => error.to_string().split(" (os error ").next().unwrap_or_default().into(),View on GitHub (pinned to 9690622007)
Solutions
- Choose a different reference file with a sane timestamp (`stat <file>` to inspect).
- Instead of -r, set the time explicitly: `touch -d '<timestamp>' target`.
- Normalize the reference file's time first (`touch reference`) if its timestamp is corrupt.
- Copy the file to a normal filesystem and use the copy as reference.
Example fix
// before touch -r /mnt/fat/oddfile target.txt // Source has invalid access or modification time // after touch -d '2026-01-01 00:00:00' target.txt
Defensive patterns
Strategy: fallback
Validate before calling
import { statSync } from 'node:fs';
function referenceTimeIsSane(p) {
const t = statSync(p).mtimeMs;
return Number.isFinite(t) && t > 0 && t < Date.now() + 3.15e12;
} Type guard
function isInvalidFiletimeError(err) {
return err instanceof Error && err.message.startsWith('Source has invalid access or modification time: ');
} Try / catch
try {
await touch.run(['-r', ref, target]);
} catch (err) {
if (String(err).startsWith('Source has invalid access or modification time')) {
// fall back to copying the reference's mtime explicitly
const { mtime } = statSync(ref);
await utimes(target, mtime, mtime).catch(() => {});
} else throw err;
} Prevention
- Inspect the reference file's timestamps (stat) before using -r.
- Avoid reference files on FAT/exFAT with out-of-range timestamps.
- Prefer explicit -d timestamps when the reference's provenance is unknown.
When it happens
Trigger: Running `touch -r <reference> <target>` where the reference file's stored mtime/atime is outside the representable range (e.g. extreme values on FAT/extreme epoch timestamps) or was corrupted.
Common situations: Reference files on FAT/exFAT filesystems with timestamps far outside normal ranges; archives containing malformed timestamps; clock-skew or year-1601/9999 edge values copied from other systems.
Related errors
- Unable to parse date: {0}
- failed to get attributes of {}: {}
- GetFinalPathNameByHandleW failed with code {0}
- {0}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/e2f10cdab2f3bbf1.
Report an issue: GitHub.