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

Trailing empty line in <file> is stripped #426

Open
martin-29 opened this issue Jan 9, 2025 · 4 comments
Open

Trailing empty line in <file> is stripped #426

martin-29 opened this issue Jan 9, 2025 · 4 comments

Comments

@martin-29
Copy link
Contributor

The changes of the decoding in v15.3 (introduced by 3c5923e) seems to remove trailing empty lines within the <file> command.

Most of the time this wouldn't be an issue, but there are some cases where you want to overwrite for example a conf file, where a trailing empty line is required for proper parsing.

We discovered that with the following example:

<file dst="/etc/locale.gen">
    	en_US.UTF-8 UTF-8
    	de_DE.UTF-8 UTF-8

</file>

With v15.3 there is no newline character at the end which leads to the issue that local-gen is ignoring the last line and in this case the locales de_DE are not generated.

I think that behavior can create quite some confusion to the user.

Of course, there are workaround to this by using the encoding="raw" or using an archive file instead of creating the file within the finetuning.

But is this behavior expected and also desired for the case of the <file> command, when introducing strip_leading_whitespace_from_lines()?

@martin-29
Copy link
Contributor Author

Anything new on that topic?

@t-8ch
Copy link
Contributor

t-8ch commented Jan 20, 2025

This does need to be fixed.
I also want to improve the testing of the finetuning in general, to avoid similar issues in the future.

@t-8ch
Copy link
Contributor

t-8ch commented Jan 24, 2025

Could you test the diff below?
For me it seems to strike a nice balance between flexibility and predictability.

diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
index 63b1b61013e2..578dde3ead28 100644
--- a/elbepack/finetuning.py
+++ b/elbepack/finetuning.py
@@ -8,6 +8,7 @@ import logging
 import os
 import shlex
 import subprocess
+import textwrap
 from shutil import rmtree
 
 from gpg import core
@@ -241,7 +242,7 @@ class AddFileAction(FinetuningAction):
     @staticmethod
     def decode(text, encoding):
         if encoding == 'plain':
-            msg = strip_leading_whitespace_from_lines(text)
+            msg = textwrap.dedent(text.removeprefix('\n').removesuffix('\n'))
         elif encoding == 'raw':
             msg = '\n'.join(text.splitlines()[1:-1])
         elif encoding == 'base64':

@martin-29
Copy link
Contributor Author

Thanks for the diff, I tested it, and it looks good to me.

With that solution you always will have an empty line at the end, which is in my opinion the better default.
In case you want to omit that empty line, you would need to use the raw mode.

For me that would be fine, because that scenario is probably just an edge case and here raw mode should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants