diff options
| -rw-r--r-- | main_test.go | 33 | ||||
| -rw-r--r-- | pathfs_frontend/file.go | 3 | 
2 files changed, 35 insertions, 1 deletions
| diff --git a/main_test.go b/main_test.go index 8d216ac..4f51d00 100644 --- a/main_test.go +++ b/main_test.go @@ -1,6 +1,7 @@  package main  import ( +	"bytes"  	"crypto/md5"  	"encoding/hex"  	"fmt" @@ -145,6 +146,38 @@ func TestTruncate(t *testing.T) {  	}  } +func TestAppend(t *testing.T) { +	fn := plainDir + "append" +	file, err := os.Create(fn) +	if err != nil { +		t.FailNow() +	} +	data := []byte("testdata123456789") // length 17 +	var buf bytes.Buffer +	var hashWant string +	for i := 0; i <= 500; i++ { +		file.Write(data) +		buf.Write(data) +		bin := md5.Sum(buf.Bytes()) +		hashWant = hex.EncodeToString(bin[:]) +		hashActual := md5fn(fn) +		if hashWant != hashActual { +			t.FailNow() +		} +	} + +	// Overwrite with the same data +	// Hash must stay the same +	file.Seek(0, 0) +	for i := 0; i <= 500; i++ { +		file.Write(data) +		hashActual := md5fn(fn) +		if hashWant != hashActual { +			t.FailNow() +		} +	} +} +  func BenchmarkStreamWrite(t *testing.B) {  	buf := make([]byte, 1024*1024)  	t.SetBytes(int64(len(buf))) diff --git a/pathfs_frontend/file.go b/pathfs_frontend/file.go index fe346b6..a4ed30b 100644 --- a/pathfs_frontend/file.go +++ b/pathfs_frontend/file.go @@ -70,11 +70,12 @@ func (f *file) doRead(off uint64, length uint64) ([]byte, fuse.Status) {  		cryptfs.Warn.Printf("read: ReadAt: %s\n", err.Error())  		return nil, fuse.ToStatus(err)  	} -	cryptfs.Debug.Printf("ReadAt length=%d offset=%d -> n=%d len=%d\n", alignedLength, alignedOffset, n, len(ciphertext)) +	cryptfs.Debug.Printf("ReadAt offset=%d length=%d -> n=%d len=%d\n", alignedLength, alignedOffset, n, len(ciphertext))  	// Decrypt it  	plaintext, err := f.cfs.DecryptBlocks(ciphertext)  	if err != nil { +		cryptfs.Warn.Printf("Corrupt block at offset=%d\n", off + uint64(len(plaintext)))  		cryptfs.Warn.Printf("doRead: returning IO error\n")  		return nil, fuse.EIO  	} | 
