当前位置: 首页>>代码示例>>Golang>>正文


Golang FileMode.IsDir方法代码示例

本文整理汇总了Golang中os.FileMode.IsDir方法的典型用法代码示例。如果您正苦于以下问题:Golang FileMode.IsDir方法的具体用法?Golang FileMode.IsDir怎么用?Golang FileMode.IsDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os.FileMode的用法示例。


在下文中一共展示了FileMode.IsDir方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: visit

func visit(path string, f os.FileInfo, err error) error {

	var fMod os.FileMode
	fMod = f.Mode()
	if fMod.IsDir() {
		fmt.Printf("Entering Folder: %s\n", f.Name())
		return nil
	}
	fmt.Printf("Saving log: %s\n", path)
	file, err := os.Open(path)
	if err != nil {
		fmt.Printf("trouble opening file: %s\n", err)
		return nil
	}

	b := make([]byte, f.Size())
	n, err := file.Read(b)

	if int64(n) != f.Size() {
		fmt.Printf("Error reading entire file: %s\n", err)
	}
	var finalkey = KEY_PREFIX + f.Name()
	var kmsg KafkaMsg = KafkaMsg{
		Topic: FolderTopic,
		Key:   finalkey,
		Value: string(b),
	}

	sendMsg(kmsg)

	return nil
}
开发者ID:kwilsonO,项目名称:log-daemon,代码行数:32,代码来源:log-daemon.go

示例2: Chmod

func (nd *Node) Chmod(newMode os.FileMode) error {
	if nd.Size() > 0 && newMode.IsDir() {
		return errors.New("File has size, cannot change to directory")
	}
	nd.mode = newMode
	return nd.save()
}
开发者ID:sdcoffey,项目名称:Olympus,代码行数:7,代码来源:node.go

示例3: mode

// mode converts an os.FileMode to a go9p mode.
func mode(m os.FileMode, dotu bool) uint32 {
	other := uint32(m & 0777)
	if m.IsDir() {
		other |= go9p.DMDIR
	}

	if !dotu {
		return other
	}

	if m&os.ModeSymlink != 0 {
		other |= go9p.DMSYMLINK
	}
	if m&os.ModeSocket != 0 {
		other |= go9p.DMSOCKET
	}
	if m&os.ModeNamedPipe != 0 {
		other |= go9p.DMNAMEDPIPE
	}
	if m&os.ModeDevice != 0 {
		other |= go9p.DMDEVICE
	}
	if m&os.ModeSetuid != 0 {
		other |= go9p.DMSETUID
	}
	if m&os.ModeSetgid != 0 {
		other |= go9p.DMSETGID
	}

	return other
}
开发者ID:flynn,项目名称:bake,代码行数:32,代码来源:p9.go

示例4: 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
}
开发者ID:matomesc,项目名称:rkt,代码行数:13,代码来源:main.go

示例5: 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
}
开发者ID:freakmac,项目名称:adbfs,代码行数:19,代码来源:util.go

示例6: 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'
	}
}
开发者ID:clongbupt,项目名称:parfind,代码行数:20,代码来源:parfind.go

示例7: WriteEntry

func (w *Workspace) WriteEntry(name string, mode os.FileMode, modTime time.Time, r io.Reader, replace bool) error {
	os.MkdirAll(w.Root, 0755)
	filePath := w.getEntry(name)
	info, err := os.Stat(filePath)
	if err != nil {
		if mode.IsDir() {
			if err := os.MkdirAll(filePath, mode|0700); err != nil {
				return err
			}
		} else {
			if err := w.writeRegFile(filePath, mode|0600, modTime, r); err != nil {
				return err
			}
		}
	} else {
		if info.IsDir() {
			if mode.IsDir() {
				if err := os.Chmod(filePath, (mode&0777555)|0700); err != nil {
					return err
				}
			} else {
				if info.ModTime().Before(modTime) || replace {
					os.RemoveAll(filePath)
					if err := w.writeRegFile(filePath, mode|0600, modTime, r); err != nil {
						return err
					}
				} else {
					// pass
				}
			}
		} else {
			if mode.IsDir() {
				if info.ModTime().Before(modTime) || replace {
					os.RemoveAll(filePath)
					if err := os.MkdirAll(filePath, mode|0700); err != nil {
						return err
					}
				} else {
					// pass
				}
			} else {
				if info.ModTime().Before(modTime) || replace {
					if err := w.writeRegFile(filePath, mode|0600, modTime, r); err != nil {
						return err
					}
				} else {
					// pass
				}
			}
		}
	}

	return nil
}
开发者ID:thingswise,项目名称:dcd,代码行数:54,代码来源:workspace.go

示例8: parseMLST

// an entry looks something like this:
// type=file;size=12;modify=20150216084148;UNIX.mode=0644;unique=1000004g1187ec7; lorem.txt
func parseMLST(entry string, skipSelfParent bool) (os.FileInfo, error) {
	parseError := ftpError{err: fmt.Errorf(`failed parsing MLST entry: %s`, entry)}
	incompleteError := ftpError{err: fmt.Errorf(`MLST entry incomplete: %s`, entry)}

	parts := strings.Split(entry, "; ")
	if len(parts) != 2 {
		return nil, parseError
	}

	facts := make(map[string]string)
	for _, factPair := range strings.Split(parts[0], ";") {
		factParts := strings.SplitN(factPair, "=", 2)
		if len(factParts) != 2 {
			return nil, parseError
		}
		facts[strings.ToLower(factParts[0])] = strings.ToLower(factParts[1])
	}

	typ := facts["type"]

	if typ == "" {
		return nil, incompleteError
	}

	if skipSelfParent && (typ == "cdir" || typ == "pdir" || typ == "." || typ == "..") {
		return nil, nil
	}

	var mode os.FileMode
	if facts["unix.mode"] != "" {
		m, err := strconv.ParseInt(facts["unix.mode"], 8, 32)
		if err != nil {
			return nil, parseError
		}
		mode = os.FileMode(m)
	} else if facts["perm"] != "" {
		// see http://tools.ietf.org/html/rfc3659#section-7.5.5
		for _, c := range facts["perm"] {
			switch c {
			case 'a', 'd', 'c', 'f', 'm', 'p', 'w':
				// these suggest you have write permissions
				mode |= 0200
			case 'l':
				// can list dir entries means readable and executable
				mode |= 0500
			case 'r':
				// readable file
				mode |= 0400
			}
		}
	} else {
		// no mode info, just say it's readable to us
		mode = 0400
	}

	if typ == "dir" || typ == "cdir" || typ == "pdir" {
		mode |= os.ModeDir
	} else if strings.HasPrefix(typ, "os.unix=slink") || strings.HasPrefix(typ, "os.unix=symlink") {
		// note: there is no general way to determine whether a symlink points to a dir or a file
		mode |= os.ModeSymlink
	}

	var (
		size int64
		err  error
	)

	if facts["size"] != "" {
		size, err = strconv.ParseInt(facts["size"], 10, 64)
	} else if mode.IsDir() && facts["sizd"] != "" {
		size, err = strconv.ParseInt(facts["sizd"], 10, 64)
	} else if facts["type"] == "file" {
		return nil, incompleteError
	}

	if err != nil {
		return nil, parseError
	}

	if facts["modify"] == "" {
		return nil, incompleteError
	}

	mtime, err := time.ParseInLocation(timeFormat, facts["modify"], time.UTC)
	if err != nil {
		return nil, incompleteError
	}

	info := &ftpFile{
		name:  filepath.Base(parts[1]),
		size:  size,
		mtime: mtime,
		raw:   entry,
		mode:  mode,
	}

	return info, nil
}
开发者ID:stancarney,项目名称:goftp,代码行数:100,代码来源:file_system.go

示例9: parseModeSymbolic

func parseModeSymbolic(s string, base os.FileMode) (os.FileMode, error) {
	// log.Println("-- " + s)
	perm := uint32(base.Perm())
	sbitsMask := uint32(os.ModeSetuid | os.ModeSetgid | os.ModeSticky)
	sbits := uint32(base) & sbitsMask

	for i := 0; i < len(s); {
		// user, group, other, or all
		var whom uint32

		for j, c := range s[i:] {
			// log.Printf("whom: %d %s\n", i, string(s[i]))
			if c == 'u' {
				whom = whom | 0700
			} else if c == 'g' {
				whom = whom | 0070
			} else if c == 'o' {
				whom = whom | 0007
			} else if c == 'a' {
				whom = whom | 0777
			} else {
				if j == 0 {
					whom = 0777
				}
				break
			}
			i++
		}
		if i >= len(s) {
			return 0, errors.New("failed to parse the mode, operator is not found")
		}

		for i < len(s) {
			// operator
			// log.Printf("op: %d %s\n", i, string(s[i]))
			op := 0
			switch s[i] {
			case '-':
				op = '-'
			case '+':
				op = '+'
			case '=':
				op = '='
			default:
				return 0, errors.New("failed to parse the mode, invalid operator")
			}
			i++

			// permission bits to modify
			var smod uint32
			var mod uint32
			if i < len(s) {
				// log.Printf("mod: %d %s\n", i, string(s[i]))
				switch s[i] {
				case 'u':
					mod = (perm & 0700) >> 6
					i++
				case 'g':
					mod = (perm & 0070) >> 3
					i++
				case 'o':
					mod = (perm & 0007) >> 0
					i++
				default:
					for i < len(s) {
						// log.Printf("mod-f: %d %s\n", i, string(s[i]))
						if s[i] == 'r' {
							mod = mod | 4
						} else if s[i] == 'w' {
							mod = mod | 2
						} else if s[i] == 'x' {
							mod = mod | 1
						} else if s[i] == 'X' {
							if base.IsDir() {
								mod = mod | 1
							}
						} else if s[i] == 's' {
							if (whom & 0700) > 0 {
								smod = smod | uint32(os.ModeSetuid)
							}
							if (whom & 0070) > 0 {
								smod = smod | uint32(os.ModeSetgid)
							}
						} else if s[i] == 't' {
							smod = smod | uint32(os.ModeSticky)
						} else {
							break
						}
						i++
					}
				}
				mod = mod<<6 | mod<<3 | mod<<0
			}
			// if i < len(s) {
			//	log.Printf("mod-e: %d %s\n", i, string(s[i]))
			//}

			switch op {
			case '-':
				perm = perm - (whom & mod)
//.........这里部分代码省略.........
开发者ID:harukasan,项目名称:orchestra-pit,代码行数:101,代码来源:parseMode.go


注:本文中的os.FileMode.IsDir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。