Page MenuHomeFreeBSD

sed: fix -i option behavior with 'q' command
ClosedPublic

Authored by yuripv on Aug 19 2018, 3:52 AM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 14 2024, 2:59 PM
Unknown Object (File)
Jan 10 2024, 1:46 AM
Unknown Object (File)
Sep 11 2023, 9:17 AM
Unknown Object (File)
Sep 3 2023, 5:43 AM
Unknown Object (File)
Aug 22 2023, 7:39 PM
Unknown Object (File)
Aug 15 2023, 7:18 AM
Unknown Object (File)
Jul 11 2023, 5:41 PM
Unknown Object (File)
Jul 1 2023, 7:15 PM

Details

Summary

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=230507

Don't just exit when encountering the 'q' command if we edit file inplace, and give mf_fgets() a chance to actually handle inplace case.

Test Plan

$ jot 5 > a
$ /usr/obj/home/yuri/ws/pr230507/amd64.amd64/usr.bin/sed/sed -i.bak '2q' a
$ cat a
1
2
$ cat a.bak
1
2
3
4
5

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This seems reasonable to me. Would you be willing to add a regression test?

This seems reasonable to me. Would you be willing to add a regression test?

Sure, will update this in a bit.

Add a simple test case (hopefully not TOO simple).

yuripv added a subscriber: kevans.
yuripv removed a subscriber: kevans.

This looks good to me, just had one question.

usr.bin/sed/tests/sed2_test.sh
67 ↗(On Diff #46935)

What's the purpose of this line?

This revision is now accepted and ready to land.Aug 27 2018, 4:28 PM
yuripv added inline comments.
usr.bin/sed/tests/sed2_test.sh
67 ↗(On Diff #46935)

Currently we leave the temporary files with a pattern like ".!12345!" behind, just checking that those aren't there (for any reason).

usr.bin/sed/tests/sed2_test.sh
67 ↗(On Diff #46935)

To avoid confusion I'd suggest having a similar check in the other tests. That said, I wish kyua would catch this sort of thing itself.

usr.bin/sed/tests/sed2_test.sh
67 ↗(On Diff #46935)

I guess it can, let me take a look.

usr.bin/sed/tests/sed2_test.sh
67 ↗(On Diff #46935)

It's not clear to me why this is pertinent, though. We generally don't support* running these tests standalone, and Kyua does its own construction/destruction of the sandbox when run properly.

  • Technically we do, but we don't go to any lengths within tests to clean up
usr.bin/sed/tests/sed2_test.sh
67 ↗(On Diff #46935)

It's not about kyua, it's about sed leaving temporary files behind and that's bad. I'm just checking that it doesn't anymore as part of regression test case.

usr.bin/sed/tests/sed2_test.sh
67 ↗(On Diff #46935)

Oh dear, I see what you mean.

usr.bin/sed/tests/sed2_test.sh
67 ↗(On Diff #46935)

OK, Mark and Kyle, what do you want me to do here:

  • leave it as is
  • add it to other inplace tests
  • make kyua notice leftover files instead of using error-prone ls way
usr.bin/sed/tests/sed2_test.sh
67 ↗(On Diff #46935)

How hard is option 3? If you're talking about modifying kyua itself, I would just go with option 2.

usr.bin/sed/tests/sed2_test.sh
67 ↗(On Diff #46935)

I think Option 2 is the way to go- this is a useful test of sed behavior, which is what's creating the !* files to work on. One could potentially break the cleanup, which would be nice to detect.

I don't see an easy way to check for leftovers in the working directory using standard kyua commands, so simply add the check for '.!'* files to all inplace cases.

This revision now requires review to proceed.Aug 27 2018, 9:49 PM

I'll submit a change request to re@ to get this into 12.0.

This revision is now accepted and ready to land.Aug 28 2018, 3:02 PM
This revision was automatically updated to reflect the committed changes.