[Libguestfs] [PATCH] Target::LibVirt: Don't truncate a volume when opening it

Matthew Booth mbooth at redhat.com
Wed Apr 7 11:59:54 UTC 2010


On 07/04/10 12:07, Daniel P. Berrange wrote:
> On Wed, Apr 07, 2010 at 12:05:37PM +0100, Matthew Booth wrote:
>> perl's '>' open mode truncates by default, and will create a new file if
>> necessary. We don't want to truncate an existing volume when writing to it, and
>> it's an error if the volume doesn't already exist. Use sysopen to be explicit
>> about this.
>> ---
>>  lib/Sys/VirtV2V/Target/LibVirt.pm |    6 +++++-
>>  1 files changed, 5 insertions(+), 1 deletions(-)
>>
>> diff --git a/lib/Sys/VirtV2V/Target/LibVirt.pm b/lib/Sys/VirtV2V/Target/LibVirt.pm
>> index c8802ac..99a1ad2 100644
>> --- a/lib/Sys/VirtV2V/Target/LibVirt.pm
>> +++ b/lib/Sys/VirtV2V/Target/LibVirt.pm
>> @@ -20,6 +20,8 @@ use warnings;
>>  
>>  package Sys::VirtV2V::Target::LibVirt::Vol;
>>  
>> +use POSIX;
>> +
>>  use Sys::VirtV2V::UserMessage qw(user_message);
>>  
>>  sub _new
>> @@ -106,7 +108,9 @@ sub open
>>      my $self = shift;
>>  
>>      my $path = $self->get_path();
>> -    open(my $fd, '>', $path)
>> +
>> +    # We want to open the existing volume without truncating it
>> +    sysopen(my $fd, $path, O_WRONLY)
> 
> NB There's no need to switch to sysopen. You can use '>>' instead of '>' if you
> want to append instead of truncate

I need to write from the beginning, not append.

Matt
-- 
Matthew Booth, RHCA, RHCSS
Red Hat Engineering, Virtualisation Team

M:       +44 (0)7977 267231
GPG ID:  D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490




More information about the Libguestfs mailing list