• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang protocol.Vector类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/syncthing/syncthing/lib/protocol.Vector的典型用法代码示例。如果您正苦于以下问题:Golang Vector类的具体用法?Golang Vector怎么用?Golang Vector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: walkSymlink

// walkSymlinks returns true if the symlink should be skipped, or an error if
// we should stop walking altogether. filepath.Walk isn't supposed to
// transcend into symlinks at all, but there are rumours that this may have
// happened anyway under some circumstances, possibly Windows reparse points
// or something. Hence the "skip" return from this one.
func (w *Walker) walkSymlink(absPath, relPath string, dchan chan protocol.FileInfo) (skip bool, err error) {
	// If the target is a directory, do NOT descend down there. This will
	// cause files to get tracked, and removing the symlink will as a result
	// remove files in their real location.
	if !symlinks.Supported {
		return true, nil
	}

	// We always rehash symlinks as they have no modtime or
	// permissions. We check if they point to the old target by
	// checking that their existing blocks match with the blocks in
	// the index.

	target, targetType, err := symlinks.Read(absPath)
	if err != nil {
		l.Debugln("readlink error:", absPath, err)
		return true, nil
	}

	blocks, err := Blocks(strings.NewReader(target), w.BlockSize, 0, nil)
	if err != nil {
		l.Debugln("hash link error:", absPath, err)
		return true, nil
	}

	var currentVersion protocol.Vector
	if w.CurrentFiler != nil {
		// A symlink is "unchanged", if
		//  - it exists
		//  - it wasn't deleted (because it isn't now)
		//  - it was a symlink
		//  - it wasn't invalid
		//  - the symlink type (file/dir) was the same
		//  - the block list (i.e. hash of target) was the same
		cf, ok := w.CurrentFiler.CurrentFile(relPath)
		if ok && !cf.IsDeleted() && cf.IsSymlink() && !cf.IsInvalid() && SymlinkTypeEqual(targetType, cf) && BlocksEqual(cf.Blocks, blocks) {
			return true, nil
		}
		currentVersion = cf.Version
	}

	f := protocol.FileInfo{
		Name:     relPath,
		Version:  currentVersion.Update(w.ShortID),
		Flags:    uint32(protocol.FlagSymlink | protocol.FlagNoPermBits | 0666 | SymlinkFlags(targetType)),
		Modified: 0,
		Blocks:   blocks,
	}

	l.Debugln("symlink changedb:", absPath, f)

	select {
	case dchan <- f:
	case <-w.Cancel:
		return false, errors.New("cancelled")
	}

	return false, nil
}
开发者ID:wmwwmv,项目名称:syncthing,代码行数:64,代码来源:walk.go


示例2: walkRegular

func (w *Walker) walkRegular(relPath string, info os.FileInfo, mtime time.Time, fchan chan protocol.FileInfo) error {
	curMode := uint32(info.Mode())
	if runtime.GOOS == "windows" && osutil.IsWindowsExecutable(relPath) {
		curMode |= 0111
	}

	var currentVersion protocol.Vector
	if w.CurrentFiler != nil {
		// A file is "unchanged", if it
		//  - exists
		//  - has the same permissions as previously, unless we are ignoring permissions
		//  - was not marked deleted (since it apparently exists now)
		//  - had the same modification time as it has now
		//  - was not a directory previously (since it's a file now)
		//  - was not a symlink (since it's a file now)
		//  - was not invalid (since it looks valid now)
		//  - has the same size as previously
		cf, ok := w.CurrentFiler.CurrentFile(relPath)
		permUnchanged := w.IgnorePerms || !cf.HasPermissionBits() || PermsEqual(cf.Flags, curMode)
		if ok && permUnchanged && !cf.IsDeleted() && cf.Modified == mtime.Unix() && !cf.IsDirectory() &&
			!cf.IsSymlink() && !cf.IsInvalid() && cf.Size() == info.Size() {
			return nil
		}
		currentVersion = cf.Version

		l.Debugln("rescan:", cf, mtime.Unix(), info.Mode()&os.ModePerm)
	}

	var flags = curMode & uint32(maskModePerm)
	if w.IgnorePerms {
		flags = protocol.FlagNoPermBits | 0666
	}

	f := protocol.FileInfo{
		Name:       relPath,
		Version:    currentVersion.Update(w.ShortID),
		Flags:      flags,
		Modified:   mtime.Unix(),
		CachedSize: info.Size(),
	}
	l.Debugln("to hash:", relPath, f)

	select {
	case fchan <- f:
	case <-w.Cancel:
		return errors.New("cancelled")
	}

	return nil
}
开发者ID:wmwwmv,项目名称:syncthing,代码行数:50,代码来源:walk.go


示例3: walkDir

func (w *Walker) walkDir(relPath string, info os.FileInfo, mtime time.Time, dchan chan protocol.FileInfo) error {
	var currentVersion protocol.Vector

	if w.CurrentFiler != nil {
		// A directory is "unchanged", if it
		//  - exists
		//  - has the same permissions as previously, unless we are ignoring permissions
		//  - was not marked deleted (since it apparently exists now)
		//  - was a directory previously (not a file or something else)
		//  - was not a symlink (since it's a directory now)
		//  - was not invalid (since it looks valid now)
		cf, ok := w.CurrentFiler.CurrentFile(relPath)
		permUnchanged := w.IgnorePerms || !cf.HasPermissionBits() || PermsEqual(cf.Flags, uint32(info.Mode()))
		if ok && permUnchanged && !cf.IsDeleted() && cf.IsDirectory() && !cf.IsSymlink() && !cf.IsInvalid() {
			return nil
		}
		currentVersion = cf.Version
	}

	flags := uint32(protocol.FlagDirectory)
	if w.IgnorePerms {
		flags |= protocol.FlagNoPermBits | 0777
	} else {
		flags |= uint32(info.Mode() & maskModePerm)
	}
	f := protocol.FileInfo{
		Name:     relPath,
		Version:  currentVersion.Update(w.ShortID),
		Flags:    flags,
		Modified: mtime.Unix(),
	}
	l.Debugln("dir:", relPath, f)

	select {
	case dchan <- f:
	case <-w.Cancel:
		return errors.New("cancelled")
	}

	return nil
}
开发者ID:wmwwmv,项目名称:syncthing,代码行数:41,代码来源:walk.go


示例4: inConflict

func (f *rwFolder) inConflict(current, replacement protocol.Vector) bool {
	if current.Concurrent(replacement) {
		// Obvious case
		return true
	}
	if replacement.Counter(f.model.shortID) > current.Counter(f.model.shortID) {
		// The replacement file contains a higher version for ourselves than
		// what we have. This isn't supposed to be possible, since it's only
		// we who can increment that counter. We take it as a sign that
		// something is wrong (our index may have been corrupted or removed)
		// and flag it as a conflict.
		return true
	}
	return false
}
开发者ID:kluppy,项目名称:syncthing,代码行数:15,代码来源:rwfolder.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang rand.String函数代码示例发布时间:2022-05-29
下一篇:
Golang protocol.FileInfo类代码示例发布时间:2022-05-29
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap