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


Golang FileSystem.Walk方法代码示例

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


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

示例1: isValidGitRepository

// isValidGitRepository checks to see if there is a git repository in the
// directory and if the repository is valid -- i.e. it has remotes or commits
func isValidGitRepository(fs util.FileSystem, dir string) (bool, error) {
	gitPath := filepath.Join(strings.TrimPrefix(dir, "file://"), ".git")

	fi, err := fs.Stat(gitPath)
	if os.IsNotExist(err) {
		// The directory is not a git repo, no error
		return false, nil
	}
	if err != nil {
		return false, err
	}

	if !fi.IsDir() {
		gitPath, err = followGitSubmodule(fs, gitPath)
		if err != nil {
			return false, err
		}
	}

	// Search the content of the .git directory for content
	directories := [2]string{
		filepath.Join(gitPath, "objects"),
		filepath.Join(gitPath, "refs"),
	}

	// For the directories we search, if the git repo has been used, there will
	// be some file.  We don't just search the base git repository because of the
	// hook samples that are normally generated with `git init`
	isEmpty := true
	for _, dir := range directories {
		err := fs.Walk(dir, func(path string, info os.FileInfo, err error) error {
			// If we find a file, the git directory is "not empty"
			// We're looking for object blobs, and ref files
			if info != nil && !info.IsDir() {
				isEmpty = false
				return filepath.SkipDir
			}

			return err
		})

		if err != nil && err != filepath.SkipDir {
			// There is a .git, but we've encountered an error
			return true, err
		}

		if !isEmpty {
			return true, nil
		}
	}

	// Since we know there's a .git directory, but there is nothing in it, we
	// throw an error
	return true, errors.NewEmptyGitRepositoryError(dir)
}
开发者ID:php-coder,项目名称:origin,代码行数:57,代码来源:git.go


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