From 230fb083fc0d91914064911b344c7db830f17765 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 12 Dec 2017 11:30:20 +0100 Subject: [PATCH] lib/model: Remove dead code (*sharedPullerState).sourceFile --- lib/model/sharedpullerstate.go | 20 ----------- lib/model/sharedpullerstate_test.go | 52 ----------------------------- 2 files changed, 72 deletions(-) diff --git a/lib/model/sharedpullerstate.go b/lib/model/sharedpullerstate.go index dd57e9dfe..ce5ae5f8b 100644 --- a/lib/model/sharedpullerstate.go +++ b/lib/model/sharedpullerstate.go @@ -169,26 +169,6 @@ func (s *sharedPullerState) tempFile() (io.WriterAt, error) { 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 // sharedPullerState as failed. Is a no-op when called on an already failed state. func (s *sharedPullerState) fail(context string, err error) { diff --git a/lib/model/sharedpullerstate_test.go b/lib/model/sharedpullerstate_test.go index c375324d2..ac01a659c 100644 --- a/lib/model/sharedpullerstate_test.go +++ b/lib/model/sharedpullerstate_test.go @@ -14,58 +14,6 @@ import ( "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 func TestReadOnlyDir(t *testing.T) { // Create a read only directory, clean it up afterwards.