2014-12-21 08:26:54 +00:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
|
|
|
//
|
2015-03-07 20:36:35 +00:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 06:52:18 +00:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2014-12-21 08:26:54 +00:00
|
|
|
|
2021-08-17 08:10:41 +00:00
|
|
|
//go:build integration
|
2014-12-21 08:26:54 +00:00
|
|
|
// +build integration
|
|
|
|
|
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
2017-11-12 23:54:21 +00:00
|
|
|
"time"
|
2014-12-21 08:26:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIgnores(t *testing.T) {
|
|
|
|
// Clean and start a syncthing instance
|
|
|
|
|
|
|
|
log.Println("Cleaning...")
|
2015-03-29 10:55:27 +00:00
|
|
|
err := removeAll("s1", "h1/index*")
|
2014-12-21 08:26:54 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2015-06-18 13:22:45 +00:00
|
|
|
p := startInstance(t, 1)
|
|
|
|
defer checkedStop(t, p)
|
2014-12-21 08:26:54 +00:00
|
|
|
|
|
|
|
// Create eight empty files and directories
|
|
|
|
|
|
|
|
dirs := []string{"d1", "d2", "d3", "d4", "d11", "d12", "d13", "d14"}
|
2015-09-02 18:54:18 +00:00
|
|
|
files := []string{"f1", "f2", "f3", "f4", "f11", "f12", "f13", "f14", "d1/f1.TXT"}
|
2014-12-21 08:26:54 +00:00
|
|
|
|
2015-09-02 18:54:18 +00:00
|
|
|
for _, dir := range dirs {
|
|
|
|
err := os.Mkdir(filepath.Join("s1", dir), 0755)
|
2014-12-21 08:26:54 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-02 18:54:18 +00:00
|
|
|
for _, file := range files {
|
|
|
|
fd, err := os.Create(filepath.Join("s1", file))
|
2014-12-21 08:26:54 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-09-02 18:54:18 +00:00
|
|
|
fd.Close()
|
2014-12-21 08:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Rescan and verify that we see them all
|
|
|
|
|
2015-06-18 13:22:45 +00:00
|
|
|
if err := p.Rescan("default"); err != nil {
|
|
|
|
t.Fatal(err)
|
2015-03-16 20:14:19 +00:00
|
|
|
}
|
|
|
|
|
2015-06-18 13:22:45 +00:00
|
|
|
m, err := p.Model("default")
|
2014-12-21 08:26:54 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-11-12 23:54:21 +00:00
|
|
|
expected := len(files) // nothing is ignored
|
2014-12-21 08:26:54 +00:00
|
|
|
if m.LocalFiles != expected {
|
|
|
|
t.Fatalf("Incorrect number of files after initial scan, %d != %d", m.LocalFiles, expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add some of them to an ignore file
|
|
|
|
|
2021-11-22 07:59:47 +00:00
|
|
|
err = os.WriteFile("s1/.stignore",
|
2017-11-12 23:54:21 +00:00
|
|
|
[]byte("f1*\nf2\nd1*\nd2\ns1*\ns2\n(?i)*.txt"), // [fds][34] only non-ignored items
|
|
|
|
0644)
|
2014-12-21 08:26:54 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rescan and verify that we see them
|
|
|
|
|
2015-06-18 13:22:45 +00:00
|
|
|
if err := p.Rescan("default"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
m, err = p.Model("default")
|
2014-12-21 08:26:54 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-11-12 23:54:21 +00:00
|
|
|
expected = len(files) * 2 / 8 // two out of eight items should remain
|
2014-12-21 08:26:54 +00:00
|
|
|
if m.LocalFiles != expected {
|
|
|
|
t.Fatalf("Incorrect number of files after first ignore, %d != %d", m.LocalFiles, expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change the pattern to include some of the files and dirs previously ignored
|
|
|
|
|
2017-11-12 23:54:21 +00:00
|
|
|
time.Sleep(1100 * time.Millisecond)
|
2021-11-22 07:59:47 +00:00
|
|
|
err = os.WriteFile("s1/.stignore", []byte("f2\nd2\ns2\n"), 0644)
|
2014-12-21 08:26:54 +00:00
|
|
|
|
|
|
|
// Rescan and verify that we see them
|
|
|
|
|
2015-06-18 13:22:45 +00:00
|
|
|
if err := p.Rescan("default"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
m, err = p.Model("default")
|
2014-12-21 08:26:54 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-11-12 23:54:21 +00:00
|
|
|
expected = len(files)*7/8 + 1 // seven out of eight items should remain, plus the foo.TXT
|
2014-12-21 08:26:54 +00:00
|
|
|
if m.LocalFiles != expected {
|
|
|
|
t.Fatalf("Incorrect number of files after second ignore, %d != %d", m.LocalFiles, expected)
|
|
|
|
}
|
|
|
|
}
|