Make touch
logic in file_metadata.sh
more portable
#1648
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Following up on #1496, it turns out that, in the fixture script that
from_path_no_follow
runs, which usestouch
to createfuture
andpast
files with extreme timestamps:The date-time strings, intended to take advantage of nanosecond precision where available by specifying fractions of a second, are unlikely to be helping, because:
from_path_no_follow
test does not require the exactly most extreme values to be useful.stat
implementations that show sub-second precision suggests that, for the extreme values representable in ext4--which the values used there were chosen to cover--there is no benefit over usingtouch
with whole seconds. (I was also not able to verify the correctness and relevance of the specific fractional values, but it may be that further research would confirm them.)TZ
was not set in the script or in the code that set it, sotouch
seems often to have been converting from some other time zone, usually local time, to UTC.The fallback date-time string used for
future
isis not fully portable either, becausetouch
on some systems will reject values that are too large to parse as 32-bittime_t
. I have observed this on three platforms:touch
and 64-bit GNUtouch
tested)As noted, this does not affect all 32-bit GNU/Linux systems. A 32-bit x86 Debian 12 system I tested was unaffected, allowing timestamps far in the future of 2038 to be set with
touch
. (This most likely relates to Debian 12 being much newer than Ubuntu 18.04 LTS, and not to the Debian vs. Ubuntu distinction. Recent versions of Ubuntu do not support installation on machines with 32-bit x86 processors, so there is no comparably recent version of Ubuntu to test for close comparison to Debian 12.)On the affected 32-bit GNU/Linux system (Ubuntu 18.04 LTS), as well as on Windows (in Git Bash), the test suite finds GNU
touch
and, in both cases, the errors are:On illumos, some users place
/usr/gnu/bin
early in the path, but I did not make that change, so the illumostouch
command was used. The errors were:On all three platforms, manual experimentation confirmed that the second error message was not actually due to the format in which the date-time string was given--though the error messages make it seem that way--but instead was due to it being out of range. The wording is presumably due to this being discovered during parsing.
That these values would have a low ceiling on a 64-bit illumos system is unintuitive. The error message may be affected by how common illumos tools, including the
touch
command, are 32-bit builds even on a 64-bit system. But the GNU tools, including GNUtouch
, which are also installed with the system, are 64-bit builds. The following brief experiment demonstrates thattime_t
is a different-sized type in 32-bit and 64-bit builds running on the same system, but that the 64-bit GNUtouch
still refuses to set large values:I can investigate further, including on this 64-bit OmniOS illumos system, if needed. However, I think the above is sufficient to establish that the existing fallback logic is not portable, that it can be improved while still preserving the tangible benefits of the previous approach, and that this can be done without increasing overall complexity if aspects of the previous approach that were ineffective or unnecessary are removed at the same time.
This PR:
TZ=UTC
.future
, adds a fallback for 32-bittime_t
so we get both portability and, where feasible, the ability to test a very high (probably exactly maximal) ext4 timestamp.The commit message, as well as the rewritten code comment in the fixture script, have some further information.
In addition to checking that
from_path_no_follow
test does fail, and in the expected way reported above, on all four affected test systems, I have also verified that the change here makes that test pass on those systems. (There are four systems rather than three because I tested on both LTSC and non-LTSC Windows 10 systems. But the difference between those systems is probably not significant in ways relevant to this behavior, so it may be better to think of them as only three test systems.)A few more notes about how I tested this:
I have not manually tested this on macOS, because this particular fixture script always runs even when
GIX_TEST_IGNORE_ARCHIVES
is not set, and it does not rungit
so it will not vary based on whethergit
is Apple Git, so CI should be sufficient to test it.I have rerun the tests, including these changes, on three unaffected systems to ensure they remain unaffected:
The test passed on
bothall three systems, both when run individually and when run as part of the entire test suite.The generated archive, while
.gitignore
d, could interfere with testing. I made sure to rungix clean
commands sufficient to delete it between all successive tests on the same system.Output of some test runs is saved in this gist, in case for some reason it is of interest. Various other tests failed in some runs, but the changes here produced no new failures on any system. The only failures the change here remedies is
from_path_no_follow
.Edit: Minor fixes for clarity in case this is referred to later, with
strikethroughto show what was changed (though I think this was already read with the intended meanings when reviewed for merging).