mtimehash

package module
v0.0.0-...-84ef6af Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 11 Imported by: 0

README

mtimehash

Go Reference Test

CLI to modify files mtime (modification data time) based on the hash of the file content. This makes it deterministic regardless of when the file was created or modified.

Installation

go install github.com/slsyy/mtimehash/cmd/mtimehash@latest

Rationale

go test uses mtimes to determine, if files opened during tests has changed and thus: tests need to be re-run. Unfortunately in a typical CI workflow modifications times are random as git does not preserve them. This makes caching for those tests ineffective, which slows down the test execution

More information here: https://github.com/golang/go/issues/58571

The trick is to set mtime based on the file content hash. This way the mtime is deterministic regardless of when the repository was modified/clone, so a hit ratio should be much higher.

Usage

Processing Files

Pass a list of files to modify via stdin:

find . -type f | mtimehash files

In my project I use:

find . -type f -size -10000k ! -path ./.git/\*\* | mtimehash files

to skip large files and .git directory

Processing Directories

Pass a list of directories to modify via stdin:

find . -type d | mtimehash dirs

The directory modification time is set based on a hash of the directory contents (file and subdirectory names), making it deterministic based on what files are present in the directory.

Note: It's recommended to process files first, then directories:

find . -type f | mtimehash files
find . -type d | mtimehash dirs

This ensures directories get updated mtimes based on the final state of their contents.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Process

func Process(input iter.Seq[string], maxUnixTime int64) error

Process input files and update their modification time based on the hash of their content. The modification time is set to the hash modulo maxUnixTime.

func ProcessDirectories

func ProcessDirectories(input iter.Seq[string], maxUnixTime int64) error

ProcessDirectories processes directories and updates their modification time based on their contents. The mtime is set based on a hash of the directory entries (sorted names), making it deterministic based on what files/subdirectories are present.

Types

This section is empty.

Directories

Path Synopsis
cmd
mtimehash command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL