Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nielash committed Dec 11, 2023
0 parents commit e57c374
Show file tree
Hide file tree
Showing 8 changed files with 667 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

# Other
.DS_Store
rclone-permissions-mapper
build
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 nielash

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SHELL = bash
VERSION := 1.0

compile_all:
go run bin/cross-compile.go -compile-only $(VERSION)
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Rclone Permissions Mapper

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/).

## Usage
```bash
rclone sync source:path dest:path --metadata-mapper /path/to/rclone-permissions-mapper
```

or, to see input and output:
```bash
rclone sync source:path dest:path --metadata-mapper /path/to/rclone-permissions-mapper -v --dump mapper
```

## Background
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:

```text
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.

## Installation
[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`:
```bash
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:

```bash
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:
``` bash
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"}}
```

## Resources
* [`--metadata-mapper` docs](https://rclone.org/docs/#metadata-mapper)
* [rclone's handling of `uid` and `gid`](https://github.com/rclone/rclone/blob/c69eb84573c85206ab028eda2987180e049ef2e4/backend/local/metadata.go#L113-L128)
* [Downloads](https://github.com/nielash/rclone-permissions-mapper/releases)
* [Rclone Forum](https://forum.rclone.org/)
Loading

0 comments on commit e57c374

Please sign in to comment.