coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

Implement cp

Open GrayJack opened this issue 4 years ago • 10 comments

This is a tracking issue for the cp util.

Required options and flags in the POSIX standard:

  • [ ] f (long: force)
  • [ ] H (long: ¹)
  • [ ] i (long: interactive)
  • [ ] L (long: dereference)
  • [ ] P (long: no-dereference)
  • [ ] p (long: preserve)
  • [ ] R (long: recursive-compat)

Required extension options and flags:

  • [ ] r (long: recursive)

Notes: ¹ : Long name not defined on other implementation of this utility. Implementer must choose a long name. ² : Short name (one letter) not defined on other implementation of this utility. Implementer must choose. a short name

References

POSIX standard text

Unresolved questions:

None yet

History

GrayJack avatar Sep 27 '19 20:09 GrayJack

I will start with this.

kegesch avatar Oct 02 '19 12:10 kegesch

Nice, have fun :smile:

GrayJack avatar Oct 02 '19 16:10 GrayJack

@GrayJack i ran into a problem here. Maybe you know how to solve it. cp -p -R symlink should copy a symlink and preserve its metadata. But apparently there is no way in Rust to copy a symlink. You can only create one. But also you can not set a file's metadata, at least i could not find any way to do so. Do you have an idea?

kegesch avatar Oct 05 '19 16:10 kegesch

I have to look into that, never done it

GrayJack avatar Oct 08 '19 13:10 GrayJack

How do you preserve the metadata on the other types of file?

GrayJack avatar Oct 08 '19 14:10 GrayJack

fs::copy() copies a file with metadata. And to not preserve it i use io::copy(). For dirs i have the same problem as with symlinks. There is a function in fs to set permissions but i found nothing about modified, creation date etc.

kegesch avatar Oct 08 '19 17:10 kegesch

Did you found out any more info on how to do this?

GrayJack avatar Oct 10 '19 18:10 GrayJack

Aha!!! Found it, to preserve attributes of a link you have to hardlink the files

So, if you want to copy a symlink, you have to hardlink the link to another path, and hardlink will preserve the attributes

fs::hard_link() function does that

GrayJack avatar Oct 10 '19 19:10 GrayJack

Yes, but a hardlink is not a symlink if i understood correctly.

kegesch avatar Oct 12 '19 14:10 kegesch

Yes, but all code that I saw (FreeBSD, NetBSD and uutils) does that when preserving a copy a symlink preserving metadata

GrayJack avatar Oct 12 '19 14:10 GrayJack