IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17448


Ignore:
Timestamp:
Apr 17, 2008, 2:08:23 PM (18 years ago)
Author:
jhoblitt
Message:

add Nebulous::Client::open() '>' (truncate) mode

Location:
trunk/Nebulous
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous/Changes

    r17081 r17448  
    11Revision history for Nebulous
     2
     30.08
     4    - add Nebulous::Client::open() '>' (truncate) mode
    25
    360.07
  • trunk/Nebulous/lib/Nebulous/Client.pm

    r17081 r17448  
    11# Copyright (c) 2004-2008  Joshua Hoblitt
    22#
    3 # $Id: Client.pm,v 1.41 2008-03-21 01:53:36 jhoblitt Exp $
     3# $Id: Client.pm,v 1.42 2008-04-18 00:08:23 jhoblitt Exp $
    44
    55package Nebulous::Client;
     
    503503            type        => SCALAR,
    504504            callbacks   => {
    505                 'is read or write' => sub { $_[0] =~ /^(?:read|write)$/ },
     505                'is read or write' => sub { $_[0] =~ /^(?:read|write|>)$/ },
    506506            },
    507507        },
     
    538538    }
    539539
    540     if ( $type eq 'write' ) {
     540    if ( $type eq 'write' or $type eq '>' ) {
    541541        my $num_instances = scalar @$locations;
    542542
     
    551551        };
    552552        $log->logdie( $@ ) if $@;
     553
     554        if ($type eq '>') {
     555            truncate($fh, 0) or $log->logdie("truncate failed: $!");
     556        }
    553557    } elsif ( $type eq 'read' ) {
    554558        eval {
  • trunk/Nebulous/lib/Nebulous/Client.pod

    r17081 r17448  
    285285=item * type
    286286
    287 The type of lock to acquire.  Either C<read> or C<write>.
     287The type of lock to acquire.  One of [C<read>, C<write>, C<>>].
     288
     289C<>> truncates any pre-existing files to zero length and opens it for writing.
    288290
    289291=back
  • trunk/Nebulous/t/58_client_open.t

    r5667 r17448  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 58_client_open.t,v 1.1 2005-12-03 02:52:31 jhoblitt Exp $
     5# $Id: 58_client_open.t,v 1.2 2008-04-18 00:08:23 jhoblitt Exp $
    66
    77use strict;
     
    1010use Apache::Test qw( -withtestmore );
    1111
    12 plan tests => 8;
     12plan tests => 10;
    1313
    1414use lib qw( ./t ./lib );
     
    1717use Nebulous::Util qw( :standard );
    1818use Test::Nebulous;
     19use File::stat;
    1920
    2021my $hostport = Apache::Test->config->{ 'hostport' };
     
    6869Test::Nebulous->setup;
    6970
     71# truncation test
     72{
     73    my $neb = Nebulous::Client->new(
     74        proxy => "http://$hostport/nebulous",
     75    );
     76    my $fh = $neb->open( "foo", 'write' );
     77    print $fh "foobar";
     78    close $fh;
     79
     80    $fh = $neb->open( "foo", '>' );
     81    ok($fh, "open in trucate mode" );
     82    my $sb = stat($fh);
     83    is($sb->size, 0, "file was truncated");
     84}
     85
     86Test::Nebulous->setup;
     87
    7088{
    7189    my $neb = Nebulous::Client->new(
Note: See TracChangeset for help on using the changeset viewer.