andyfeller / gh-publicize

GitHub CLI extension to publish content from source repository into multiple target repositories.
MIT License
14 stars 3 forks source link

Update library helper to preserve file mode in copying files #9

Open andyfeller opened 1 year ago

andyfeller commented 1 year ago

Overview

Thanks to feedback from @slmingol, it appears that copyFile helper function does not preserve the existing file's mode when copying it to the target repository:

https://github.com/andyfeller/gh-publicize/blob/860cd0bc4c8b3dc6c53f65d5ba0f10dbd8ede545/lib/helpers.sh#L3-L14

Two suggestions on additional flags to incorporate have been offered:

  1. -p flag
  2. -a flag
man cp relevant portions

```shell SYNOPSIS cp [-R [-H | -L | -P]] [-fi | -n] [-alpsvXx] source_file target_file cp [-R [-H | -L | -P]] [-fi | -n] [-alpsvXx] source_file ... target_directory cp [-f | -i | -n] [-alPpsvx] source_file target_file cp [-f | -i | -n] [-alPpsvx] source_file ... target_directory DESCRIPTION ... -P No symbolic links are followed. This is the default if the -R option is specified. -R If source_file designates a directory, cp copies the directory and the entire subtree connected at that point. If the source_file ends in a /, the contents of the directory are copied rather than the directory itself. This option also causes symbolic links to be copied, rather than indirected through, and for cp to create special files rather than copying them as normal files. Created directories have the same mode as the corresponding source directory, unmodified by the process' umask. In -R mode, cp will continue copying even if errors are detected. Note that cp copies hard linked files as separate files. If you need to preserve hard links, consider using tar(1), cpio(1), or pax(1) instead. -a Archive mode. Same as -RpP options. Preserves structure and attributes of files but not directory structure. ... -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. ```

Thoughts

Since copyFile method is genuinely only intended for files and not directories, -p flag in this situation seems more appropriate than -a.

Action Items

- [ ] Implement and test changes to ensure noted information is preserved as expected
- [ ] Release changes