1
0
Fork 0
mirror of https://github.com/pygos/pkg-utils.git synced 2024-11-22 04:49:46 +01:00

Add support for filenames with spaces in them

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2019-07-17 11:17:57 +02:00
parent 6d053ff213
commit ec1020ffc6

View file

@ -13,6 +13,22 @@ static void oom(const char *filename, size_t linenum)
input_file_complain(filename, linenum, "out of memory"); input_file_complain(filename, linenum, "out of memory");
} }
static void unescape_name(char *name)
{
char *dst = name, *src = name + 1;
while (*src != '"' && *src != '\0') {
if (src[0] == '\\' && (src[1] == '\\' || src[1] == '"')) {
*(dst++) = src[1];
src += 2;
} else {
*(dst++) = *(src++);
}
}
*dst = '\0';
}
static image_entry_t *filelist_mkentry(char *line, const char *filename, static image_entry_t *filelist_mkentry(char *line, const char *filename,
size_t linenum, mode_t filetype) size_t linenum, mode_t filetype)
{ {
@ -27,8 +43,23 @@ static image_entry_t *filelist_mkentry(char *line, const char *filename,
} }
/* name */ /* name */
for (i = 0; !isspace(line[i]) && line[i] != '\0'; ++i) if (*line == '"') {
; for (i = 1; line[i] != '"' && line[i] != '\0'; ++i) {
if (line[i] == '\\' &&
(line[i + 1] == '\\' || line[i + 1] == '"')) {
++i;
}
}
if (line[i++] != '"') {
input_file_complain(filename, linenum,
"missing \" after file name");
goto fail;
}
} else {
for (i = 0; !isspace(line[i]) && line[i] != '\0'; ++i)
;
}
if (!isspace(line[i])) { if (!isspace(line[i])) {
input_file_complain(filename, linenum, input_file_complain(filename, linenum,
@ -43,6 +74,10 @@ static image_entry_t *filelist_mkentry(char *line, const char *filename,
} }
memcpy(ent->name, line, i); memcpy(ent->name, line, i);
if (ent->name[0] == '"')
unescape_name(ent->name);
if (canonicalize_name(ent->name)) { if (canonicalize_name(ent->name)) {
input_file_complain(filename, linenum, "invalid file name"); input_file_complain(filename, linenum, "invalid file name");
goto fail; goto fail;