Fix ntfs resize progress tracker matching spurious text (#760709)

When the ntfs resize operation had almost completed, percentage complete
was >= 99.9%, the progress tracker was passing 0.04 (4%) to the progress
bar.  After reading the next chunk of output from the ntfsresize command
the last line contained this text:
    "  4)  set the bootable flag for the partit"

End of the ntfsresize command output for context:
    Relocating needed data ...
    100.00 percent completed
    Updating $BadClust file ...
    Updating $Bitmap file ...
    Updating Boot record ...
    Syncing device ...
    Successfully resized NTFS on device '/dev/sdd4'.
    You can go on to shrink the device for example with Linux fdisk.
    IMPORTANT: When recreating the partition, make sure that you
      1)  create it at the same disk sector (use sector as the unit!)
      2)  create it with the same partition type (usually 7, HPFS/NTFS)
      3)  do not make it smaller than the new NTFS filesystem size
      4)  set the bootable flag for the partition if it existed before
    Otherwise you won't be able to access NTFS or can't boot from the disk!
    If you make a mistake and don't have a partition table backup then you
    can recover the partition table by TestDisk or Parted's rescue mode.

This was occurring because *scanf() can't actually report failure to
match fixed text after conversion of the last variable.  See code
comment in ntfs::resize_progress() for more details.  Fix by using
.find() instead to match the required "percent completed" explicit text
of the progress information when it appears on the last line.

Bug 760709 - Add progress bars to XFS and EXT2/3/4 file system specific
             copy methods
This commit is contained in:
Mike Fleetwood 2016-01-18 15:59:51 +00:00 committed by Curtis Gedak
parent 9f7a38e6b3
commit af0ed90d49
1 changed files with 10 additions and 1 deletions

View File

@ -270,8 +270,17 @@ void ntfs::resize_progress( OperationDetail *operationdetail )
ProgressBar & progressbar = operationdetail->get_progressbar();
Glib::ustring line = Utils::last_line( output );
// Text progress on the LAST LINE looks like " 15.24 percent completed"
// NOTE:
// Specifying text to match following the last converted variable in *scanf() is
// ineffective because it reports the number of successfully converted variables
// and has no way to indicate following text didn't match. Specifically:
// sscanf( "%f percent completed", &percent )
// will return 1 after successfully converting percent variable as 4 given this
// line from the important information at the end of the ntfsresize output:
// " 4) set the bootable flag for the partit"
// Definitely not progress information.
float percent;
if ( sscanf( line.c_str(), "%f percent completed", &percent ) == 1 )
if ( line.find( "percent completed" ) != line.npos && sscanf( line.c_str(), "%f", &percent ) == 1 )
{
if ( ! progressbar.running() )
progressbar.start( 100.0 );