Size detection from output block device no longer working #91

Closed
opened 2024-06-25 22:12:11 +02:00 by bogiord · 2 comments
Image

The manual says

if the input size cannot be calculated, and the output is a block device, then the size of the block device will be used

However, pv has lost this ability in version 1.8.10. It works properly in 1.8.9, but in 1.8.10 there's no ETA and no progress bar when, say, zeroing a drive, just the indicator moving back and forth.

This seems to be a side effect of the changes made for adding the -o option. pv_calc_total_bytes() was modified to use state->control.output_fd instead of STDOUT_FILENO, but that field is not yet initialized when the function is called from main().

The simplest solution would seem to be to move the block that calls pv_state_output_set() higher in main(), right before the block that calls pv_calc_total_size(). The only downside that I can see with this solution is that, if the output is a normal existing file, it will be truncated a bit more eagerly than before. I don't think this matters currently, as I don't see any early returns from main between the new and old positions of that block of code, but if main() is modified in the future to exit early for some reason, this has a higher chance of leaving the user with an error message and a truncated output file (instead of leaving the output file alone in case of a critical error).

What do you think?

The manual says > if the input size cannot be calculated, and the output is a block device, then the size of the block device will be used However, `pv` has lost this ability in version 1.8.10. It works properly in 1.8.9, but in 1.8.10 there's no ETA and no progress bar when, say, zeroing a drive, just the indicator moving back and forth. This seems to be a side effect of the changes made for adding the `-o` option. `pv_calc_total_bytes()` was modified to use `state->control.output_fd` instead of `STDOUT_FILENO`, but that field is not yet initialized when the function is called from `main()`. The simplest solution would seem to be to move the block that calls `pv_state_output_set()` higher in `main()`, right before the block that calls `pv_calc_total_size()`. The only downside that I can see with this solution is that, if the output is a normal existing file, it will be truncated a bit more eagerly than before. I don't think this matters currently, as I don't see any early returns from main between the new and old positions of that block of code, but if `main()` is modified in the future to exit early for some reason, this has a higher chance of leaving the user with an error message and a truncated output file (instead of leaving the output file alone in case of a critical error). What do you think?
Image
Owner

I've not looked at the code yet regarding this, but what you propose certainly sounds like the way to go. Thanks!

I've not looked at the code yet regarding this, but what you propose certainly sounds like the way to go. Thanks!
Image
Owner

A fix has been committed which will be in the next release. Thanks again for reporting this, and your very helpful analysis.

A fix has been committed which will be in the next release. Thanks again for reporting this, and your very helpful analysis.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ivarch/pv#91
No description provided.