Tool to convert uid
and gid
between mac and linux defaults when syncing files via cloud storage using rclone sync
.
rclone sync source:path dest:path --metadata-mapper /path/to/rclone-permissions-mapper
or, to see input and output:
rclone sync source:path dest:path --metadata-mapper /path/to/rclone-permissions-mapper -v --dump mapper
The default UID of the first regular user on macOS is 501
. On Linux, it is usually 1000
. If you rclone sync
a file created on one to the other (by way of a cloud storage remote) and use the --metadata
flag (without using sudo
), by default you will probably get an error like this one:
ERROR : file.txt: Failed to copy: failed to set metadata: failed to change ownership: chown /testing/file.txt.fekayen6.partial: operation not permitted
This is because it is trying to chown 1000:1000 /testing/file.txt
when actually it should be 501:20
(or vice versa.)
This tool uses rclone's new --metadata-mapper
feature to automatically detect and correct this during the sync. It does so by simply omitting the uid
and gid
(when necessary) in the metadata blob it passes back to rclone, so that the default values are kept.
Download and unzip (or build from source with go build
), and then move the executable to your $PATH
:
sudo rclone moveto /Users/yourusername/Downloads/rclone-permissions-mapper-1.0-osx-arm64/rclone-permissions-mapper /usr/local/bin/rclone-permissions-mapper -v
Test if it's working:
echo '{"Metadata": {"hello": "world"}}' | rclone-permissions-mapper
should output: {"Metadata":{"hello":"world"}}
You can test what it will do by giving it different uid
and gid
values:
echo '{"Metadata":{"gid":"20","uid":"501"}}' | rclone-permissions-mapper
// on mac: {"Metadata":{"gid":"20","uid":"501"}}
// on linux: {"Metadata":{}}
echo '{"Metadata":{"gid":"1000","uid":"1000"}}' | rclone-permissions-mapper
// on mac: {"Metadata":{}}
// on linux: {"Metadata":{"gid":"20","uid":"501"}}