|
| 1 | +# Rclone Permissions Mapper |
| 2 | + |
| 3 | +Tool to convert `uid` and `gid` between mac and linux defaults when syncing files via cloud storage using [rclone](https://github.com/rclone/rclone) [`sync`](https://rclone.org/commands/rclone_sync/). |
| 4 | + |
| 5 | +## Usage |
| 6 | +```bash |
| 7 | +rclone sync source:path dest:path --metadata-mapper /path/to/rclone-permissions-mapper |
| 8 | +``` |
| 9 | + |
| 10 | +or, to see input and output: |
| 11 | +```bash |
| 12 | +rclone sync source:path dest:path --metadata-mapper /path/to/rclone-permissions-mapper -v --dump mapper |
| 13 | +``` |
| 14 | + |
| 15 | +## Background |
| 16 | +The default UID of the first regular user on macOS is `501`. On Linux, it is usually `1000`. If you [`rclone sync`](https://rclone.org/commands/rclone_sync/) a file created on one to the other (by way of a cloud storage remote) and use the [`--metadata`](https://rclone.org/docs/#m-metadata) flag (without using `sudo`), by default you will probably get an error like this one: |
| 17 | + |
| 18 | +```text |
| 19 | +ERROR : file.txt: Failed to copy: failed to set metadata: failed to change ownership: chown /testing/file.txt.fekayen6.partial: operation not permitted |
| 20 | +``` |
| 21 | + |
| 22 | +This is because it is trying to `chown 1000:1000 /testing/file.txt` when actually it should be `501:20` (or vice versa.) |
| 23 | + |
| 24 | +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. |
| 25 | + |
| 26 | +## Installation |
| 27 | +[Download](https://github.com/nielash/rclone-permissions-mapper/releases) and unzip (or build from source with `go build`), and then move the executable to your `$PATH`: |
| 28 | +```bash |
| 29 | +sudo rclone moveto /Users/yourusername/Downloads/rclone-permissions-mapper-1.0-osx-arm64/rclone-permissions-mapper /usr/local/bin/rclone-permissions-mapper -v |
| 30 | +``` |
| 31 | + |
| 32 | +Test if it's working: |
| 33 | + |
| 34 | +```bash |
| 35 | +echo '{"Metadata": {"hello": "world"}}' | rclone-permissions-mapper |
| 36 | +``` |
| 37 | +should output: `{"Metadata":{"hello":"world"}}` |
| 38 | + |
| 39 | +You can test what it will do by giving it different `uid` and `gid` values: |
| 40 | +``` bash |
| 41 | +echo '{"Metadata":{"gid":"20","uid":"501"}}' | rclone-permissions-mapper |
| 42 | +// on mac: {"Metadata":{"gid":"20","uid":"501"}} |
| 43 | +// on linux: {"Metadata":{}} |
| 44 | + |
| 45 | +echo '{"Metadata":{"gid":"1000","uid":"1000"}}' | rclone-permissions-mapper |
| 46 | +// on mac: {"Metadata":{}} |
| 47 | +// on linux: {"Metadata":{"gid":"20","uid":"501"}} |
| 48 | +``` |
| 49 | + |
| 50 | +## Resources |
| 51 | +* [`--metadata-mapper` docs](https://rclone.org/docs/#metadata-mapper) |
| 52 | +* [rclone's handling of `uid` and `gid`](https://github.com/rclone/rclone/blob/c69eb84573c85206ab028eda2987180e049ef2e4/backend/local/metadata.go#L113-L128) |
| 53 | +* [Downloads](https://github.com/nielash/rclone-permissions-mapper/releases) |
| 54 | +* [Rclone Forum](https://forum.rclone.org/) |
0 commit comments