Skip to content

Commit 670bbe5

Browse files
committed
reafactor: fix some review points like file.Stream function
1 parent be6c354 commit 670bbe5

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ NAME = CatchMyFile
77

88
TARGET = pkg/**/*.go
99

10-
#@dupl -t 30 $(TARGET)
11-
1210
format:
1311
@gofmt -s -w $(TARGET)
1412

pkg/file/file.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func Stream(ctx context.Context, in io.Reader, out io.Writer, onProg OnProgressC
3838
return -1, fmt.Errorf("file stream error: output writer is nil")
3939
}
4040

41+
return stream(ctx, in, out, onProg)
42+
}
43+
44+
func stream(ctx context.Context, in io.Reader, out io.Writer, onProg OnProgressChange) (int, error) {
4145
var transferred int
4246
buf := make([]byte, transferChunkSize)
4347
for {

pkg/transfer/receiver.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ func handleRequest(ctx context.Context, conn net.Conn, store *TransferStore) {
128128
trans.Status = Verifying
129129
store.Update(id, trans)
130130

131-
f, err := file.Open(trans.LocalFilePath, file.OPEN_READ)
131+
verifyFile(ctx, trans, rcvSize, id, store)
132+
}
133+
134+
func verifyFile(ctx context.Context, t *Transfer, rcvSize, id int, store *TransferStore) {
135+
f, err := file.Open(t.LocalFilePath, file.OPEN_READ)
132136
if err != nil {
133137
clog.Error(err)
134138
}
@@ -139,13 +143,13 @@ func handleRequest(ctx context.Context, conn net.Conn, store *TransferStore) {
139143
}
140144
}()
141145

142-
if err = verifyTransfer(ctx, trans, rcvSize, f); err != nil {
143-
trans.SetError(err)
146+
if err = verifyTransfer(ctx, t, rcvSize, f); err != nil {
147+
t.SetError(err)
144148
} else {
145-
trans.Status = Completed
149+
t.Status = Completed
146150
}
147151

148-
store.Update(id, trans)
152+
store.Update(id, t)
149153
}
150154

151155
// reqDecisionAndWait will add the transfer to the store and wait for confirmation

pkg/transfer/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (tl *TransferList) updateItem(i widget.ListItemID, item fyne.CanvasObject)
122122
if t.Status == Error && t.Error() != nil {
123123
dialog.ShowError(t.Error(), tl.Parent)
124124

125-
//! Realy don't like this
125+
//! Really don't like this
126126
go func() {
127127
t.err = nil
128128
tl.store.Update(i, t)

0 commit comments

Comments
 (0)