Skip to content

Commit

Permalink
mkcomposefs: Process last content in dumpfile without newline
Browse files Browse the repository at this point in the history
I was doing some more testing and ended up crafting a dumpfile
without a trailing newline. It took me a surprising amount
of time to figure out that we just ignore data without a
trailing newline.

Hopefully, this doesn't break anyone.

Closes: containers#327
Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Sep 5, 2024
1 parent 47042e8 commit 202821a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion man/composefs-dump.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ files in it.

The file format is very simple, with one file per line, first with a
11 fixed fields, followed by a variable number of extended attributes
for the file.
for the file. It is recommended, but not required to include a trailing
newline for the last file.

Fields are separated by a single space, and lines by a single
newline. Extended attributes further use '=' to separate key from
Expand Down
3 changes: 3 additions & 0 deletions tests/assets/no-newline.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/ 4096 40555 222 0 0 10 0.0 - - - trusted.foo1=bar-1 user.foo2=bar-2
/a 0 100644 1 0 0 0 0.0 - - -
/b 0 100644 1 0 0 0 0.0 - - -
1 change: 1 addition & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ test_assets_small = [
'config-with-hard-link.dump.gz',
'special.dump',
'special_v1.dump',
'no-newline.dump',
]

test_assets_small_extra = [
Expand Down
9 changes: 9 additions & 0 deletions tools/mkcomposefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,15 @@ static struct lcfs_node_s *tree_from_dump(FILE *input, char **out_err)
}
}
}
// Handle no trailing newline
if (buf.size > 0) {
char *err = tree_from_dump_line(&info, buf.buf, buf.size);
if (err != NULL) {
*out_err = err;
buffer_free(&buf);
return NULL;
}
}

buffer_free(&buf);

Expand Down

0 comments on commit 202821a

Please sign in to comment.