Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip carriage returns when computing config hash at check time. #1171

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

gouttegd
Copy link
Contributor

At seeding time, the hash of the configuration file is computed using Python code. The default behaviour of Python, when reading text files, is to automatically translate CRLF line endings (such as those found in text files originating from a Windows machine) into LF line endings (normal line endings from the civilised world). This means that the config hash is computed on a buffer that only contain LF line endings, not CRLF line endings.

But at checking time, the hash of the configuration file is computed using sha256sum, which takes the contents of the file as it is, without any kind of mangling of the line endings.

On GNU/Linux and macOS, this all works fine, because the configuration file only contains LF endings on those systems.

But on Windows, the default behaviour of Git, when checking out a repository, is to write text files with CRLF line endings, therefore causing the configuration file to have a sha256sum-computed hash that is different from the Python-computed hash, and thus causing spurious warnings from the ODK that the configuration file has changed since the Makefile was last re-generated.

The fix is to forcefully strip all carriage returns (CR) from the configuration file prior to computing its hash.

closes #1170

At seeding time, the hash of the configuration file is computed using
Python code. The default behaviour of Python, when reading text files,
is to automatically translate CRLF line endings (such as those found in
text files originating from a Windows machine) into LF line endings
(normal line endings from the civilised world). This means that the
config hash is computed on a buffer that only contain LF line endings,
not CRLF line endings.

But at checking time, the hash of the configuration file is computed
using sha256sum, which takes the contents of the file as it is, without
any kind of mangling of the line endings.

On GNU/Linux and macOS, this all works fine, because the configuration
file only contains LF endings on those systems.

But on Windows, the default behaviour of Git, when checking out a
repository, is to write text files with CRLF line endings, therefore
causing the configuration file to have a sha256sum-computed hash that is
different from the Python-computed hash, and thus causing spurious
warnings from the ODK that the configuration file has changed since the
Makefile was last re-generated.

The fix is to forcefully strip all carriage returns (CR) from the
configuration file prior to computing its hash.

closes #1170
@gouttegd gouttegd self-assigned this Jan 17, 2025
@gouttegd gouttegd requested a review from matentzn January 17, 2025 14:23
Copy link
Contributor

@matentzn matentzn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; assuming you tried this 😂

@gouttegd gouttegd merged commit 0e88714 into master Jan 17, 2025
1 check passed
@gouttegd gouttegd deleted the fix-hash-check-on-windows branch January 17, 2025 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants