Преглед на файлове

Synchronize zero sized files (fixes #44)

Jakob Borg преди 12 години
родител
ревизия
618c376e18
променени са 7 файла, в които са добавени 30 реда и са изтрити 8 реда
  1. 10 5
      integration/test.sh
  2. 9 0
      model/blocks.go
  3. 3 2
      model/blocks_test.go
  4. 6 0
      model/model_test.go
  5. 0 0
      model/testdata/empty
  6. 1 1
      model/walk.go
  7. 1 0
      model/walk_test.go

+ 10 - 5
integration/test.sh

@@ -9,11 +9,11 @@ go build genfiles.go
 go build md5r.go
 
 echo "Setting up (keys)..."
-i1=$(syncthing -c conf-1 2>&1 | awk '/My ID/ {print $6}')
+i1=$(syncthing --home conf-1 2>&1 | awk '/My ID/ {print $7}')
 echo $i1
-i2=$(syncthing -c conf-2 2>&1 | awk '/My ID/ {print $6}')
+i2=$(syncthing --home conf-2 2>&1 | awk '/My ID/ {print $7}')
 echo $i2
-i3=$(syncthing -c conf-3 2>&1 | awk '/My ID/ {print $6}')
+i3=$(syncthing --home conf-3 2>&1 | awk '/My ID/ {print $7}')
 echo $i3
 
 echo "Setting up (files)..."
@@ -26,11 +26,16 @@ dir = $p/files-$i
 $i1 = 127.0.0.1:22001
 $i2 = 127.0.0.1:22002
 $i3 = 127.0.0.1:22003
+
+[settings]
+gui-enabled = false
+listen-address = :2200$i
 EOT
 
 	mkdir files-$i
 	pushd files-$i >/dev/null
-	../genfiles -maxexp 21 -files 4000
+	../genfiles -maxexp 21 -files 400
+	touch empty-$i
 	../md5r > ../md5-$i
 	popd >/dev/null
 done
@@ -38,7 +43,7 @@ done
 echo "Starting..."
 for i in 1 2 3 ; do
 	sleep 1
-	syncthing -c conf-$i --no-gui -l :2200$i $extraopts &
+	syncthing --home conf-$i $extraopts &
 done
 
 cat md5-* | sort > md5-tot

+ 9 - 0
model/blocks.go

@@ -37,6 +37,15 @@ func Blocks(r io.Reader, blocksize int) ([]Block, error) {
 		offset += int64(n)
 	}
 
+	if len(blocks) == 0 {
+		// Empty file
+		blocks = append(blocks, Block{
+			Offset: 0,
+			Size:   0,
+			Hash:   []uint8{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55},
+		})
+	}
+
 	return blocks, nil
 }
 

+ 3 - 2
model/blocks_test.go

@@ -11,7 +11,8 @@ var blocksTestData = []struct {
 	blocksize int
 	hash      []string
 }{
-	{[]byte(""), 1024, []string{}},
+	{[]byte(""), 1024, []string{
+		"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}},
 	{[]byte("contents"), 1024, []string{
 		"d1b2a59fbea7e20077af9f91b27e95e865061b270be03ff539ab3b73587882e8"}},
 	{[]byte("contents"), 9, []string{
@@ -86,7 +87,7 @@ var diffTestData = []struct {
 	{"contents", "cantents", 3, []Block{{0, 3, nil}}},
 	{"contents", "contants", 3, []Block{{3, 3, nil}}},
 	{"contents", "cantants", 3, []Block{{0, 3, nil}, {3, 3, nil}}},
-	{"contents", "", 3, nil},
+	{"contents", "", 3, []Block{{0, 0, nil}}},
 	{"", "contents", 3, []Block{{0, 3, nil}, {3, 3, nil}, {6, 2, nil}}},
 	{"con", "contents", 3, []Block{{3, 3, nil}, {6, 2, nil}}},
 	{"contents", "con", 3, nil},

+ 6 - 0
model/model_test.go

@@ -34,6 +34,12 @@ var testDataExpected = map[string]File{
 		Modified: 0,
 		Blocks:   []Block{{Offset: 0x0, Size: 0x7, Hash: []uint8{0xae, 0xc0, 0x70, 0x64, 0x5f, 0xe5, 0x3e, 0xe3, 0xb3, 0x76, 0x30, 0x59, 0x37, 0x61, 0x34, 0xf0, 0x58, 0xcc, 0x33, 0x72, 0x47, 0xc9, 0x78, 0xad, 0xd1, 0x78, 0xb6, 0xcc, 0xdf, 0xb0, 0x1, 0x9f}}},
 	},
+	"empty": File{
+		Name:     "empty",
+		Flags:    0,
+		Modified: 0,
+		Blocks:   []Block{{Offset: 0x0, Size: 0x0, Hash: []uint8{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}}},
+	},
 	"bar": File{
 		Name:     "bar",
 		Flags:    0,

+ 0 - 0
model/testdata/empty


+ 1 - 1
model/walk.go

@@ -32,7 +32,7 @@ func (f File) Size() (bytes int) {
 }
 
 func (f File) String() string {
-	return fmt.Sprintf("File{Name:%q, Flags:0x%x, Modified:%d, Version:%d:, NumBlocks:%d}",
+	return fmt.Sprintf("File{Name:%q, Flags:0x%x, Modified:%d, Version:%d, NumBlocks:%d}",
 		f.Name, f.Flags, f.Modified, f.Version, len(f.Blocks))
 }
 

+ 1 - 0
model/walk_test.go

@@ -13,6 +13,7 @@ var testdata = []struct {
 	hash string
 }{
 	{"bar", 10, "2f72cc11a6fcd0271ecef8c61056ee1eb1243be3805bf9a9df98f92f7636b05c"},
+	{"empty", 0, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
 	{"foo", 7, "aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f"},
 }