Open porg opened 1 year ago
You're right that --copyfrom
does not currently copy date/time (or mode/permissions for that matter). It only works on metadata items. I'll think about this. I can see from your user story that this definitely could be useful but I also don't want too much scope creep into osxmetadata which currently is focused on metadata.
There are other ways to achieve this, for example, touch -r
:
touch [-A [-][[hh]mm]SS] [-acfhm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...
-r Use the access and modifications times from the specified file instead of the current time of day.
If implemented, it might make sense to simple do what cp -p
does as this is "expected" behavior on the command line:
-p Cause cp to preserve the following attributes of each source file in the copy: modification time, access time, file flags,
file mode, user ID, and group ID, as allowed by permissions. Access Control Lists (ACLs) and Extended Attributes (EAs),
including resource forks, will also be preserved.
If the user ID and group ID cannot be preserved, no error message is displayed and the exit value is not altered.
If the source file has its set-user-ID bit on and the user ID cannot be preserved, the set-user-ID bit is not preserved in
the copy's permissions. If the source file has its set-group-ID bit on and the group ID cannot be preserved, the set-group-
ID bit is not preserved in the copy's permissions. If the source file has both its set-user-ID and set-group-ID bits on, and
either the user ID or group ID cannot be preserved, neither the set-user-ID nor set-group-ID bits are preserved in the copy's
permissions.
By the way, copyfrom
currently supports the following attributes though some of these are applicable to only certain file types (e.g. audio) and will have no effect if set on other files.
1) Thanks for confirming that timestamps are not copied and for the list of attributes that currently get copied. For readability sake thanks that you have put your long list into a spoiler tag.
2) Thanks for considering it. In combination with #73 it unfolds its batch processing / repairing / fixing potential.
3) Regarding the danger of feature creep: I know there are other tools to copy timestates specifically. But from a user standpoint "osxmeta" is the software which helps me backup/restore all my metadata conveniently (timestamps included in the JSON). In addition the --copyfrom allows me to mirror metadata in cases where no metadata-backup was made in time but disaster or bad software stroke but where the originals are still available to consider them for their metadata. So my proposal is not really exploding scope, but fitting right into that theme. Would love if you could give it a consideration!
touch
-r only can copy Date Modified
and Date Last Accessed
.Date Created
can currently only be manipulated with SetFile.
I think that adding the ability to restore time (and maybe permissions) does make sense but that functionality should be added also to the backup/restore. I'll take a look at implementing this but it'll be a while as I've got a number of other projects I'm working on at the moment.
I inspected the JSON and now realized that timestamps and permissions were indeed not backed up.
The plethora of Mac timestamps really tell you a lot and are so useful. Would be worthy to have them in --backup
, --restore
and also in --copyfrom
. I am glad you recognize the backup value of this too.
The permissions matter a bit less for general purposes, but matter in some use cases (restoring software directories, or shared directories).
For all use cases (--backup
, --restore
, --copyfrom
(possibly in combo with paste and xargs) ) you may want to be able to set that not ALL attributes are included but only a certain subset:
--backup
--restore
or --copyfrom
side you request certain attributes which were not included in the --backup. So in doubt --backup shall not have that attribute filtering capabilities.--restore
: Likely that you want only certain attributes to be restored (e.g. comments) or certain attributes NOT restored on purpose (e.g. the modification date shall be now, to have an indication of the restoration).--copyfrom
: Even more likely that you want to use that very specifically.So the companion parameter originally suggested as --copy
should have a more general name if it can be used together with --restore
, --copyfrom
and potentially also --backup
. I propose --include
and --exclude
. That way you must not work in an enumerate fashion. But can say "all but A,B" or "only X,Y".
User Story
my-video.mp4
is a fresh file and all its metadata (Finder tags, Spotlight comment, file timestamps) is blank/initialized.Existing capabilities
osxmeta --copyfrom my-video.m4v my-video.mp4
copies over Finder tags and Spotlight comments fine,Proposed new feature
-f, --copyfrom SOURCE_FILE
stays as is but gets a companion parameter for fine grained control for what filesystem attributes to copy over:-F, --copy attr1[,attr2,attr3,…]
accepts: all, all-dates, comments, tags, xattr, date-created, date-modified, date-last-openedall
is a shorthand to all attributesall-dates
a shorthand to all timestampscomments,tags
is what--copyfrom
currently does from what I could observe