coreutils
coreutils copied to clipboard
Implement cp
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
Unresolved questions:
None yet
History
I will start with this.
Nice, have fun :smile:
@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?
I have to look into that, never done it
How do you preserve the metadata on the other types of file?
fs::copy()
copies a file with metadata. And to not preserve it i use io::copy()
. For dir
s 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.
Did you found out any more info on how to do this?
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
Yes, but a hardlink is not a symlink if i understood correctly.
Yes, but all code that I saw (FreeBSD, NetBSD and uutils) does that when preserving a copy a symlink preserving metadata