Thursday, 2024-10-31

shermanmwelp, the final answer seems to be that if the "source-repository-$something" file isn't terminated with a newline, the final line of the file is skipped, or, if only one line is present, the whole thing is skipped13:00
clarkboh thats good to know but also your editor should always add a newline :)15:02
* clarkb has used vim for years and it does so automatically and its easy to forget not every editor does so15:03
clarkbin bash `help read` does show that by default the delimiter is newline and it reads until the delimiter15:20
clarkbso that is documented behavior of the underlying implementation15:20
clarkblooks like you can use readline to read the line and that treats EOF as newline on a non empty input15:22
clarkbshermanm: if you're up to it maybe you want to test updating https://opendev.org/openstack/diskimage-builder/src/commit/02a3c8755960f0e1851da5ec0f8d4b66aee06494/diskimage_builder/elements/source-repositories/extra-data.d/98-source-repositories#L45 to `while read -e line; do` and see if that works for your original case15:22
clarkbshermanm: if that does work I'd +2 a patch that does that (-e is the use readline flag)15:23
shermanmah! I made a bug report and included a different fix actually, adding `while read line || [ -n "$line" ]; do` : https://bugs.launchpad.net/diskimage-builder/+bug/208619215:26
shermanmit looks like `-e` still returns nonzero if there's no trailing newline15:26
shermanmbut I'm happy to submit a patch as well15:26
clarkbshermanm: if you get an EOF it should return non zero so that the loop exits15:27
JayFyeah that fix looks strange to me15:27
clarkbI think that is correct behavior we just want it to treat that as a newline for purposes of returning a line15:27
clarkboh but we need do while I guess15:28
shermanmthe issue, from what I can find, is that if the last line isn't terminated with a newline, `read` both returns a value, and exits nonzero15:28
clarkbgot it and readline would do the same thing (I wonder why they list that as an alternative)15:29
shermanmthis led me to a whole rabbit hole of stackoverflow posts, mostly of the theme "'while read line; do' considered harmful", so I'm not sure there's a clean looking fix15:30
shermanmotoh, just loudly exiting if the source file isn't newline terminated would also be fine for me15:30
clarkbya and maybe add a note in the readme for the element that the input must end on a newline15:30

Generated by irclog2html.py 2.17.3 by Marius Gedminas - find it at https://mg.pov.lt/irclog2html/!