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:
Nick Craig-Wood
2024-07-03 11:34:29 +01:00
parent fc1d8dafd5
commit a28287e96d
39 changed files with 408 additions and 236 deletions

40
vfs/vfscommon/filemode.go Normal file
View 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
})
}