本文整理汇总了Golang中os.FileMode.IsRegular方法的典型用法代码示例。如果您正苦于以下问题:Golang FileMode.IsRegular方法的具体用法?Golang FileMode.IsRegular怎么用?Golang FileMode.IsRegular使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os.FileMode
的用法示例。
在下文中一共展示了FileMode.IsRegular方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: put
// put single file
func put(args []string) error {
fs := flag.NewFlagSet("put", flag.ContinueOnError)
fs.Usage = func() {
fmt.Fprintln(os.Stderr, "create usage: gomote put [put-opts] <buildlet-name> <source or '-' for stdin> [destination]")
fs.PrintDefaults()
os.Exit(1)
}
modeStr := fs.String("mode", "", "Unix file mode (octal); default to source file mode")
fs.Parse(args)
if n := fs.NArg(); n < 2 || n > 3 {
fs.Usage()
}
bc, err := namedClient(fs.Arg(0))
if err != nil {
return err
}
var r io.Reader = os.Stdin
var mode os.FileMode = 0666
src := fs.Arg(1)
if src != "-" {
f, err := os.Open(src)
if err != nil {
return err
}
defer f.Close()
r = f
if *modeStr == "" {
fi, err := f.Stat()
if err != nil {
return err
}
mode = fi.Mode()
}
}
if *modeStr != "" {
modeInt, err := strconv.ParseInt(*modeStr, 8, 64)
if err != nil {
return err
}
mode = os.FileMode(modeInt)
if !mode.IsRegular() {
return fmt.Errorf("bad mode: %v", mode)
}
}
dest := fs.Arg(2)
if dest == "" {
if src == "-" {
return errors.New("must specify destination file name when source is standard input")
}
dest = filepath.Base(src)
}
return bc.Put(r, dest, mode)
}
示例2: categorizeEntry
func categorizeEntry(path string, mode os.FileMode, list *filelist.Lists) error {
switch {
case mode.IsDir():
list.Dirs = append(list.Dirs, path)
case mode.IsRegular():
list.Files = append(list.Files, path)
case isSymlink(mode):
list.Symlinks = append(list.Symlinks, path)
default:
return fmt.Errorf("unsupported file mode: %d (not a file, directory or symlink)", mode&os.ModeType)
}
return nil
}
示例3: osFileModeToFuseFileMode
// osFileModeToFuseFileMode converts a standard os.FileMode to the bit array used
// by the fuse package. Permissions, regular/dir modes, symlinks, and named pipes
// are the only bits that are converted.
func osFileModeToFuseFileMode(inMode os.FileMode) (outMode uint32) {
if inMode.IsRegular() {
outMode |= fuse.S_IFREG
}
if inMode.IsDir() {
outMode |= fuse.S_IFDIR
}
if inMode&os.ModeSymlink == os.ModeSymlink {
outMode |= fuse.S_IFLNK
}
if inMode&os.ModeNamedPipe == os.ModeNamedPipe {
outMode |= fuse.S_IFIFO
}
outMode |= uint32(inMode.Perm())
return
}
示例4: modeToType
func modeToType(mode os.FileMode) byte {
switch {
case mode.IsDir():
return 'd'
case mode.IsRegular():
return 'f'
case mode&os.ModeSymlink != 0:
return 'l'
case mode&os.ModeSocket != 0:
return 's'
case mode&os.ModeNamedPipe != 0:
return 'p'
case mode&os.ModeDevice != 0 && mode&os.ModeCharDevice != 0:
return 'C'
case mode&os.ModeDevice != 0 && mode&os.ModeCharDevice == 0:
return 'D'
default:
return 'u'
}
}