From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 9541 invoked from network); 12 Aug 2023 03:30:30 -0000 Received: from 9front.inri.net (168.235.81.73) by inbox.vuxu.org with ESMTPUTF8; 12 Aug 2023 03:30:30 -0000 Received: from pb-smtp20.pobox.com ([173.228.157.52]) by 9front; Fri Aug 11 23:26:08 -0400 2023 Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 1189B36A6D for <9front@9front.org>; Fri, 11 Aug 2023 23:26:03 -0400 (EDT) (envelope-from unobe@cpan.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=message-id :from:to:subject:date:mime-version:content-type :content-transfer-encoding; s=sasl; bh=aVB/zUkbemjNbzrvtIvW6xTDP vnkyRk8ZgGwZ26RpNo=; b=o9lNEIYptX1ebqFq4JdNZsD2JxZG7NgS2lqczw1r4 FZc5uKYYPy8V1jZnLcSvQL+cVS5erFgdX6vJcnmzE3eBTM4veSz5SVn/KTDk4qvB KDdE6GYTle3FNxUpbDX6HJhwjUUUueGDzzVAsn5RAD99slDEIvrrQmvcH0rM4u+N 58= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id F132436A6C for <9front@9front.org>; Fri, 11 Aug 2023 23:26:02 -0400 (EDT) (envelope-from unobe@cpan.org) Received: from strider.localdomain (unknown [97.131.109.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 4245836A69 for <9front@9front.org>; Fri, 11 Aug 2023 23:25:59 -0400 (EDT) (envelope-from unobe@cpan.org) Message-ID: From: Romano To: 9front@9front.org Date: Fri, 11 Aug 2023 20:25:56 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Pobox-Relay-ID: F4E3923E-38BF-11EE-A75C-C2DA088D43B2-09620299!pb-smtp20.pobox.com List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: RESTful content-addressed realtime-java manager Subject: [9front] PATCH walk(1) to (optionally) quote name and path Reply-To: 9front@9front.org Precedence: bulk I'm working with files on a backup drive that have spaces and quotation marks in their names, using walk(1). I can pipe to sed s/''''/''''''''''/g and do similarly for other characters requiring escaping for rc(1), but figured patching walk(1) would be better. I don't like how I just copied case 'p': the quoting "works", but isn't as clean as the output for ls(1). For example: Desktop/Movies/'A Bug''s Life.mp4' 'Desktop/Movies/TV/TV Library.tvlibrary'/'Library Preferences.tvdb' Desktop/Movies/'The American President.mp4' instead of: 'Desktop/Movies/A Bug''s Life.mp4' 'Desktop/Movies/TV/TV Library.tvlibrary/Library Preferences.tvdb' 'Desktop/Movies/The American President.mp4' But it's better than what happens now, where there's no quoting. From: Romano Date: Sat, 12 Aug 2023 03:18:22 +0000 Subject: [PATCH] walk: quote name and paths using N and P --- diff deb39a43ae5ed09c7971726cedeb06a9f65ccc6d 2da52094832662c533f60629813dbd5ac805e3ad --- a/sys/man/1/walk +++ b/sys/man/1/walk @@ -81,8 +81,14 @@ .B n final path element (name) .TP +.B N +final path element (name), rc (1) quoted when necessary +.TP .B p path +.TP +.B P +path, rc (1) quoted when necessary .TP .B q qid path.version.type (see --- a/sys/src/cmd/walk.c +++ b/sys/src/cmd/walk.c @@ -43,7 +43,7 @@ void dofile(char *path, Dir *f, int pathonly) { - char *p; + char *p, *quoted; if( (f == dotdir) @@ -60,6 +60,10 @@ case 'a': Bprint(bout, "%uld", f->atime); break; case 'm': Bprint(bout, "%uld", f->mtime); break; case 'n': Bwrite(bout, f->name, strlen(f->name)); break; + case 'N': + quoted = quotestrdup(f->name); + Bwrite(bout, quoted, strlen(quoted)); + break; case 'p': if(path != dotpath) Bwrite(bout, path, strlen(path)); @@ -69,6 +73,18 @@ Bwrite(bout, f->name, strlen(f->name)); } break; + case 'P': + if(path != dotpath) { + quoted = quotestrdup(path); + Bwrite(bout, quoted, strlen(quoted)); + } + if(! (f->qid.type & QTDIR) && !pathonly){ + if(path != dotpath) + Bputc(bout, '/'); + quoted = quotestrdup(f->name); + Bwrite(bout, quoted, strlen(quoted)); + } + break; case 'q': Bprint(bout, "%ullx.%uld.%.2uhhx", f->qid.path, f->qid.vers, f->qid.type); break; case 's': Bprint(bout, "%lld", f->length); break; case 'x': Bprint(bout, "%M", f->mode); break; @@ -243,7 +259,7 @@ if((stfmt = s_reset(stfmt)) == nil) sysfatal("s_reset: %r"); s_append(stfmt, EARGF(usage())); - i = strspn(s_to_c(stfmt), "UGMamnpqsxDT"); + i = strspn(s_to_c(stfmt), "UGMamnNpPqsxDT"); if(i != s_len(stfmt)) sysfatal("bad stfmt: %s", s_to_c(stfmt)); break;