* [Thu, Oct 31, 2013 at 02:54:59PM +0100] Gian Piero Carrubba:
Oh... I was tweaking a bit the last patch posted by Bernhard in order to let it be POSIX compliant (but now I have to add: "for my interpretation of POSIX"), but didn't had the time to complete before going to work. Will probably finish it up anyway this evening or tomorrow, at this point at least for comparing how far we're currently are from "POSIX".
Here it is.First of all, sorry for having generated a lot of noise. I completely misunderstood the meaning of --no-preserve=links. Having get rid of that, the differences in the results of the tests are a lot less.
$ fgrep "DIFFERENCE in Test: " testit.log | sed 's/^.*: //' cp -l filelink ... cp -l --preserve=links filelink ... cp -L -l filelink ... cp -L -l --preserve=links filelink ... cp -L -l -R filelink ... cp -L -l -R --preserve=links filelink ... cp -H -l filelink ... cp -H -l --preserve=links filelink ... cp -H -l -R filelink ... cp -H -l -R --preserve=links filelink ... I think they are all legit (full log and differences summary attached). * Changes with regard to the last patch posted by Bernhard. === Minor changes- use 'dereference' instead of 'deref' in order to be consistent with 'x->dereference' and for passing the "grep test"[0] - use 'command_line_arg' instead of 'cli_arg' in order to be consistent with an already used variable and for passing the "grep test" - move up the declaration of bool dereference in order to use it for every invocation of create_hard_link()
- clean up the initialization of 'flags' in create_hard_link() [0] i.e.: http://jamie-wong.com/2013/07/12/grep-test/ === Major changes- dereference by default (i.e.: unless --no-dereference is used) the source files. I promise that I will not insist anymore :), but I really think this is important for consistency from a user point of view.
Ciao, Gian Piero.
Thu Oct 31 21:57:32 CET 2013 Gian Piero Carrubba <[email protected]> * bug-15173 http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15173 diff -rN -u old-trunk/NEWS new-trunk/NEWS --- old-trunk/NEWS 2013-10-31 22:24:51.690232614 +0100 +++ new-trunk/NEWS 2013-10-31 22:24:51.694232641 +0100 @@ -70,6 +70,10 @@ ** Changes in behavior + cp --link now dereferences a symbolic link as source files before creating + the hard link in the destination, unless --no-dereference is used too. + Previously, it would create a hard link of the symbolic link. + dd status=none now suppresses all non fatal diagnostic messages, not just the transfer counts. diff -rN -u old-trunk/src/copy.c new-trunk/src/copy.c --- old-trunk/src/copy.c 2013-10-31 22:24:51.690232614 +0100 +++ new-trunk/src/copy.c 2013-10-31 22:24:51.698232676 +0100 @@ -1558,18 +1558,23 @@ _("failed to restore the default file creation context")); } -/* Create a hard link DST_NAME to SRC_NAME, honoring the REPLACE and - VERBOSE settings. Return true upon success. Otherwise, diagnose - the failure and return false. - If SRC_NAME is a symbolic link it will not be followed. If the system - doesn't support hard links to symbolic links, then DST_NAME will - be created as a symbolic link to SRC_NAME. */ +/* Create a hard link DST_NAME to SRC_NAME, honoring the REPLACE, VERBOSE and + DEREFERENCE settings. Return true upon success. Otherwise, diagnose the + failure and return false. If SRC_NAME is a symbolic link it will not be + followed unless DEREFERENCE is true. + If the system doesn't support hard links to symbolic links, then DST_NAME + will be created as a symbolic link to SRC_NAME. */ static bool create_hard_link (char const *src_name, char const *dst_name, - bool replace, bool verbose) + bool replace, bool verbose, bool dereference) { - /* We want to guarantee that symlinks are not followed. */ - bool link_failed = (linkat (AT_FDCWD, src_name, AT_FDCWD, dst_name, 0) != 0); + /* We want to guarantee that symlinks are not followed, unless requested. */ + int flags = 0; + if (dereference) + flags = AT_SYMLINK_FOLLOW; + + bool link_failed = (linkat (AT_FDCWD, src_name, AT_FDCWD, dst_name, flags) + != 0); /* If the link failed because of an existing destination, remove that file and then call link again. */ @@ -1582,7 +1587,8 @@ } if (verbose) printf (_("removed %s\n"), quote (dst_name)); - link_failed = (linkat (AT_FDCWD, src_name, AT_FDCWD, dst_name, 0) != 0); + link_failed = (linkat (AT_FDCWD, src_name, AT_FDCWD, dst_name, flags) + != 0); } if (link_failed) @@ -1595,6 +1601,17 @@ return true; } +/* Return true if the current file should be (tried to be) dereferenced: + either for DEREF_ALWAYS or for DEREF_COMMAND_LINE_ARGUMENTS in the case + where the current file is a COMMAND_LINE_ARG; otherwise return false. */ +static inline bool _GL_ATTRIBUTE_PURE +should_dereference (const struct cp_options *x, bool command_line_arg) +{ + return x->dereference == DEREF_ALWAYS + || (x->dereference == DEREF_COMMAND_LINE_ARGUMENTS + && command_line_arg); +} + /* Copy the file SRC_NAME to the file DST_NAME. The files may be of any type. NEW_DST should be true if the file DST_NAME cannot exist because its parent directory was just created; NEW_DST should @@ -1670,6 +1687,8 @@ record_file (x->src_info, src_name, &src_sb); } + bool dereference = should_dereference (x, command_line_arg); + if (!new_dst) { /* Regular files can be created by writing through symbolic @@ -1748,7 +1767,7 @@ /* Note we currently replace DST_NAME unconditionally, even if it was a newer separate file. */ if (! create_hard_link (earlier_file, dst_name, true, - x->verbose)) + x->verbose, dereference)) { goto un_backup; } @@ -2078,7 +2097,8 @@ } else { - if (! create_hard_link (earlier_file, dst_name, true, x->verbose)) + if (! create_hard_link (earlier_file, dst_name, true, x->verbose, + dereference)) goto un_backup; return true; @@ -2389,7 +2409,7 @@ && !(LINK_FOLLOWS_SYMLINKS && S_ISLNK (src_mode) && x->dereference == DEREF_NEVER)) { - if (! create_hard_link (src_name, dst_name, false, false)) + if (! create_hard_link (src_name, dst_name, false, false, dereference)) goto un_backup; } else if (S_ISREG (src_mode) diff -rN -u old-trunk/tests/cp/same-file.sh new-trunk/tests/cp/same-file.sh --- old-trunk/tests/cp/same-file.sh 2013-10-31 22:24:51.690232614 +0100 +++ new-trunk/tests/cp/same-file.sh 2013-10-31 22:24:51.698232676 +0100 @@ -189,9 +189,9 @@ 0 -bf (foo sl1 -> foo sl2 sl2.~1~ -> foo) 0 -bdf (foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo) 1 -l [cp: cannot create hard link 'sl2' to 'sl1'] (foo sl1 -> foo sl2 -> foo) -0 -fl (foo sl1 -> foo sl2 -> foo) -0 -bl (foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo) -0 -bfl (foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo) +0 -fl (foo sl1 -> foo sl2) +0 -bl (foo sl1 -> foo sl2 sl2.~1~ -> foo) +0 -bfl (foo sl1 -> foo sl2 sl2.~1~ -> foo) 1 [cp: 'foo' and 'hardlink' are the same file] (foo hardlink) 1 -d [cp: 'foo' and 'hardlink' are the same file] (foo hardlink)
testit-differences-summary.log.gz
Description: Binary data
���rRtestit.log �]]�۶}�_��������H_�STH����ז#���n��@ƽ����e;�ő���q�}��C�><<�Ra?��X�b�R��������i:O�TL��^�r��2�(f��M�f�ދ�w7���r!z*k5O�|�i��L��2>xk�|����c��w�����4{=�/�{]e��4�^P����DH%zr��0�)^�<
���$���פ��_������J��
^�������^���0�c}�K^zI/����c3l��!���?y�W�����]����l{_��l�{��q���;n1<j�8m��M���GM�C�C���M%Z�M�CU�;d�&���W��כ�V�d5_|أ���m^��sv��ȧC������O�;��?K9}�O�{{w{{����~Ի��Σ��:j��H�`(�
o1,�7��yܨ4.��)"���75�����X������#*
�xH)�x3��E:Φ�Q�ΏcY�����J��/��"JaqT���r��Ơ'�J��M�X�B���NJ�y�����a���闟~�}��[1_�2�jcNὬ�{�
��w����;j�
��:��"A .�z@,4��H��@�x=�αP����#=�۽�v���m��_
�Um��K�y.oD]W��./��H��l��
0�^�wc����*"JazX��!�l�� ���@�C�md���l(��M�X`Nh`��u}����6�Y.mX.yWJ\ͥ����#L�{dIy�bc�Pm7A��?���W6�go���ຯ�t�=*���YN�j�F(@���
{��[),j�;�:
yD�9.B�/O"�#:G�hd0&0�`�ji��Y�O俴���U5$����"H�E���sţR �j�3)��L������#����d�x/F��8_��daߨ���k�2[S�7��M���t`��l� ���
;�^o�#��P����lyD��@}�<�\�l�̾6�o���AS��}#����q������73�����9�
|#����}#h�7�7��7"�L�/�f��oTcd�5E��)�Q��υ�r:�od|N�����Pl����<������H���d�L������&�����}PG���)C~�}j��8
����Ԥ��29W���+�c����j�\��{B�]3�:ðl}.r*:`Qّ@�������kê65��e��Qr&Q$"UT�UFO1��vk��H3��
(y��$or%[M�$gWN0M�_Iz�%kfY~�RD�?Z�*��L���&\�S-�T������6�jtQ�5���!��j5�R�m9�4}���ٖ:��5�/y��Q`�P��n[1�Z
M�jg^��>S�⩘�.Y$^H$Y��)�H���T5�,d��i��!�%ZD��sd2�Ǧ"��/d|��釟�����K���d��E�U_�$;�L����1�EF㻕L��c�q�Y
ߵd��>kIg@06b�X�c��6�����s�1�EFt���L0�A�8�����2%)'��4Y4p�P'yC����j���ќ`�>'�
Y�Z6ƃ]������0����>�l:�B%
��u�T�]���ۦ
���M��R�L���'�G�D{�*L�g��C+�����d�)Z��OOް�YYt
H}O�N��}��;dtd6:y���|8��A�q4$5X_��X
2T3MN���P�U��j�"6���yU�F�yU�F��*�W!T�
RA4�'��w7�kb�D���r����0��I�m�����=�J�DKj�.% Ec�{(]�LH��
���J����y�t0�*�\v�JM��Ug�I_���5!B���f�';��c�b�b�:�l)l��t2ιw'soE��w{|��+�Cw{���l�Ӂݭ��Ц�����S,�X�W��c��}��R�'"��r!�eO$�|I�x��N���f^���;[/���UM��\��إA�Cױ=��^e�67,F�y�ƭd����Gd�nO����9�9��sb�J^hr��?���
h��Ъ �8�4� �[����g]��k�����G�A�6��>�T�/�}���:]�⬬�wSy[�]��|�O���ҦA��-L�o��߲���8)/H�,4\5\5��\�X5mW�Wͺ�8t�$��PW_5����Fe��|ӂ2ߴ>�7��_���T����SïZΉm�R$R�S&��l��6�dkM�y���Ju�ʕe�e�e�$3
�M5��rn���VQwS���W���8t7�U����^YpI�I�09|��R=���kFϦ�\0�R�R{�R���/>��x�T],WB�ƫ��c��5��-��2�(fs�eBя]�����v:<�ѹ��ϑ��b��1NbK0��X i
m��]���*B����!4��l����W��>l2*m�9��)�(��*\o9��;�
)�+��Y �L�@>�
Kw�x[E��,Dz�"�Ӗ�D+�M�A�H���,S������|���$(�2�3(�rH����@���s���A/����m��˶�=�DB��fuY�e!�=L\�ߐ�i���c���amʆ��;����@oC���
�D�F6�e����sgi �tx?�>2AՂ���q�g�cHGf�F�fd��Ȓ��J螎�E�Y��T+"�v#��<��+3=vރ(y /���ً�=ٶ�vоgtբD����Nq��S�{&���$PG����<D�\�:�s')�:\��>�
�,\��qWvy*q���w�Y�̒6G�%�+T�Ox��%2^����1��:�N����:�t^�M��S:�/�c
���s8��)n#�'�t貞ٗ��H98���/'�e�˾�}8�/N�2P����|��/�
�͗�|@}8�/]�e����y|pʗ�_N��@�}0�e�l�\�/#~��x������:�
