9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] this history(1) is scratched
@ 2022-11-12  8:15 qwx
  2022-11-12 11:03 ` Eckard Brauer
  2022-11-12 19:13 ` ori
  0 siblings, 2 replies; 14+ messages in thread
From: qwx @ 2022-11-12  8:15 UTC (permalink / raw)
  To: 9front

Hello,

I'm having an issue with our new history(1) implementation: printing
paths in the dump always fails for me.  Example from the manpage:

	; history /adm/users
	Feb 28 09:52:37 CET 2022 /adm/users 159 [adm]
	walk: path:  /n/dump/2022/1111/adm/users: ' ' directory entry not found
	Nov 12 08:39:54 CET 2022walk: path:  /n/dump/2022/1111/adm/users: ' ' directory entry not found
	walk: path:  /n/dump/2022/0228/adm/users: ' ' directory entry not found
	Nov 12 08:39:54 CET 2022walk: path:  /n/dump/2022/0228/adm/users: ' ' directory entry not found

Same for any other file -- a space character is prepended to the
paths, so walk(1) fails.  The issue seems to be in the awk command at
/rc/bin/history:39:

	[...]
 	awk '"/n/'$dump/$since'" <= $2 {next}
 	     $1 != qid {
 		qid=$1
		gsub($1, "")
 		print}' |
	[...]

This does a substitution on $0, which retains the space between $1 and
$2, even though $1 has been replaced by $2:

	; echo 'a b' | awk '{gsub($1, ""); print}'
	 b
	; echo 'a b' | awk '{gsub($1, ""); print $1}'
	b

If I understand the intent correctly, then the simplest fix is to add
the space character to the regex:

	; echo 'a b' | awk '{gsub($1" ", ""); print}'
	b

It's also not necessary to call `gsub' instead of just `sub'.

The thing is, this change is already a few months old, and I cannot
imagine that the script has not worked for anyone in all of this time,
including when it was first pushed, or that absolutely everyone has
been using the old C version without noticing it.  This behavior in
awk is surprising to me, but is not 9front-specific.  What the hell is
going on?  Can anyone else reproduce this?  Any idea what I could be
doing wrong?

Including a fix below, if any is actually needed.

Thanks,
qwx


diff 7a5a9b592af208aac719a6cfc0dacf44a5eebcef uncommitted
--- a//rc/bin/history
+++ b//rc/bin/history
@@ -36,7 +36,7 @@
 	awk '"/n/'$dump/$since'" <= $2 {next}
 	     $1 != qid {
 		qid=$1
-		gsub($1, "")
+		sub($1" ", "")
 		print}' |
 	while(new=`$nl{read}){
 		prfile $new

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-11-15 22:01 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-12  8:15 [9front] this history(1) is scratched qwx
2022-11-12 11:03 ` Eckard Brauer
2022-11-12 12:16   ` Eckard Brauer
2022-11-12 18:07     ` Eckard Brauer
2022-11-12 19:13 ` ori
2022-11-12 20:32   ` Eckard Brauer
2022-11-12 20:44     ` Eckard Brauer
2022-11-12 20:53       ` Eckard Brauer
2022-11-12 21:26     ` ori
2022-11-12 22:43       ` umbraticus
2022-11-13  3:35   ` Anthony Martin
2022-11-13 23:20     ` qwx
2022-11-15 11:49       ` qwx
2022-11-15 21:59         ` qwx

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).