rclone/vfs/vfsflags/filemode.go

33 lines
571 B
Go
Raw Normal View History

package vfsflags
import (
"fmt"
"os"
"strconv"
)
// 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 {
2023-02-20 19:12:46 +01:00
i, err := strconv.ParseInt(s, 8, 32)
if err != nil {
return fmt.Errorf("bad FileMode - must be octal digits: %w", err)
}
*x.Mode = (os.FileMode)(i)
return nil
}
// Type of the value
func (x *FileMode) Type() string {
return "FileMode"
}