Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

vfs: add --dir-perms and --file-perms flags - fixes #2897

Nick Craig-Wood554ee0d96351
diff --git a/vfs/vfs.go b/vfs/vfs.go
index e49235228..ea39e0753 100644
--- a/vfs/vfs.go
+++ b/vfs/vfs.go
@@ -43,7 +43,7 @@ var DefaultOpt = Options{
Umask: 0,
UID: ^uint32(0), // these values instruct WinFSP-FUSE to use the current user
GID: ^uint32(0), // overriden for non windows in mount_unix.go
- DirPerms: os.FileMode(0777) | os.ModeDir,
+ DirPerms: os.FileMode(0777),
FilePerms: os.FileMode(0666),
CacheMode: CacheModeOff,
CacheMaxAge: 3600 * time.Second,
diff --git a/vfs/vfsflags/filemode.go b/vfs/vfsflags/filemode.go
new file mode 100644
index 000000000..cfa39a71e
--- /dev/null
+++ b/vfs/vfsflags/filemode.go
@@ -0,0 +1,34 @@
+package vfsflags
+
+import (
+ "fmt"
+ "os"
+ "strconv"
+
+ "github.com/pkg/errors"
+)
+
+// FileMode is a command line friendly os.FileMode
+type FileMode struct {
+ Mode *os.FileMode
+}
+
+// String turns FileMode into a string
+func (x *FileMode) String() string {
+ return fmt.Sprintf("0%3o", *x.Mode)
+}
+
+// Set a FileMode
+func (x *FileMode) Set(s string) error {
+ i, err := strconv.ParseInt(s, 8, 64)
+ if err != nil {
+ return errors.Wrap(err, "Bad FileMode - must be octal digits")
+ }
+ *x.Mode = (os.FileMode)(i)
+ return nil
+}
+
+// Type of the value
+func (x *FileMode) Type() string {
+ return "int"
+}
diff --git a/vfs/vfsflags/vfsflags.go b/vfs/vfsflags/vfsflags.go
index b90e6509f..b216b16c7 100644
--- a/vfs/vfsflags/vfsflags.go
+++ b/vfs/vfsflags/vfsflags.go
@@ -10,7 +10,9 @@ import (
// Options set by command line flags
var (
- Opt = vfs.DefaultOpt
+ Opt = vfs.DefaultOpt
+ DirPerms = &FileMode{Mode: &Opt.DirPerms}
+ FilePerms = &FileMode{Mode: &Opt.FilePerms}
)
// AddFlags adds the non filing system specific flags to the command
@@ -27,5 +29,7 @@ func AddFlags(flagSet *pflag.FlagSet) {
flags.DurationVarP(flagSet, &Opt.CacheMaxAge, "vfs-cache-max-age", "", Opt.CacheMaxAge, "Max age of objects in the cache.")
flags.FVarP(flagSet, &Opt.ChunkSize, "vfs-read-chunk-size", "", "Read the source objects in chunks.")
flags.FVarP(flagSet, &Opt.ChunkSizeLimit, "vfs-read-chunk-size-limit", "", "If greater than --vfs-read-chunk-size, double the chunk size after each chunk read, until the limit is reached. 'off' is unlimited.")
+ flags.FVarP(flagSet, DirPerms, "dir-perms", "", "Directory permissions")
+ flags.FVarP(flagSet, FilePerms, "file-perms", "", "File permissions")
platformFlags(flagSet)
}