Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@polarathene
Copy link
Member

@polarathene polarathene commented Jan 24, 2024

Description

This PR is to address a parsing concern with postfix-master.cf (no final newline ignores last line of file), which happens to be the only config we loop through with read to process individual lines from but wasn't using the common helper method.

New helper methods added replace very old corrections (that we had only for postfix-accounts.cf):

This is also a follow-up PR to #2820 (which provides more details on those replaced / removed sed calls)

Commit history is fairly clean with additional context in commit messages if needed.


sed '$a\' (sed docs) in particular didn't seem to offer any extra value than just a printf '\n'.

I've included several links in comment for the helper as context. That could be removed too, but that sed example was presumably taken from there (top answer), while another better clarifies why tail -c 1 + wc -l is chosen for detection.


I could drop the -w read-only conditional, I just recall setup.bash in tests having a concern about read-only mount support. Not that our inputs should really cause any concerns there with this change. Let me know, happy to drop that guard (might affect those eventual plans for error handling magic I've seen discussed 😝 ).

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change that does improve existing functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • If necessary I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have added information about changes made in this PR to CHANGELOG.md

@polarathene
Copy link
Member Author

This has surfaced some bugs in the test suite, I'll need to investigate those tomorrow.

@georglauterbach georglauterbach added this to the v14.0.0 milestone Jan 24, 2024
@georglauterbach
Copy link
Member

Is this WIP? If so, please mark as draft - otherwise I'll start to review.

These lines will be not be processed by `read`, emit a warning to raise awareness.
This functionality was handled in `accounts.sh` via a similar sed command (that the linked references also offer).

`printf` is better for this, no shellcheck comment required either.

We additionally don't attempt to modify files that are read-only.
Likewise, this runtime fix was only covering two config files. It now applies to all callers of this method.
This feature should have been using the helper to avoid user error from their config updates accidentally introducing subtle breakage implicitly (due to CRLF or missing final newline).
@polarathene polarathene force-pushed the fix/warn-on-missing-final-newline branch from 313a776 to 936d43c Compare January 25, 2024 09:08
This temporary directory is created and removed implicitly. Even after a test failure.
This was introduced in 2018, there should be no one needing to rely on this anymore?
@polarathene polarathene force-pushed the fix/warn-on-missing-final-newline branch from 936d43c to 60017bc Compare January 25, 2024 09:25
@polarathene
Copy link
Member Author

Is this WIP?

It's ready for review now πŸ‘

Copy link
Member

@georglauterbach georglauterbach left a comment

Choose a reason for hiding this comment

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

Looks good overall, but I have left a few comments to address still.

@polarathene polarathene merged commit 47f8d50 into docker-mailserver:master Jan 25, 2024
@polarathene polarathene mentioned this pull request Jan 27, 2024
8 tasks
Copy link
Member

@casperklein casperklein left a comment

Choose a reason for hiding this comment

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

Only some minor things I saw while reviewing.

Comment on lines 19 to +21
function _get_valid_lines_from_file() {
_convert_crlf_to_lf_if_necessary "${1}"
_append_final_newline_if_missing "${1}"
Copy link
Member

Choose a reason for hiding this comment

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

From a logical POV: A "get" function, should not alter the provided source file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, if you have a suggestion to change it to a pipe instead that only transforms the text being parsed into lines instead of needing to write it, I'm all good for that πŸ‘

Copy link
Member

Choose a reason for hiding this comment

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

Minimal effort: Rename the function to _fix_file_and_get_content


if [[ -w ${1} ]]; then
_log 'debug' 'Converting CRLF to LF'
sed -i 's|\r||g' "${1}"
Copy link
Member

Choose a reason for hiding this comment

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

A file change is expected, let's ensure that with:

sedfile --strict -i

Copy link
Member Author

Choose a reason for hiding this comment

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

I originally did use sedfile here πŸ€“ but the tests run outside of the container where sedfile is not a binary on the host so it failed, not sure how to approach that?

Copy link
Member

Choose a reason for hiding this comment

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

Okay, that actually makes sense!

Copy link
Member

@casperklein casperklein Jan 28, 2024

Choose a reason for hiding this comment

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

I don't understand this. So when writing scripts that are meant to run inside our container, we must take into account, that they also run on any host?

Like any other dependency, it must be present on the host. If not, sedfile should either be copied to /usr/bin or included in the PATH env: PATH=$PATH:target/bin/sedfile

For example, parallel is also a dependency that is not available on a default debian installation and have to be explicit installed in order to run tests. But that's no reason for not using parallel.


What do I miss here? Why are container scripts run the host? Why not run them in the container, where all dependencies are satisfied?

Copy link
Member Author

Choose a reason for hiding this comment

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

What do I miss here? Why are container scripts run the host? Why not run them in the container, where all dependencies are satisfied?

Not missing anything, I think it was just how it was handled before and we just haven't considered moving the tests to be run within the container?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants