mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-24 15:38:27 +00:00
lib/model: Remove dead code (*sharedPullerState).sourceFile
This commit is contained in:
parent
509ae5e2d9
commit
230fb083fc
@ -169,26 +169,6 @@ func (s *sharedPullerState) tempFile() (io.WriterAt, error) {
|
|||||||
return lockedWriterAt{&s.mut, s.fd}, nil
|
return lockedWriterAt{&s.mut, s.fd}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// sourceFile opens the existing source file for reading
|
|
||||||
func (s *sharedPullerState) sourceFile() (fs.File, error) {
|
|
||||||
s.mut.Lock()
|
|
||||||
defer s.mut.Unlock()
|
|
||||||
|
|
||||||
// If we've already hit an error, return early
|
|
||||||
if s.err != nil {
|
|
||||||
return nil, s.err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to open the existing file
|
|
||||||
fd, err := s.fs.Open(s.realName)
|
|
||||||
if err != nil {
|
|
||||||
s.failLocked("src open", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return fd, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// fail sets the error on the puller state compose of error, and marks the
|
// fail sets the error on the puller state compose of error, and marks the
|
||||||
// sharedPullerState as failed. Is a no-op when called on an already failed state.
|
// sharedPullerState as failed. Is a no-op when called on an already failed state.
|
||||||
func (s *sharedPullerState) fail(context string, err error) {
|
func (s *sharedPullerState) fail(context string, err error) {
|
||||||
|
@ -14,58 +14,6 @@ import (
|
|||||||
"github.com/syncthing/syncthing/lib/sync"
|
"github.com/syncthing/syncthing/lib/sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSourceFileOK(t *testing.T) {
|
|
||||||
s := sharedPullerState{
|
|
||||||
fs: fs.NewFilesystem(fs.FilesystemTypeBasic, "testdata"),
|
|
||||||
realName: "foo",
|
|
||||||
mut: sync.NewRWMutex(),
|
|
||||||
}
|
|
||||||
|
|
||||||
fd, err := s.sourceFile()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if fd == nil {
|
|
||||||
t.Fatal("Unexpected nil fd")
|
|
||||||
}
|
|
||||||
|
|
||||||
bs := make([]byte, 6)
|
|
||||||
n, err := fd.Read(bs)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if n != len(bs) {
|
|
||||||
t.Fatalf("Wrong read length %d != %d", n, len(bs))
|
|
||||||
}
|
|
||||||
if string(bs) != "foobar" {
|
|
||||||
t.Fatalf("Wrong contents %s != foobar", string(bs))
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.failed(); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSourceFileBad(t *testing.T) {
|
|
||||||
s := sharedPullerState{
|
|
||||||
fs: fs.NewFilesystem(fs.FilesystemTypeBasic, "testdata"),
|
|
||||||
realName: "nonexistent",
|
|
||||||
mut: sync.NewRWMutex(),
|
|
||||||
}
|
|
||||||
|
|
||||||
fd, err := s.sourceFile()
|
|
||||||
if err == nil {
|
|
||||||
t.Fatal("Unexpected nil error")
|
|
||||||
}
|
|
||||||
if fd != nil {
|
|
||||||
t.Fatal("Unexpected non-nil fd")
|
|
||||||
}
|
|
||||||
if err := s.failed(); err == nil {
|
|
||||||
t.Fatal("Unexpected nil failed()")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test creating temporary file inside read-only directory
|
// Test creating temporary file inside read-only directory
|
||||||
func TestReadOnlyDir(t *testing.T) {
|
func TestReadOnlyDir(t *testing.T) {
|
||||||
// Create a read only directory, clean it up afterwards.
|
// Create a read only directory, clean it up afterwards.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user