<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 27, 2022 at 11:32 PM Rob Landley <<a href="mailto:rob@landley.net">rob@landley.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I just added sed --tarxform and taught tar --xform to use it, so a single<br>
persistent instance of sed can speak a simple protocol allowing<br>
call-and-response sed invocation across a pipe. (This didn't work before for<br>
several reasons: a line that produced no output could block tar trying to read<br>
the result, a sed invocation adding an extra \n or \0 to the output could get<br>
tar out of sync, sed wouldn't produce output until it read the NEXT line of data<br>
so it could do $ matching at EOF...) Anyway, wrapped in a protocol, works now.<br>
<br>
I'm not pushing the commit publicly yet because I'm hopefully about to CHANGE<br>
said protocol slightly, to add a type indicator because in<br>
<a href="https://www.gnu.org/software/tar/manual/tar.html#transform" rel="noreferrer" target="_blank">https://www.gnu.org/software/tar/manual/tar.html#transform</a> we have this little<br>
horror show:<br>
<br>
In addition, several transformation scope flags are supported, that control to<br>
what files transformations apply. These are:<br>
<br>
‘r’ Apply transformation to regular archive members.<br>
‘R’ Do not apply transformation to regular archive members.<br>
‘s’ Apply transformation to symbolic link targets.<br>
‘S’ Do not apply transformation to symbolic link targets.<br>
‘h’ Apply transformation to hard link targets.<br>
‘H’ Do not apply transformation to hard link targets.<br>
<br>
Default is ‘rsh’, which means to apply transformations to both archive members<br>
and targets of symbolic and hard links.<br>
<br>
Default scope flags can also be changed using ‘flags=’ statement in the<br>
transform expression. The flags set this way remain in force until next<br>
‘flags=’ statement or end of expression, whichever occurs first. For example:<br>
<br>
--transform 'flags=S;s|^|/usr/local/|'<br>
<br>
No, "flags=" is not how sed command syntax normally works, thanks for asking.<br>
<br>
So now I'm starting at this going:<br>
<br>
1) Is rsh only the default when there are no scope flags? As in if I tell it<br>
scope s should that switch off r and h?<br>
<br>
2) Does flags= interact with the block logic? If I do<br>
<br>
--transform '{flags=S;s/potato/blah/;};s/a/b/'<br>
<br>
should the second transform apply to symlink type?<br>
<br>
3) If how about jumps? If I b to a :label past a flags= statement does that<br>
prevent the flag change from taking effect? (Is this a parse time attribute or a<br>
runtime attribute?)<br></blockquote><div><br></div><div>remember that GNU tar explicitly doesn't support _sed_ --- it supports something like looks kind of like the sed 's' command.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
The sad part is I strongly suspect I'm putting more thought into this than the<br>
tar developers did, but I kind of need to know the answers to do it RIGHT.<br></blockquote><div><br></div><div><div>"any similarity to actual sed, living or dead, is entirely coincidental".</div></div><div><br></div><div>tbh, i think all the choices were bad here:</div><div><br></div><div>1. invent a new format. now you have two problems.</div><div><br></div><div>2. reuse sed entirely. now you have the problems you've been dealing with. (plus a lot of curious "what does <thing> even mean?" questions, because sed is too general for this use case. luckily i doubt we'll ever have to answer those questions, because i doubt anything esoteric is likely to be used. despite hyrum's law, i don't really know anyone except you who writes sed more complex than a single s command, and issues with trying to run your sed programs on macOS suggest that nothing beyond a single s command is portable to different sed implementations anyway!)</div><div><br></div><div>3. rewrite that one command from sed. now you have duplication, and potential skew between "actual s command" and "fake s command".</div><div><br></div><div>option 3 is not obviously a bad choice given the issues with the alternatives, but it's a bad fit for anyone trying to do option 2 instead.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Sigh,<br>
<br>
Rob<br>
_______________________________________________<br>
Toybox mailing list<br>
<a href="mailto:Toybox@lists.landley.net" target="_blank">Toybox@lists.landley.net</a><br>
<a href="http://lists.landley.net/listinfo.cgi/toybox-landley.net" rel="noreferrer" target="_blank">http://lists.landley.net/listinfo.cgi/toybox-landley.net</a><br>
</blockquote></div></div>