Bug 254842 - cp does not support preserving created time (btime)
Summary: cp does not support preserving created time (btime)
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.0-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-07 02:44 UTC by akww244
Modified: 2021-04-08 16:54 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description akww244 2021-04-07 02:44:30 UTC
1) Create a .txt file. Then open the .txt file and edit the .txt file and save. Now have 3 different timestamps for atime, mtime and btime.


stat -f "Accessed (atime): %Fa%nModified (mtime): %Fm%nCreated  (btime): %FB" '/home/liveuser/Desktop/123.txt' 
Accessed (atime): 1617769412.044026000
Modified (mtime): 1617769415.349392000
Created  (btime): 1617768991.589695000


2) Copy the file from the source to the destination.

cp -p '/home/liveuser/Desktop/123.txt' '/'


3) View the file info of the destination.

stat -f "Accessed (atime): %Fa%nModified (mtime): %Fm%nCreated  (btime): %FB" '/123.txt'                       
Accessed (atime): 1617769412.044026000
Modified (mtime): 1617769415.349392000
Created  (btime): 1617769415.349392000


Result:
atime and mtime were preserved. But btime was not preserved by the source and was automatically set to mtime.


Expectation:
cp -p supports preserving btime from the source to the destination. The support works for files and directories.
Comment 1 Andriy Gapon freebsd_committer 2021-04-08 08:02:56 UTC
When a tool's behavior does not match expectations there are two possibilities: the tool has a bug or your expectations are incorrect.  It always pays off to check your expectations first.  E.g., you can read manuals or start a discussion on FreeBSD forums.
In this case:
     -p    Cause cp to preserve the following attributes of each source file
           in the copy: modification time, access time, file flags, file mode,
           ACL, user ID, and group ID, as allowed by permissions.

I do not see anything about birth time, do you?
Comment 2 akww244 2021-04-08 15:16:09 UTC
> I do not see anything about birth time, do you?
I have read the manual before and know that cp -p has no support for birth time. The title of this report shows that there is a request to support it. I am sorry that I did not make it more obvious in the description.


It doesn't have to be cp -p, but it generally lacks support in cp command for birth time. The command for preserve created time (btime) could be like this: cp -b or -c
Comment 3 Andriy Gapon freebsd_committer 2021-04-08 16:40:11 UTC
If you are proposing a change for an existing feature or suggesting an idea for a new feature, wouldn't it better to discuss it on public forums first?  For example, the mailing lists.
I do not see how opening a bug report helps moving forward.
Comment 4 Ceri Davies 2021-04-08 16:54:10 UTC
Why is leaving it open a problem? This is far from the only “feature request” in bugzilla.