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

Golang ignore.New函数代码示例

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

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



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

示例1: TestWalk

func TestWalk(t *testing.T) {
	ignores := ignore.New(false)
	err := ignores.Load("testdata/.stignore")
	if err != nil {
		t.Fatal(err)
	}
	t.Log(ignores)

	w := Walker{
		Dir:       "testdata",
		BlockSize: 128 * 1024,
		Matcher:   ignores,
		Hashers:   2,
	}

	fchan, err := w.Walk()
	if err != nil {
		t.Fatal(err)
	}

	var tmp []protocol.FileInfo
	for f := range fchan {
		tmp = append(tmp, f)
	}
	sort.Sort(fileList(tmp))
	files := fileList(tmp).testfiles()

	if !reflect.DeepEqual(files, testdata) {
		t.Errorf("Walk returned unexpected data\nExpected: %v\nActual: %v", testdata, files)
	}
}
开发者ID:kristallizer,项目名称:syncthing,代码行数:31,代码来源:walk_test.go


示例2: TestWalk

func TestWalk(t *testing.T) {
	ignores := ignore.New(false)
	err := ignores.Load("testdata/.stignore")
	if err != nil {
		t.Fatal(err)
	}
	t.Log(ignores)

	fchan, err := Walk(Config{
		Dir:       "testdata",
		BlockSize: 128 * 1024,
		Matcher:   ignores,
		Hashers:   2,
	})

	if err != nil {
		t.Fatal(err)
	}

	var tmp []protocol.FileInfo
	for f := range fchan {
		tmp = append(tmp, f)
	}
	sort.Sort(fileList(tmp))
	files := fileList(tmp).testfiles()

	if diff, equal := messagediff.PrettyDiff(testdata, files); !equal {
		t.Errorf("Walk returned unexpected data. Diff:\n%s", diff)
	}
}
开发者ID:carriercomm,项目名称:syncthing,代码行数:30,代码来源:walk_test.go


示例3: TestWalkSub

func TestWalkSub(t *testing.T) {
	ignores := ignore.New(false)
	err := ignores.Load("testdata/.stignore")
	if err != nil {
		t.Fatal(err)
	}

	fchan, err := Walk(Config{
		Dir:       "testdata",
		Subs:      []string{"dir2"},
		BlockSize: 128 * 1024,
		Matcher:   ignores,
		Hashers:   2,
	})
	var files []protocol.FileInfo
	for f := range fchan {
		files = append(files, f)
	}
	if err != nil {
		t.Fatal(err)
	}

	// The directory contains two files, where one is ignored from a higher
	// level. We should see only the directory and one of the files.

	if len(files) != 2 {
		t.Fatalf("Incorrect length %d != 2", len(files))
	}
	if files[0].Name != "dir2" {
		t.Errorf("Incorrect file %v != dir2", files[0])
	}
	if files[1].Name != filepath.Join("dir2", "cfile") {
		t.Errorf("Incorrect file %v != dir2/cfile", files[1])
	}
}
开发者ID:carriercomm,项目名称:syncthing,代码行数:35,代码来源:walk_test.go


示例4: TestIssue3164

func TestIssue3164(t *testing.T) {
	os.RemoveAll("testdata/issue3164")
	defer os.RemoveAll("testdata/issue3164")

	if err := os.MkdirAll("testdata/issue3164/oktodelete/foobar", 0777); err != nil {
		t.Fatal(err)
	}
	if err := ioutil.WriteFile("testdata/issue3164/oktodelete/foobar/file", []byte("Hello"), 0644); err != nil {
		t.Fatal(err)
	}
	if err := ioutil.WriteFile("testdata/issue3164/oktodelete/file", []byte("Hello"), 0644); err != nil {
		t.Fatal(err)
	}
	f := protocol.FileInfo{
		Name: "issue3164",
	}
	m := ignore.New(false)
	if err := m.Parse(bytes.NewBufferString("(?d)oktodelete"), ""); err != nil {
		t.Fatal(err)
	}

	fl := rwFolder{
		dbUpdates: make(chan dbUpdateJob, 1),
		dir:       "testdata",
	}

	fl.deleteDir(f, m)

	if _, err := os.Stat("testdata/issue3164"); !os.IsNotExist(err) {
		t.Fatal(err)
	}
}
开发者ID:brgmnn,项目名称:syncthing,代码行数:32,代码来源:model_test.go


示例5: watchFolder

// watchFolder installs inotify watcher for a folder, launches
// goroutine which receives changed items. It never exits.
func watchFolder(folder FolderConfiguration, stInput chan STEvent) {
	folderPath, err := realPath(expandTilde(folder.Path))
	if err != nil {
		Warning.Println("Failed to install inotify handler for "+folder.Label+".", err)
		informError("Failed to install inotify handler for " + folder.Label + ": " + err.Error())
		return
	}
	ignores := ignore.New(false)
	Trace.Println("Getting ignore patterns for " + folder.Label)
	ignores.Load(filepath.Join(folderPath, ".stignore"))
	fsInput := make(chan string)
	c := make(chan notify.EventInfo, maxFiles)
	ignoreTest := func(absolutePath string) bool {
		relPath := relativePath(absolutePath, folderPath)
		return ignores.Match(relPath).IsIgnored()
	}
	notify.SetDoNotWatch(ignoreTest)
	if err := notify.Watch(filepath.Join(folderPath, "..."), c, notify.All); err != nil {
		if strings.Contains(err.Error(), "too many open files") || strings.Contains(err.Error(), "no space left on device") {
			msg := "Failed to install inotify handler for " + folder.Label + ". Please increase inotify limits, see http://bit.ly/1PxkdUC for more information."
			Warning.Println(msg, err)
			informError(msg)
			return
		} else {
			Warning.Println("Failed to install inotify handler for "+folder.Label+".", err)
			informError("Failed to install inotify handler for " + folder.Label + ": " + err.Error())
			return
		}
	}
	defer notify.Stop(c)
	go accumulateChanges(debounceTimeout, folder.ID, folderPath, dirVsFiles, stInput, fsInput, informChange)
	OK.Println("Watching " + folder.Label + ": " + folderPath)
	if folder.RescanIntervalS < 1800 && delayScan <= 0 {
		OK.Printf("The rescan interval of folder %s can be increased to 3600 (an hour) or even 86400 (a day) as changes should be observed immediately while syncthing-inotify is running.", folder.Label)
	}
	// will we ever get out of this loop?
	for {
		evAbsolutePath := waitForEvent(c)
		Debug.Println("Change detected in: " + evAbsolutePath + " (could still be ignored)")
		evRelPath := relativePath(evAbsolutePath, folderPath)
		if ignores.Match(evRelPath).IsIgnored() {
			Debug.Println("Ignoring", evAbsolutePath)
			continue
		}
		Trace.Println("Change detected in: " + evAbsolutePath)
		fsInput <- evRelPath
	}
}
开发者ID:tillberg,项目名称:syncthing-inotify,代码行数:50,代码来源:syncwatcher.go


示例6: createIgnoreFilter

// Returns a function to test whether a path should be ignored.
// The directory given by the absolute path "folderPath" must contain the
// ".stignore" file. The returned function expects the path of the file to be
// tested relative to its folders root.
func createIgnoreFilter(folderPath string) func(relPath string) bool {
	ignores := ignore.New(false)
	ignores.Load(filepath.Join(folderPath, ".stignore"))
	return func(relPath string) bool {
		if strings.SplitN(relPath, pathSeparator, 2)[0] == versionFolder {
			return true
		}
		for _, ignorePrefix := range tempFilePrefixes {
			if strings.HasPrefix(filepath.Base(relPath), ignorePrefix) &&
				strings.HasSuffix(relPath, tempFileSuffix) {
				return true
			}
		}
		return ignores.Match(relPath).IsIgnored()
	}
}
开发者ID:syncthing,项目名称:syncthing-inotify,代码行数:20,代码来源:syncwatcher.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang ignore.Matcher类代码示例发布时间:2022-05-29
下一篇:
Golang events.Subscription类代码示例发布时间: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