-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FileIO usage tweaks [DEVINFRA-640] #429
Changes from 13 commits
ebd1574
7278cb7
36ac5b3
bc4f81a
3503e6c
c66d5eb
6ea9add
02baf5e
813c82b
d6212dd
bf62569
c4df77b
5212be1
135c172
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,8 @@ impl Fileio { | |
return Err(err); | ||
}; | ||
|
||
let mut total_bytes_read = 0; | ||
|
||
loop { | ||
select! { | ||
recv(rx) -> msg => { | ||
|
@@ -97,6 +99,7 @@ impl Fileio { | |
return Err(err.into()); | ||
} | ||
let bytes_read = msg.contents.len(); | ||
total_bytes_read += bytes_read; | ||
on_progress(bytes_read as u64); | ||
if bytes_read != READ_CHUNK_SIZE { | ||
break; | ||
|
@@ -116,13 +119,21 @@ impl Fileio { | |
}, | ||
recv(channel::tick(FILE_IO_TIMEOUT)) -> _ => { | ||
self.link.unregister(key); | ||
bail!("Timed out waiting for file read response. Ensure SBP FILEIO message {} ({}) is enabled.", MsgFileioReadResp::MESSAGE_TYPE, MsgFileioReadResp::MESSAGE_NAME); | ||
bail!("Timed out waiting for file read response. Ensure SBP FILEIO message {} ({}) is enabled.", MsgFileioReadResp::MESSAGE_TYPE, MsgFileioReadResp::MESSAGE_NAME); | ||
} | ||
} | ||
} | ||
|
||
self.link.unregister(key); | ||
Ok(()) | ||
|
||
if total_bytes_read == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's possible to differentiate between whether the file attempting to be read is actually a 0 byte file or if the file read failed here (because the file didn't exist or because the user isn't allowed to read the file). Thinking about this some more, maybe the error message should be more descriptive? Something like "File {} read was 0 bytes long. This could indicate that the file doesn't exist or is not accessible." We should also potentially delete the file locally, as the user will see a 0 bytes file after running this at the moment. What do others think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the more informative message, IMO leaving the file is fine if we have the warning since the remote file could be a zero byte file. |
||
Err(anyhow!( | ||
"File {} read was 0 bytes long. This could indicate that the file doesn't exist or is not accessible.", | ||
path | ||
)) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
|
||
/// Deletes `filename` on the remote device (if it exists) and writes the contents of `data` to the file. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slight change, this will mean you won't be able to do
swift-files 192.168.0.222:/data --list
any longer but IMO makes reading the code slightly easier.