dennisdoomen / dennisdoomen/pathy
[API Proposal]: TouchFile and SetLastWriteTimeUtc
- Dominant language
- C#
- Stars
- 27
- Forks
- 5
- Avg merge
- 21h 29m
- Merged PRs (30d)
- 10
Description
### Background and motivation
`LastWriteTimeUtc` was added as a read-only property, but there is no way to set it and no way to create an empty file or update its timestamp. Both are staples of build scripts: creating a sentinel or stamp file, marking a target as up to date, and forcing a rebuild by touching an input. Tests that verify timestamp-based logic also need to set the timestamp deterministically rather than sleeping.
### API Proposal
```C#
namespace Pathy
{
public static class ChainablePathExtensions
{
public static ChainablePath TouchFile(this ChainablePath path);
public static void SetLastWriteTimeUtc(this ChainablePath path, DateTime value);
}
}
```
`TouchFile` creates the file (and its parent directories) when it does not exist, and updates the last write time when it does. It returns the path so it can be chained.
### API Usage
```C#
var stamp = (artifacts / ".build-complete").TouchFile();
// Make a test deterministic instead of sleeping
(temp / "input.txt").SetLastWriteTimeUtc(DateTime.UtcNow.AddHours(-1));
if (output.LastWriteTimeUtc < input.LastWriteTimeUtc)
{
Rebuild();
}
```
### Alternative Designs
* Make `LastWriteTimeUtc` a settable property. Not possible in the current shape without turning the readonly struct into something mutable, and a property setter that performs file system I/O is misleading anyway.
* Add `CreateFile()` separately from touching. Most callers want the combined behaviour that `touch` provides.
### Risks
Whether `TouchFile` should create missing parent directories needs a decision; doing it silently is convenient but hides typos. Setting a timestamp on a directory should either work consistently or be documented as unsupported.
Contributor guide
Research direction
Start by locating ChainablePathExtensions and the existing LastWriteTimeUtc implementation. Review how the current API handles file and directory operations, then resolve the parent-directory and directory-timestamp questions before defining tests for creating files, updating timestamps, chaining, and deterministic UTC values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100