Skip to content

cp: making cp compatible with "same-file" gnu test case  #6158

@matrixhead

Description

@matrixhead

Hi,
currently, our cp is failing gnu test case same-file, so I'm using this issue to log my findings and to discuss how to approach the problems. From my initial impression, same-file is failing for a number of reasons, and I'm listing them out here.

-b is not respecting VERSION_CONTROL environment variable.

It says in here that whenever --backup is given with an argument it takes precedence over VERSION_CONTROL and it also says that -b is equivalent to --backup=existing that means when -b is given cp should ignore the VERSION_CONTROL and set the backup method to "existing" and this is how uu-cp works, but gnu's implementation seems to respect the VERSION_CONTROL environment variable when -b is given.

gnu's cp

~ >> touch foo
~ >> touch bar
~ >> export VERSION_CONTROL=numbered
~ >> cp -b foo bar
~ >> ls
bar  bar.~1~  foo

our cp

~ >> touch foo
~ >> touch bar
~ >> export VERSION_CONTROL=numbered
~ >> cp -b foo bar
~ >> ls
bar  bar~  foo

difference in behaviors and error messages

this test case fails also because of the way how uutil-cp handles error code and messages, the following tables show the difference between two implementations, behaviors that should be changed are marked with these

when a file(foo) is copied to the symlink(symlink -> foo) that points to the same file

Options Exit status Exit status(GNU) std error std error(GNU) Files in the folder after copying Files in the folder after copying(GNU) remarks remarks(gnu)
none 1 1 "cp: 'foo' and 'symlink' are the same file" "cp: 'foo' and 'symlink' are the same file" "foo symlink -> foo" "foo symlink -> foo" none none
-d 1 1 "cp: 'foo' and 'symlink' are the same file" "cp: 'foo' and 'symlink' are the same file" "foo symlink -> foo" "foo symlink -> foo" none none
-f 1 1 "cp: 'foo' and 'symlink' are the same file" "cp: 'foo' and 'symlink' are the same file" "foo symlink -> foo" "foo symlink -> foo" none none
-df 1 1 "cp: 'foo' and 'symlink' are the same file" "cp: 'foo' and 'symlink' are the same file" "foo symlink -> foo" "foo symlink -> foo" none none
--rem 0 0 none none "foo symlink" "foo symlink" none none
-b 0 0 none none "foo symlink symlink~ -> foo" "foo symlink symlink.~1~ -> foo" none none
-bd "1" 0 "cp: No such file or directory (os error 2)" none "foo symlink~ -> foo" "foo symlink symlink.~1~ -> foo" symlink-loop none
-bf "1" 0 "cp: No such file or directory (os error 2)" none "foo symlink~ -> foo" "foo symlink symlink.~1~ -> foo" symlink-loop none
-bdf "1" 0 "cp: No such file or directory (os error 2)" none "foo symlink~ -> foo" "foo symlink symlink.~1~ -> foo" symlink-loop none
-l 1 1 "cp: 'foo' and 'symlink' are the same file" "cp: cannot create hard link 'symlink' to 'foo'" "foo symlink -> foo" "foo symlink -> foo" none none
-dl 1 1 "cp: 'foo' and 'symlink' are the same file" "cp: cannot create hard link 'symlink' to 'foo'" "foo symlink -> foo" "foo symlink -> foo" none none
-fl "1" 0 "cp: 'foo' and 'symlink' are the same file" none "foo symlink -> foo" "foo symlink" none none
-dfl "1" 0 "cp: 'foo' and 'symlink' are the same file" none "foo symlink -> foo" "foo symlink" none none
-bl 0 0 none none "foo symlink symlink~ -> foo" "foo symlink symlink.~1~ -> foo" none none
-bdl "1" 0 "cp: No such file or directory (os error 2)" none "foo symlink~ -> foo" "foo symlink symlink.~1~ -> foo" symlink-loop none
-bfl "1" 0 "cp: No such file or directory (os error 2)" none "foo symlink~ -> foo" "foo symlink symlink.~1~ -> foo" symlink-loop none
-bdfl "1" 0 "cp: No such file or directory (os error 2)" none "foo symlink~ -> foo" "foo symlink symlink.~1~ -> foo" symlink-loop none
-s 1 1 "cp: 'foo' and 'symlink' are the same file" "cp: cannot create symlink 'symlink' to 'foo'" "foo symlink -> foo" "foo symlink -> foo" none none
-sf "1" 0 "cp: 'foo' and 'symlink' are the same file" none "foo symlink -> foo" "foo symlink -> foo" none none

when a symlink(symlink -> foo) that points to a file(foo) is copied to the same file

Options Exit status Exit status(GNU) std error std error(GNU) Files in the folder after copying Files in the folder after copying(GNU) remarks remarks(gnu)
none 1 1 "cp: 'symlink' and 'foo' are the same file" "cp: 'symlink' and 'foo' are the same file" "foo symlink -> foo" "foo symlink -> foo" none none
-d "0" 1 "none" "cp: 'symlink' and 'foo' are the same file" "foo -> foo symlink -> foo" "foo symlink -> foo" symlink-loop symlink-loop none
-f 1 1 "cp: 'symlink' and 'foo' are the same file" "cp: 'symlink' and 'foo' are the same file" "foo symlink -> foo" "foo symlink -> foo" none none
-df "0" 1 "none" "cp: 'symlink' and 'foo' are the same file" "foo -> foo symlink -> foo" "foo symlink -> foo" symlink-loop symlink-loop none
--rem 1 1 "cp: 'symlink' and 'foo' are the same file" "cp: 'symlink' and 'foo' are the same file" "foo symlink -> foo" "foo symlink -> foo" none none
-b 1 1 "cp: 'symlink' and 'foo' are the same file" "cp: 'symlink' and 'foo' are the same file" "foo symlink -> foo" "foo symlink -> foo" none none
-bd 0 0 none none "foo -> foo foo~ symlink -> foo" "foo -> foo foo.~1~ symlink -> foo" symlink-loop symlink-loop symlink-loop symlink-loop
-bf "0" 1 "none" "cp: 'symlink' and 'foo' are the same file" "foo foo~ symlink -> foo" "foo symlink -> foo" cp FAILED cp FAILED none
-bdf 0 0 none none "foo -> foo foo~ symlink -> foo" "foo -> foo foo.~1~ symlink -> foo" symlink-loop symlink-loop symlink-loop symlink-loop
-l "1" 0 "cp: 'symlink' and 'foo' are the same file" none "foo symlink -> foo" "foo symlink -> foo" none none
-dl 0 0 none none "foo -> foo symlink -> foo" "foo symlink -> foo" symlink-loop symlink-loop none
-fl "1" 0 "cp: 'symlink' and 'foo' are the same file" none "foo symlink -> foo" "foo symlink -> foo" none none
-bl "1" 0 "cp: 'symlink' and 'foo' are the same file" none "foo symlink -> foo" "foo symlink -> foo" none none
-bfl "1" 0 "cp: No such file or directory (os error 2)" none "foo~ symlink -> foo" "foo symlink -> foo" symlink-loop symlink-loop none
-s 1 1 "cp: 'symlink' and 'foo' are the same file" "cp: 'symlink' and 'foo' are the same file" "foo symlink -> foo" "foo symlink -> foo" none none
-sf 1 1 "cp: 'symlink' and 'foo' are the same file" "cp: 'symlink' and 'foo' are the same file" "foo symlink -> foo" "foo symlink -> foo" none none

when a file(foo) is copied to the same file(foo)

Options Exit status Exit status(GNU) std error std error(GNU) Files in the folder after copying Files in the folder after copying(GNU) remarks remarks(gnu)
none 1 1 "cp: 'foo' and 'foo' are the same file" "cp: 'foo' and 'foo' are the same file" "foo" "foo" none none
-d 1 1 "cp: 'foo' and 'foo' are the same file" "cp: 'foo' and 'foo' are the same file" "foo" "foo" none none
-f 1 1 "cp: 'foo' and 'foo' are the same file" "cp: 'foo' and 'foo' are the same file" "foo" "foo" none none
-df 1 1 "cp: 'foo' and 'foo' are the same file" "cp: 'foo' and 'foo' are the same file" "foo" "foo" none none
--rem 1 1 "cp: 'foo' -> 'foo'" "cp: 'foo' and 'foo' are the same file" "empty" "foo" symlink-loop symlink-loop none
-b 1 1 "cp: 'foo' and 'foo' are the same file" "cp: 'foo' and 'foo' are the same file" "foo" "foo" none none
-bd 1 1 "cp: 'foo' and 'foo' are the same file" "cp: 'foo' and 'foo' are the same file" "foo" "foo" none none
-bf 0 0 none none "foo foo~" "foo foo.~1~" cp FAILED cp FAILED none
-bdf 0 0 none none "foo foo~" "foo foo.~1~" cp FAILED cp FAILED none
-l 0 0 none none "foo" "foo" none none
-dl 0 0 none none "foo" "foo" none none
-fl 0 0 none none "foo" "foo" none none
-dfl 0 0 none none "foo" "foo" none none
-bl 0 0 none none "foo" "foo" none none
-bdl 0 0 none none "foo" "foo" none none
-bfl 0 0 none none "foo" "foo foo.~1~" none none
-bdfl 0 0 none none "foo" "foo foo.~1~" none none
-s 1 1 "cp: 'foo' and 'foo' are the same file" "cp: 'foo' and 'foo' are the same file" "foo" "foo" none none
-sf 1 1 "cp: 'foo' and 'foo' are the same file" "cp: 'foo' and 'foo' are the same file" "foo" "foo" none none

when a symlink(sl1 -> foo) that points to a file(foo) is copied to another symlink(sl2 -> foo) that points to same file

Options Exit status Exit status(GNU) std error std error(GNU) Files in the folder after copying Files in the folder after copying(GNU) remarks remarks(gnu)
none 1 1 "cp: 'sl1' and 'sl2' are the same file" "cp: 'sl1' and 'sl2' are the same file" "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2 -> foo" none none
-d 0 0 none none "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2 -> foo" none none
-f 1 1 "cp: 'sl1' and 'sl2' are the same file" "cp: 'sl1' and 'sl2' are the same file" "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2 -> foo" none none
-df 0 0 none none "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2 -> foo" none none
--rem 0 0 none none "foo sl1 -> foo sl2" "foo sl1 -> foo sl2" none none
-b 0 0 none none "foo sl1 -> foo sl2 sl2~ -> foo" "foo sl1 -> foo sl2 sl2.~1~ -> foo" none none
-bd "1" 0 "cp: No such file or directory (os error 2)" none "foo sl1 -> foo sl2~ -> foo" "foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo" symlink-loop none
-bf "1" 0 "cp: No such file or directory (os error 2)" none "foo sl1 -> foo sl2~ -> foo" "foo sl1 -> foo sl2 sl2.~1~ -> foo" symlink-loop none
-bdf "1" 0 "cp: No such file or directory (os error 2)" none "foo sl1 -> foo sl2~ -> foo" "foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo" symlink-loop none
-l 1 1 "cp: 'sl1' and 'sl2' are the same file" "cp: cannot create hard link 'sl2' to 'sl1'" "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2 -> foo" none none
-fl "1" 0 "cp: 'sl1' and 'sl2' are the same file" none "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2" none none
-bl 0 0 none none "foo sl1 -> foo sl2 sl2~ -> foo" "foo sl1 -> foo sl2 sl2.~1~ -> foo" none none
-bfl "1" 0 "cp: No such file or directory (os error 2)" none "foo sl1 -> foo sl2~ -> foo" "foo sl1 -> foo sl2 sl2.~1~ -> foo" symlink-loop none
-s 1 1 "cp: 'sl1' and 'sl2' are the same file" "cp: cannot create symlink 'sl2' to 'sl1'" "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2 -> foo" none none
-sf "1" 0 "cp: 'sl1' and 'sl2' are the same file" none "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2 -> sl1" none none

when a file(foo) is copied to hardlink(hardlink) of the same file

Options Exit status Exit status(GNU) std error std error(GNU) Files in the folder after copying Files in the folder after copying(GNU) remarks remarks(gnu)
none 1 1 "cp: 'sl1' and 'sl2' are the same file" "cp: 'sl1' and 'sl2' are the same file" "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2 -> foo" none none
-d 0 0 none none "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2 -> foo" none none
-f 1 1 "cp: 'sl1' and 'sl2' are the same file" "cp: 'sl1' and 'sl2' are the same file" "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2 -> foo" none none
-df 0 0 none none "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2 -> foo" none none
--rem 0 0 none none "foo sl1 -> foo sl2" "foo sl1 -> foo sl2" none none
-b 0 0 none none "foo sl1 -> foo sl2 sl2~ -> foo" "foo sl1 -> foo sl2 sl2.~1~ -> foo" none none
-bd "1" 0 "cp: No such file or directory (os error 2)" none "foo sl1 -> foo sl2~ -> foo" "foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo" symlink-loop none
-bf "1" 0 "cp: No such file or directory (os error 2)" none "foo sl1 -> foo sl2~ -> foo" "foo sl1 -> foo sl2 sl2.~1~ -> foo" symlink-loop none
-bdf "1" 0 "cp: No such file or directory (os error 2)" none "foo sl1 -> foo sl2~ -> foo" "foo sl1 -> foo sl2 -> foo sl2.~1~ -> foo" symlink-loop none
-l 1 1 "cp: 'sl1' and 'sl2' are the same file" "cp: cannot create hard link 'sl2' to 'sl1'" "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2 -> foo" none none
-fl "1" 0 "cp: 'sl1' and 'sl2' are the same file" none "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2" none none
-bl 0 0 none none "foo sl1 -> foo sl2 sl2~ -> foo" "foo sl1 -> foo sl2 sl2.~1~ -> foo" none none
-bfl "1" 0 "cp: No such file or directory (os error 2)" none "foo sl1 -> foo sl2~ -> foo" "foo sl1 -> foo sl2 sl2.~1~ -> foo" symlink-loop none
-s 1 1 "cp: 'sl1' and 'sl2' are the same file" "cp: cannot create symlink 'sl2' to 'sl1'" "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2 -> foo" none none
-sf "1" 0 "cp: 'sl1' and 'sl2' are the same file" none "foo sl1 -> foo sl2 -> foo" "foo sl1 -> foo sl2 -> sl1" none none

when a symlink(hlsl) that points to a file(foo) is copied to the hardlink(sl2) of the same symlink

Options Exit status Exit status(GNU) std error std error(GNU) Files in the folder after copying Files in the folder after copying(GNU) remarks remarks(gnu)
none "0" 1 "none" "cp: 'hlsl' and 'sl2' are the same file" "foo hlsl -> foo sl2 -> foo" "foo hlsl -> foo sl2 -> foo" none none
-d 0 0 none none "foo hlsl -> foo sl2 -> foo" "foo hlsl -> foo sl2 -> foo" none none
-f 1 1 "cp: 'hlsl' and 'sl2' are the same file" "cp: 'hlsl' and 'sl2' are the same file" "foo hlsl -> foo sl2 -> foo" "foo hlsl -> foo sl2 -> foo" none none
-df "1" 0 "cp: 'hlsl' and 'sl2' are the same file" none "foo hlsl -> foo sl2 -> foo" "foo hlsl -> foo sl2 -> foo" none none
--rem 0 0 none none "foo hlsl -> foo sl2" "foo hlsl -> foo sl2" none none
-b 0 0 none none "foo hlsl -> foo sl2 sl2~ -> foo" "foo hlsl -> foo sl2 sl2.~1~ -> foo" none none
-bd "1" 0 "cp: No such file or directory (os error 2)" none "foo hlsl -> foo sl2~ -> foo" "foo hlsl -> foo sl2 -> foo sl2.~1~ -> foo" symlink-loop none
-bf "1" 0 "cp: No such file or directory (os error 2)" none "foo hlsl -> foo sl2~ -> foo" "foo hlsl -> foo sl2 sl2.~1~ -> foo" symlink-loop none
-bdf "1" 0 "cp: No such file or directory (os error 2)" none "foo hlsl -> foo sl2~ -> foo" "foo hlsl -> foo sl2 -> foo sl2.~1~ -> foo" symlink-loop none
-l "0" 1 "none" "cp: cannot create hard link 'sl2' to 'hlsl'" "foo hlsl -> foo sl2 -> foo" "foo hlsl -> foo sl2 -> foo" none none
-dl 0 0 none none "foo hlsl -> foo sl2 -> foo" "foo hlsl -> foo sl2 -> foo" none none
-fl "1" 0 "cp: 'hlsl' and 'sl2' are the same file" none "foo hlsl -> foo sl2 -> foo" "foo hlsl -> foo sl2" none none
-dfl "1" 0 "cp: 'hlsl' and 'sl2' are the same file" none "foo hlsl -> foo sl2 -> foo" "foo hlsl -> foo sl2 -> foo" none none
-bl 0 0 none none "foo hlsl -> foo sl2 sl2~ -> foo" "foo hlsl -> foo sl2 sl2.~1~ -> foo" none none
-bdl "1" 0 "cp: No such file or directory (os error 2)" none "foo hlsl -> foo sl2~ -> foo" "foo hlsl -> foo sl2 -> foo" symlink-loop none
-bfl "1" 0 "cp: No such file or directory (os error 2)" none "foo hlsl -> foo sl2~ -> foo" "foo hlsl -> foo sl2 sl2.~1~ -> foo" symlink-loop none
-bdfl "1" 0 "cp: No such file or directory (os error 2)" none "foo hlsl -> foo sl2~ -> foo" "foo hlsl -> foo sl2 -> foo" symlink-loop none
-s "0" 1 "none" "cp: cannot create symlink 'sl2' to 'hlsl'" "foo hlsl -> foo sl2 -> foo" "foo hlsl -> foo sl2 -> foo" none none
-sf "1" 0 "cp: 'hlsl' and 'sl2' are the same file" none "foo hlsl -> foo sl2 -> foo" "foo hlsl -> foo sl2 -> hlsl" none none

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions