Skip to content

Commit e57c374

Browse files
committed
Initial commit
0 parents  commit e57c374

8 files changed

Lines changed: 667 additions & 0 deletions

File tree

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
20+
# Go workspace file
21+
go.work
22+
23+
# Other
24+
.DS_Store
25+
rclone-permissions-mapper
26+
build

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 nielash
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SHELL = bash
2+
VERSION := 1.0
3+
4+
compile_all:
5+
go run bin/cross-compile.go -compile-only $(VERSION)

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)