IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13269


Ignore:
Timestamp:
May 4, 2007, 3:41:29 PM (19 years ago)
Author:
jhoblitt
Message:

add File::ExtAttr support

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/Build.PL

    r13257 r13269  
    9292        'Net::Server::Daemonize'=> '0.05',
    9393        'Sys::Statistics::Linux::DiskUsage' => '0.02',
    94 
     94        'File::ExtAttr'         => '1.03',
    9595    },
    9696    build_requires      => {
  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r13251 r13269  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.38 2007-05-04 23:36:46 jhoblitt Exp $
     3# $Id: Server.pm,v 1.39 2007-05-05 01:41:29 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    208208    my $filename = $key;
    209209    # mange '/'s into ':'
    210     $key =~ s|/|:|g;
    211     my $uri = URI::file->new("$vol_path/$key.$ins_id");
     210    $filename =~ s|/|:|g;
     211    my $uri = URI::file->new("$vol_path/$filename.$ins_id");
    212212    $log->debug("generated uri $uri");
    213213
    214214    # TODO add some stuff here to retry if unsucessful
    215215    eval {
    216         _create_empty_file($uri->file);
     216        _create_empty_file($uri->file, $key);
    217217    };
    218218    if ($@) {
     
    361361    }
    362362
    363     my $uri = URI::file->new("$vol_path/$key.$ins_id");
     363    my $filename = $key;
     364    # mange '/'s into ':'
     365    $filename =~ s|/|:|g;
     366    my $uri = URI::file->new("$vol_path/$filename.$ins_id");
    364367    $log->debug("generated uri $uri");
    365368
    366369    # TODO add some stuff here to retry if unsucessful
    367370    eval {
    368         _create_empty_file($uri->file);
     371        _create_empty_file($uri->file, $key);
    369372    };
    370373    if ($@) {
  • trunk/Nebulous-Server/t/03_server_create_object.t

    r13206 r13269  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 03_server_create_object.t,v 1.17 2007-05-04 00:43:44 jhoblitt Exp $
     5# $Id: 03_server_create_object.t,v 1.18 2007-05-05 01:41:29 jhoblitt Exp $
    66
    77use strict;
    88use warnings FATAL => qw( all );
    99
    10 use Test::More tests => 22;
     10use Test::More tests => 28;
    1111
    1212use lib qw( ./t ./lib );
     
    1717use Test::URI;
    1818use URI::Split qw( uri_split );
     19use File::ExtAttr qw( getfattr );
    1920
    2021my $neb = Nebulous::Server->new(
     
    3334    ok(-e $path, "file exists");
    3435    uri_scheme_ok($uri, 'file');
     36
     37    is(getfattr($path, 'nebulous_key'), 'foo', 'nebulous_key xattr');
    3538}
    3639
     
    4447    ok(-e $path, "file exists");
    4548    uri_scheme_ok($uri, 'file');
     49
     50    is(getfattr($path, 'nebulous_key'), '/foo', 'nebulous_key xattr');
    4651}
    4752
     
    5560    ok(-e $path, "file exists");
    5661    uri_scheme_ok($uri, 'file');
     62
     63    is(getfattr($path, 'nebulous_key'), '/foo/', 'nebulous_key xattr');
    5764}
    5865
     
    6673    ok(-e $path, "file exists");
    6774    uri_scheme_ok($uri, 'file');
     75
     76    is(getfattr($path, 'nebulous_key'), 'foo/', 'nebulous_key xattr');
    6877}
    6978
     
    7786    ok(-e $path, "file exists");
    7887    uri_scheme_ok($uri, 'file');
     88
     89    is(getfattr($path, 'nebulous_key'), 'foo/bar', 'nebulous_key xattr');
    7990}
    8091
     
    8899    ok(-e $path, "file exists");
    89100    uri_scheme_ok($uri, 'file');
     101
     102    is(getfattr($path, 'nebulous_key'), '/foo/bar', 'nebulous_key xattr');
    90103}
    91104
  • trunk/Nebulous/Build.PL

    r13257 r13269  
    9292        'Net::Server::Daemonize'=> '0.05',
    9393        'Sys::Statistics::Linux::DiskUsage' => '0.02',
    94 
     94        'File::ExtAttr'         => '1.03',
    9595    },
    9696    build_requires      => {
  • trunk/Nebulous/lib/Nebulous/Server.pm

    r13251 r13269  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.38 2007-05-04 23:36:46 jhoblitt Exp $
     3# $Id: Server.pm,v 1.39 2007-05-05 01:41:29 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    208208    my $filename = $key;
    209209    # mange '/'s into ':'
    210     $key =~ s|/|:|g;
    211     my $uri = URI::file->new("$vol_path/$key.$ins_id");
     210    $filename =~ s|/|:|g;
     211    my $uri = URI::file->new("$vol_path/$filename.$ins_id");
    212212    $log->debug("generated uri $uri");
    213213
    214214    # TODO add some stuff here to retry if unsucessful
    215215    eval {
    216         _create_empty_file($uri->file);
     216        _create_empty_file($uri->file, $key);
    217217    };
    218218    if ($@) {
     
    361361    }
    362362
    363     my $uri = URI::file->new("$vol_path/$key.$ins_id");
     363    my $filename = $key;
     364    # mange '/'s into ':'
     365    $filename =~ s|/|:|g;
     366    my $uri = URI::file->new("$vol_path/$filename.$ins_id");
    364367    $log->debug("generated uri $uri");
    365368
    366369    # TODO add some stuff here to retry if unsucessful
    367370    eval {
    368         _create_empty_file($uri->file);
     371        _create_empty_file($uri->file, $key);
    369372    };
    370373    if ($@) {
  • trunk/Nebulous/lib/Nebulous/Util.pm

    r12961 r13269  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Util.pm,v 1.4 2007-04-23 20:45:08 jhoblitt Exp $
     3# $Id: Util.pm,v 1.5 2007-05-05 01:41:29 jhoblitt Exp $
    44
    55package Nebulous::Util;
     
    1212use base qw( Exporter );
    1313
     14use File::ExtAttr qw( setfattr );
    1415use Log::Log4perl qw( :levels );
     16use URI::file;
    1517use URI;
    16 use URI::file;
    1718
    1819my @symbols = qw(
     
    7980}
    8081
    81 sub _create_empty_file {
    82     my $path = shift;
     82sub _create_empty_file
     83{
     84    my ($path, $key) = @_;
    8385
    8486    # perl's open() can't do an O_CREAT | O_EXCL
    85     if ( -e $path ) {
    86         die "file $path already exists";
    87     }
     87    die "file $path already exists" if (-e $path);
    8888
    8989    my $fh;
    90     unless ( open( $fh, '>', $path ) ) {
    91         die "can not open $path: $!";
    92     }
     90    die "can not open $path: $!"
     91        unless (open($fh, '>', $path));
    9392
    94     unless ( close( $fh ) ) {
    95         die "can not close $path: $!";
    96     }
     93    die "can not close $path: $!"
     94        unless (close($fh));
    9795
    98     unless ( chmod 0664, $path ) {
    99         die "can not chmod $path: $!";
    100     }
     96    die "can not chmod $path: $!"
     97        unless (chmod 0664, $path);
     98
     99    die "can not set xattr on $path: $!"
     100        unless (setfattr($path, 'nebulous_key', $key));
    101101
    102102    return $path;
  • trunk/Nebulous/t/03_server_create_object.t

    r13206 r13269  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 03_server_create_object.t,v 1.17 2007-05-04 00:43:44 jhoblitt Exp $
     5# $Id: 03_server_create_object.t,v 1.18 2007-05-05 01:41:29 jhoblitt Exp $
    66
    77use strict;
    88use warnings FATAL => qw( all );
    99
    10 use Test::More tests => 22;
     10use Test::More tests => 28;
    1111
    1212use lib qw( ./t ./lib );
     
    1717use Test::URI;
    1818use URI::Split qw( uri_split );
     19use File::ExtAttr qw( getfattr );
    1920
    2021my $neb = Nebulous::Server->new(
     
    3334    ok(-e $path, "file exists");
    3435    uri_scheme_ok($uri, 'file');
     36
     37    is(getfattr($path, 'nebulous_key'), 'foo', 'nebulous_key xattr');
    3538}
    3639
     
    4447    ok(-e $path, "file exists");
    4548    uri_scheme_ok($uri, 'file');
     49
     50    is(getfattr($path, 'nebulous_key'), '/foo', 'nebulous_key xattr');
    4651}
    4752
     
    5560    ok(-e $path, "file exists");
    5661    uri_scheme_ok($uri, 'file');
     62
     63    is(getfattr($path, 'nebulous_key'), '/foo/', 'nebulous_key xattr');
    5764}
    5865
     
    6673    ok(-e $path, "file exists");
    6774    uri_scheme_ok($uri, 'file');
     75
     76    is(getfattr($path, 'nebulous_key'), 'foo/', 'nebulous_key xattr');
    6877}
    6978
     
    7786    ok(-e $path, "file exists");
    7887    uri_scheme_ok($uri, 'file');
     88
     89    is(getfattr($path, 'nebulous_key'), 'foo/bar', 'nebulous_key xattr');
    7990}
    8091
     
    8899    ok(-e $path, "file exists");
    89100    uri_scheme_ok($uri, 'file');
     101
     102    is(getfattr($path, 'nebulous_key'), '/foo/bar', 'nebulous_key xattr');
    90103}
    91104
Note: See TracChangeset for help on using the changeset viewer.