Skip to content

libpkg/metalog: escape spaces in filenames - #2754

Draft
khorben wants to merge 1 commit into
freebsd:mainfrom
khorben:khorben/metalog-escape-spaces
Draft

khorben wants to merge 1 commit into
freebsd:mainfrom
khorben:khorben/metalog-escape-spaces

Conversation

@khorben

@khorben khorben commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Still marked as draft until I can test it properly, as I have a build issue on my system (FreeBSD 15.1-STABLE/amd64).

Sponsored by: The FreeBSD Foundation

Sponsored by:	The FreeBSD Foundation

Closes(freebsd#2755)
@khorben
khorben force-pushed the khorben/metalog-escape-spaces branch from 2a42568 to 4fca177 Compare September 18, 2026 16:42
@emaste

emaste commented Sep 18, 2026

Copy link
Copy Markdown
Member

I'd prefer to keep a single fprintf and handle the escaping separately, something like

p = escape_path(path);
fprintf("./%s", p...);
free(p);

Escaping only is not sufficient -- we have to escape \ also at least so that it's reversible, and also tab and some other things... from mtree's spec.c:

/*
 * vispath --
 *      strsvis(3) encodes path, which must not be longer than MAXPATHLEN
 *      characters long, and returns a pointer to a static buffer containing
 *      the result.
 */
char *
vispath(const char *path)
{
        static const char extra[] = { ' ', '\t', '\n', '\\', '#', '\0' };
        static const char extra_glob[] = { ' ', '\t', '\n', '\\', '#', '*',
            '?', '[', '\0' };
        static char pathbuf[4*MAXPATHLEN + 1];

        if (flavor == F_NETBSD6)
                strsvis(pathbuf, path, VIS_CSTYLE, extra);
        else
                strsvis(pathbuf, path, VIS_OCTAL, extra_glob);
        return pathbuf;
}

If all consumers are equally happy with VIS_CSTYLE I'd go with that, too, but that part doesn't much matter.

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

Successfully merging this pull request may close these issues.

2 participants