示例#1
0
func (s *shard) CommitGet(name string) (Commit, error) {
	commitPath := path.Join(s.dataRepo, name)
	isCommit, err := btrfs.IsCommit(commitPath)
	if err != nil {
		return Commit{}, err
	}
	if !isCommit {
		return Commit{}, ErrInvalidObject
	}
	info, err := btrfs.Stat(commitPath)
	if err != nil {
		return Commit{}, err
	}
	return Commit{name, info.ModTime()}, nil
}
示例#2
0
func (s *shard) BranchGet(name string) (Branch, error) {
	branchPath := path.Join(s.dataRepo, name)
	isCommit, err := btrfs.IsCommit(branchPath)
	if err != nil {
		return Branch{}, err
	}
	if isCommit {
		return Branch{}, ErrInvalidObject
	}
	info, err := btrfs.Stat(branchPath)
	if err != nil {
		return Branch{}, err
	}
	return Branch{name, info.ModTime()}, nil
}
示例#3
0
func (s *shard) fileGet(dir string, name string) (File, error) {
	path := path.Join(dir, name)
	info, err := btrfs.Stat(path)
	if err != nil {
		return File{}, err
	}
	if info.IsDir() {
		return File{}, ErrIsDirectory
	}
	file, err := btrfs.Open(path)
	if err != nil {
		return File{}, err
	}
	return File{
		name,
		info.ModTime(),
		file,
	}, nil
}
示例#4
0
func (s *shard) BranchList() ([]Branch, error) {
	var result []Branch
	if err := btrfs.Commits(s.dataRepo, "", btrfs.Desc, func(name string) error {
		isCommit, err := btrfs.IsCommit(path.Join(s.dataRepo, name))
		if err != nil {
			return err
		}
		if !isCommit {
			fi, err := btrfs.Stat(path.Join(s.dataRepo, name))
			if err != nil {
				return err
			}
			result = append(result, Branch{name, fi.ModTime()})
		}
		return nil
	}); err != nil {
		return nil, err
	}
	return result, nil
}