Commit 44215b6
committed
Add support for
`FAKETIME_KEEP_BEFORE_NSEC_SINCE_EPOCH` behaves similar to
`FAKETIME_START_AFTER_SECONDS`, with two main differences:
* the timestamp is absolute, instead of being relative to process startup
* the timestamp is specified in nanoseconds
The reason we want this feature is the following use case.
We run a large test suite under faketime. That test suite has access to
filesystem artifacts that were created prior to test start up.
Among those artifacts are some caches which are considered up to date
iff the timestamps of the files match what's recorded in a data structure.
This means that to access those caches to be considered valid we need their
timestamps to not be rewritten.
The reason we can't use `FAKETIME_START_AFTER_SECONDS` directly is that the
test suite consists of multiple processes, for those processes to correctly
interact with each other they need a consistent timestamp mapping that is shared
between them. In fact the simplest bash script already behaves incorrectly
because the commands use different process start times.
```
touch old
FAKETIME=+100d FAKETIME_START_AFTER_SECONDS=0 bash -c 'touch new; stat old new'
```
The expected behavior is that the timestamp of `old` is not rewritten,
while the timestamp of `new` is rewritten.
That is in fact achievable now:
```
touch old
now_ns=$(date +%s.%N | sed -r 's_\.__')
FAKETIME=+100d FAKETIME_KEEP_BEFORE_NSEC_SINCE_EPOCH="$now_ns" bash -c 'touch new; stat old new'
```FAKETIME_KEEP_BEFORE_NSEC_SINCE_EPOCH
1 parent 942b30e commit 44215b6
1 file changed
+15
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
343 | 346 | | |
344 | 347 | | |
345 | 348 | | |
| |||
2897 | 2900 | | |
2898 | 2901 | | |
2899 | 2902 | | |
| 2903 | + | |
| 2904 | + | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
2900 | 2908 | | |
2901 | 2909 | | |
2902 | 2910 | | |
| |||
3220 | 3228 | | |
3221 | 3229 | | |
3222 | 3230 | | |
3223 | | - | |
3224 | 3231 | | |
3225 | 3232 | | |
| 3233 | + | |
| 3234 | + | |
| 3235 | + | |
| 3236 | + | |
| 3237 | + | |
| 3238 | + | |
| 3239 | + | |
3226 | 3240 | | |
3227 | 3241 | | |
3228 | 3242 | | |
| |||
0 commit comments