Propagate FS errors on read/write and close files when finished writing

This commit is contained in:
Arsen Musayelyan 2021-12-13 09:58:34 -08:00
parent 27aabdceba
commit 518fe74e96
4 changed files with 11 additions and 6 deletions

View File

@ -69,7 +69,7 @@ func (c *Client) ReadDir(path string) ([]types.FileInfo, error) {
func (c *Client) ReadFile(localPath, remotePath string) (<-chan types.FSTransferProgress, error) {
c.readProgressCh = make(chan types.FSTransferProgress, 5)
err := c.requestNoRes(types.Request{
_, err := c.request(types.Request{
Type: types.ReqTypeFS,
Data: types.ReqDataFS{
Type: types.FSTypeRead,
@ -87,7 +87,7 @@ func (c *Client) ReadFile(localPath, remotePath string) (<-chan types.FSTransfer
func (c *Client) WriteFile(localPath, remotePath string) (<-chan types.FSTransferProgress, error) {
c.writeProgressCh = make(chan types.FSTransferProgress, 5)
err := c.requestNoRes(types.Request{
_, err := c.request(types.Request{
Type: types.ReqTypeFS,
Data: types.ReqDataFS{
Type: types.FSTypeWrite,

2
go.mod
View File

@ -23,7 +23,7 @@ require (
github.com/srwiley/oksvg v0.0.0-20211120171407-1837d6608d8c // indirect
github.com/srwiley/rasterx v0.0.0-20210519020934-456a8d69b780 // indirect
github.com/yuin/goldmark v1.4.4 // indirect
go.arsenm.dev/infinitime v0.0.0-20211212212540-382b1d9556cf
go.arsenm.dev/infinitime v0.0.0-20211213175634-9250d26fdc8c
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect

4
go.sum
View File

@ -447,8 +447,8 @@ github.com/yuin/goldmark v1.3.8/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.4 h1:zNWRjYUW32G9KirMXYHQHVNFkXvMI7LpgNW2AgYAoIs=
github.com/yuin/goldmark v1.4.4/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg=
go.arsenm.dev/infinitime v0.0.0-20211212212540-382b1d9556cf h1:TJhKfJLW9rMOCZnn7j8PJp8Ye4qxRX4HG1oaK0M7gQY=
go.arsenm.dev/infinitime v0.0.0-20211212212540-382b1d9556cf/go.mod h1:xioFSrICUc4ghNJPOMSZjF7nj7QHAFLUJ2qkrSsgFfQ=
go.arsenm.dev/infinitime v0.0.0-20211213175634-9250d26fdc8c h1:cnvVLBNWyBHRhNUI01xKL+gE/2UQ49fFDnvQ5YdMwvQ=
go.arsenm.dev/infinitime v0.0.0-20211213175634-9250d26fdc8c/go.mod h1:xioFSrICUc4ghNJPOMSZjF7nj7QHAFLUJ2qkrSsgFfQ=
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=

View File

@ -582,6 +582,8 @@ func handleConnection(conn net.Conn, dev *infinitime.Device, fs *blefs.FS) {
}
}()
json.NewEncoder(conn).Encode(types.Response{Type: req.Type})
io.Copy(remoteFile, localFile)
json.NewEncoder(conn).Encode(types.Response{
@ -603,12 +605,14 @@ func handleConnection(conn net.Conn, dev *infinitime.Device, fs *blefs.FS) {
connErr(conn, req.Type, err, "Error creating local file")
break
}
defer localFile.Close()
remoteFile, err := fs.Open(reqData.Files[1])
if err != nil {
connErr(conn, req.Type, err, "Error opening remote file")
break
}
defer remoteFile.Close()
go func() {
// For every progress event
@ -626,8 +630,9 @@ func handleConnection(conn net.Conn, dev *infinitime.Device, fs *blefs.FS) {
}
}()
json.NewEncoder(conn).Encode(types.Response{Type: req.Type})
io.Copy(localFile, remoteFile)
localFile.Sync()
json.NewEncoder(conn).Encode(types.Response{
Type: req.Type,