go-rsync-close.diff

· erock's pastes · raw

expires: 2024-10-06

 1diff --git a/rsyncsender/sender.go b/rsyncsender/sender.go
 2index 292b92a..5babaf1 100644
 3--- a/rsyncsender/sender.go
 4+++ b/rsyncsender/sender.go
 5@@ -141,6 +141,7 @@ func (st *sendTransfer) sendFile(fileIndex int32, fl *utils.SenderFile) error {
 6 	const chunkSize = 32 * 1024
 7 
 8 	fi, f, err := st.filesystem.Read(fl)
 9+	defer f.Close()
10 	if err != nil {
11 		return err
12 	}
13diff --git a/utils/fs.go b/utils/fs.go
14index f129817..f446f81 100644
15--- a/utils/fs.go
16+++ b/utils/fs.go
17@@ -5,10 +5,15 @@ import (
18 	"os"
19 )
20 
21+type ReaderAtCloser interface {
22+	io.ReaderAt
23+	io.Closer
24+}
25+
26 // File System: need to handle all type of files: regular, folder, symlink, etc
27 type FS interface {
28 	Put(*ReceiverFile) (int64, error)
29 	Skip(*ReceiverFile) bool
30 	List(string) ([]os.FileInfo, error)
31-	Read(*SenderFile) (os.FileInfo, io.ReaderAt, error)
32+	Read(*SenderFile) (os.FileInfo, ReaderAtCloser, error)
33 }