From: A Tammy Subject: Re: Question about cp -P (without -R) and POSIX compliance To: Hiltjo Posthuma , tech@openbsd.org Date: Sun, 6 Oct 2024 17:11:37 -0400 On 10/6/24 5:50 AM, Hiltjo Posthuma wrote: > On Tue, Sep 17, 2024 at 12:28:45PM +0200, Hiltjo Posthuma wrote: >> On Thu, Sep 05, 2024 at 09:44:45PM +0200, Hiltjo Posthuma wrote: >>> Hi, >>> >>> I have a question about cp on OpenBSD and the -P flag. >>> >>> It seems cp -P (without the -R option) to copy a symlink behaves differently >>> for single files on OpenBSD than POSIX specifies and compared to NetBSD, >>> FreeBSD, Linux (GNU, busybox, toybox, etc). >>> >>> Test-case to reproduce it: >>> >>> touch file >>> ln -s file link >>> cp -P link link2 >>> ls -l link link2 For anyone curious about what is happening, on debian I get $ ls -l link link2 lrwxrwxrwx 1 epsilon epsilon 4 Oct  6 20:59 link -> file lrwxrwxrwx 1 epsilon epsilon 4 Oct  6 20:59 link2 -> file On openbsd I get # ls -l link link2 lrwxr-xr-x  1 root  wheel  4 Oct  6 23:03 link@ -> file -rw-r--r--  1 root  wheel  0 Oct  6 23:03 link2 Personally, I think the documentation in the openbsd man page is correct and sufficient. Regarding the posix docs, the way I read it, the -P flag is only going to modify the behaviour of the -R flag, if specified, and doesn't make any sense to have -P by itself. At the end of the day, we can bikeshed as much as we want but this difference in behaviour is here to stay and is unlikely to be changed. >>> >>> NetBSD and FreeBSD changed the check a while ago (Feb 23, 2022), for example: >>> >>> https://github.com/freebsd/freebsd-src/commit/97e13037915c22162f199461f56951793d669f57 >>> >>> Snippet: >>> >>> } else if (!Pflag) { >>> fts_options &= ~FTS_PHYSICAL; >>> fts_options |= FTS_LOGICAL | FTS_COMFOLLOW; >>> >>> The OpenBSD man page specifies: >>> >>> "if the -R option is also specified, no symbolic links are followed". >>> >>> and: >>> >>> "Symbolic links are always followed unless the -R flag is set, in which case >>> symbolic links are not followed, by default. The -H or -L flags (in conjunction >>> with the -R flag) cause symbolic links to be followed as described above. The >>> -H, -L, and -P options are ignored unless the -R option is specified. In >>> addition, these options override each other and the command's actions are >>> determined by the last one specified." >>> >>> >>> But POSIX specifies: >>> >>> "If the -R option was not specified, cp shall take actions based on the type >>> and contents of the file referenced by the symbolic link, and not by the >>> symbolic link itself, unless the -P option was specified." >>> >>> Reference: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cp.html >>> >>> Should this be changed? >>> >>> Thank you, >>> >> Hi, >> >> Any thoughts about the above? Feedback would be appreciated. >> >> If the proposed change looks good I can write a full patch and documentation >> update. >> >> Thank you, >> > One more try: any thought about the above? >