bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about exception throwing and ped_device_write.


From: Andrew Clausen
Subject: Re: question about exception throwing and ped_device_write.
Date: Tue, 4 Nov 2003 23:16:32 +1100
User-agent: Mutt/1.5.4i

On Tue, Nov 04, 2003 at 01:00:46PM +0100, Sven Luther wrote:
> > I don't think you should offer the option of "Ignore"... either "Fix"
> > or "Cancel".  There is no reason not to fix, and you'll probably
> > end up asking the user a dozen times.
> 
> Ignore is nice in case of not wanting to touch the media, but still go
> ahead to see if the resulting partition table makes sense or something
> such. Ideally there would be an option to dump the block or something
> such to make a more informed decision on how to answer.

I guess so... as long as you don't ask the user 10 times to ignore.

> > > What am i supposed to do if the ped_device_write (dev, blk, block, 1);
> > > fails ? In this case something is seriously wrong, and i should raise a
> > > PED_EXCEPTION_FATAL ?
> > 
> > Fatal is when Parted destroyed something, or similar, IMHO.
> 
> Ah, ok, so i could use it for when i fail to write back some of the partition
> blocks (containing the individual partition entries). In this case, the
> partition table is messed up.

It isn't unusable though, is it?

> That said, failing to write back the individual blocks we read should
> hardly happen.
> 
> > It's just an error... I'd do:
> > 
> >     if (!ped_device_write (dev, blk, block, 1))
> >             return 0;
> 
> And thus failing silently.

No.  ped_device_write() will tell the user.

> I don't like that, the user deserves to know when something he wants
> to do failed.

Agreed.

> Another question in the same vein. When some action failed (like
> allocating memory for the blocks, reading or writing them), i throw an
> exception with only the information about this in it, and provide only
> the Cancel option. Would it not make better sense to provide only the Ok
> or something such option instead ?

I don't think so.  I think "cancel" tells the user that the operation
is not going to finish... that Parted has no way of working around it.

> > In summary, I think you should structure this as:
> > 
> >     if (checksum(blk)) {
> >             if (ped_exception_throw(..., "Doesn't match")) {
> >                     add_checksum(blk);
> >                     if (!ped_device_write(..., blk))
> >                             return 0;
> >             }
> >     }
> 
> Mmm, i still prefer the explicit return value handling.

I should have written:

                if (ped_exception_throw() == PED_EXCEPTION_FIX)
                        ...

Anyway, I think a switch statement is very verbose.

Cheers,
Andrew





reply via email to

[Prev in Thread] Current Thread [Next in Thread]