Page MenuHomeFreeBSD

Fix behavior for '-F' option of ln(1)
ClosedPublic

Authored by shivansh on Jun 12 2017, 10:17 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Apr 19, 11:53 AM
Unknown Object (File)
Dec 30 2023, 1:24 AM
Unknown Object (File)
Dec 20 2023, 2:57 AM
Unknown Object (File)
Dec 10 2023, 9:13 PM
Unknown Object (File)
Nov 27 2023, 8:00 AM
Unknown Object (File)
Nov 23 2023, 4:18 AM
Unknown Object (File)
Nov 22 2023, 2:44 PM
Unknown Object (File)
Nov 22 2023, 2:33 PM
Subscribers
None

Details

Summary

When '-F' option is used, the target directory needs to be unlinked.
Currently, the modified target ("target/source") is being unlinked, and
since it doesn't yet exist, the original target isn't removed.
This is fixed by skipping the block where target is modified to
"target/source" when '-F' option is set.
Hence, a symbolic link (with the same name as of the original target) to
the source_file is produced.

Update the test for ln(1) to reflect fix for option '-F'

PR: 219943

Test Plan
  • Run make install from bin/ln/tests.
  • Run kyua test from /usr/tests/bin/ln. All 12 test cases should succeed.

Diff Detail

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

Event Timeline

Would it not suffice to simply skip the block at line 250 when Fflag is set?

Oh, right! We can simply modify the if clause to skip it -

if (!Fflag && (isdir ||
	    (lstat(target, &sb) == 0 && S_ISDIR(sb.st_mode)) ||
	    (!hflag && stat(target, &sb) == 0 && S_ISDIR(sb.st_mode)))) {

Will wait for others to comment before updating.

Fix as per instructed by @asomers

Updated summary -
When '-F' option is used, the target directory needs to be unlinked.
Currently, the modified target ("target/source") is being unlinked, and
since it doesn't yet exist, the original target isn't removed.
This is fixed by skipping the block where target is modified to
"target/source" when '-F' option is set.
Hence, a symbolic link (with the same name as of the original target) to
the source_file is produced.

LGTM. I'll commit tomorrow AM if no other reviewers have comments.

This revision is now accepted and ready to land.Jun 12 2017, 10:57 PM
ngie added inline comments.
bin/ln/ln.c
247–248 ↗(On Diff #29520)

This comment should be updated for the change.

shivansh edited edge metadata.

Update comment

This revision now requires review to proceed.Jun 13 2017, 12:15 AM
bin/ln/ln.c
249 ↗(On Diff #29526)

This sounds wordy. Let me think about this a bit.

bin/ln/ln.c
248 ↗(On Diff #29526)
  • source's name. -> source's name, unless Fflag is set.

Update comment

I am suspecting that some other commits are also going to be included in this update. I don't think doing an interactive rebase caused the problem, but I have tried updating my remote, hard resetting it to the original state at the time the diff was sent, but (I think) in vain.
If the changes aren't included, then it's fine. If they are, I'll figure something out.

Update comment

I am suspecting that some other commits are also going to be included in this update. I don't think doing an interactive rebase caused the problem, but I have tried updating my remote, hard resetting it to the original state at the time the diff was sent, but (I think) in vain.
If the changes aren't included, then it's fine. If they are, I'll figure something out.

No worries.. I can parse out the changes.

One that specify revisions/git hashes with arc diff --update.

This revision is now accepted and ready to land.Jun 20 2017, 8:42 PM
This revision was automatically updated to reflect the committed changes.