mirror of
https://github.com/rclone/rclone.git
synced 2025-08-19 09:52:05 +02:00
vfs: convert vfs options to new style
This also - move in use options (Opt) from vfsflags to vfscommon - change os.FileMode to vfscommon.FileMode in parameters - rework vfscommon.FileMode and add tests
This commit is contained in:
40
vfs/vfscommon/filemode.go
Normal file
40
vfs/vfscommon/filemode.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package vfscommon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/rclone/rclone/fs"
|
||||
)
|
||||
|
||||
// FileMode is a command line friendly os.FileMode
|
||||
type FileMode os.FileMode
|
||||
|
||||
// String turns FileMode into a string
|
||||
func (x FileMode) String() string {
|
||||
return fmt.Sprintf("%03o", x)
|
||||
}
|
||||
|
||||
// Set a FileMode
|
||||
func (x *FileMode) Set(s string) error {
|
||||
i, err := strconv.ParseInt(s, 8, 32)
|
||||
if err != nil {
|
||||
return fmt.Errorf("bad FileMode - must be octal digits: %w", err)
|
||||
}
|
||||
*x = (FileMode)(i)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Type of the value
|
||||
func (x FileMode) Type() string {
|
||||
return "FileMode"
|
||||
}
|
||||
|
||||
// UnmarshalJSON makes sure the value can be parsed as a string or integer in JSON
|
||||
func (x *FileMode) UnmarshalJSON(in []byte) error {
|
||||
return fs.UnmarshalJSONFlag(in, x, func(i int64) error {
|
||||
*x = FileMode(i)
|
||||
return nil
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user