IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13302


Ignore:
Timestamp:
May 7, 2007, 4:27:42 PM (19 years ago)
Author:
jhoblitt
Message:

make filesystem xattr support optional & disabled by default

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/Changes

    r13279 r13302  
    22
    330.05
     4    - make filesystem xattr support optional & disabled by default
    45    - generate instance filenames that leave the "key" at the end so as to not
    56      break a pplications that expect a certain "extension" on the filename
  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r13278 r13302  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.40 2007-05-05 02:59:31 jhoblitt Exp $
     3# $Id: Server.pm,v 1.41 2007-05-08 02:27:42 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    1313
    1414use DBI;
     15use File::ExtAttr qw( setfattr );
    1516use Log::Log4perl;
    1617use Nebulous::Server::Config;
     
    124125    my $self = shift;
    125126
    126     my ($key, $volume) = validate_pos(@_,
     127    my ($key, $vol_name) = validate_pos(@_,
    127128        {
    128129            type        => SCALAR,
     
    143144
    144145    $log->debug( "entered - @_" );
    145 
    146     # Find the storage volume to use.  We are doing this first as there's no
    147     # point in creating a new storage object if we can't allocate a new
    148     # instance. ->_get_storage_volume() throws an exception on failure.
    149     my ($vol_id, $vol_path);
    150     eval {
    151         ($vol_id, $vol_path) = $self->_get_storage_volume($volume);
    152     };
    153     if ($@) {
    154         $log->logdie($@);
    155     }
    156146
    157147    my $ins_id;
     
    206196    # actual on disk file name we can't try to create the file until after
    207197    # we've create both a new storage_storage object and instance.
    208     my $filename = $key;
    209     # mange '/'s into ':'
    210     $filename =~ s|/|:|g;
    211     my $uri = URI::file->new("$vol_path/$ins_id.$filename");
    212     $log->debug("generated uri $uri");
    213198
    214199    # TODO add some stuff here to retry if unsucessful
    215     eval {
    216         _create_empty_file($uri->file, $key);
     200    my ($uri, $vol_id);
     201    eval {
     202        ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name);
    217203    };
    218204    if ($@) {
     
    220206        $log->logdie($@);
    221207    }
     208
     209    $log->debug("created $uri on volume ID: $vol_id");
    222210
    223211    eval {
     
    225213            my $query = $db->prepare_cached( $sql->update_instance_uri );
    226214            # vol_id, uri, ins_id
    227             $query->execute($vol_id, $uri, $ins_id);
     215            $query->execute($vol_id, "$uri", $ins_id);
    228216        }
    229217
    230218        $db->commit;
     219        $log->debug("commit");
    231220    };
    232221    if ($@) {
     
    315304
    316305    $log->debug("entered - @_");
    317 
    318     my ($vol_id, $vol_path);
    319     eval {
    320         ($vol_id, $vol_path) = $self->_get_storage_volume($vol_name);
    321     };
    322     if ($@) {
    323         $log->logdie($@);
    324     }
    325306
    326307    my $ins_id;
     
    361342    }
    362343
    363     my $filename = $key;
    364     # mange '/'s into ':'
    365     $filename =~ s|/|:|g;
    366     my $uri = URI::file->new("$vol_path/$ins_id.$filename");
    367     $log->debug("generated uri $uri");
     344    # Unfortunately, since we want to use the instance row's ID as part of the
     345    # actual on disk file name we can't try to create the file until after
     346    # we've create both a new storage_storage object and instance.
    368347
    369348    # TODO add some stuff here to retry if unsucessful
    370     eval {
    371         _create_empty_file($uri->file, $key);
     349    my ($uri, $vol_id);
     350    eval {
     351        ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name);
    372352    };
    373353    if ($@) {
     
    11071087    my $name = shift;
    11081088
    1109     my ($vol_id, $vol_path);
     1089    my ($vol_id, $vol_path, $xattr);
    11101090    eval {
    11111091        # TODO cache this?
     
    11371117
    11381118        my $free;
    1139         ($vol_id, $vol_path, $free) = $query->fetchrow_array;
     1119        ($vol_id, $vol_path, $xattr, $free) = $query->fetchrow_array;
    11401120        $query->finish;
    11411121    };
     
    11501130    $log->debug( "leaving" );
    11511131
    1152     return ($vol_id, $vol_path);
     1132    return ($vol_id, $vol_path, $xattr);
    11531133}
    11541134
     
    12101190}
    12111191
     1192sub _create_empty_instance_file
     1193{
     1194    my $self = shift;
     1195
     1196    my ($key, $ins_id, $volume) = @_;
     1197
     1198    my $log = $self->log;
     1199    my $sql = $self->sql;
     1200    my $db  =$self->db;
     1201
     1202    # Find the storage volume to use.
     1203    # ->_get_storage_volume() throws an exception on failure.
     1204    my ($vol_id, $vol_path, $xattr);
     1205    my ($storage_filename);
     1206    my ($uri);
     1207    eval {
     1208        ($vol_id, $vol_path, $xattr) = $self->_get_storage_volume($volume);
     1209        $storage_filename = $self->_generate_storage_filename($key, $ins_id);
     1210        # XXX put a hook for directory hashing here
     1211        $uri = URI::file->new("$vol_path/$storage_filename");
     1212        $log->debug("generated uri $uri");
     1213        $self->_create_empty_file($uri->file);
     1214    };
     1215    if ($@) {
     1216        $log->logdie($@);
     1217    }
     1218
     1219    if ($xattr) {
     1220        my $path = $uri->file;
     1221        die "can not set xattr on $path: $!"
     1222            unless (setfattr($path, 'user.nebulous_key', $key));
     1223    }
     1224
     1225    return ($uri, $vol_id);
     1226}
     1227
     1228
     1229sub _create_empty_file
     1230{
     1231    my $self = shift;
     1232
     1233    my ($path) = @_;
     1234
     1235    # perl's open() can't do an O_CREAT | O_EXCL
     1236    die "file $path already exists" if (-e $path);
     1237
     1238    my $fh;
     1239    die "can not open $path: $!"
     1240        unless (open($fh, '>', $path));
     1241
     1242    die "can not close $path: $!"
     1243        unless (close($fh));
     1244
     1245    die "can not chmod $path: $!"
     1246        unless (chmod 0664, $path);
     1247
     1248    return $path;
     1249}
     1250
     1251
     1252sub _generate_storage_filename
     1253{
     1254    my $self = shift;
     1255
     1256    my ($key, $ins_id) = @_;
     1257
     1258    my $filename = $key;
     1259    # mangle '/'s into ':'
     1260    $filename =~ s|/|:|g;
     1261
     1262    return "$ins_id.$filename"
     1263}
     1264
    12121265
    12131266sub DESTROY
  • trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r13251 r13302  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.40 2007-05-04 23:36:46 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.41 2007-05-08 02:27:42 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    204204            vol_id,
    205205            path,
     206            xattr,
    206207            total - used as free
    207208        FROM mountedvol
     
    218219            vol_id,
    219220            path,
     221            xattr,
    220222            total - used as free
    221223        FROM mountedvol
     
    228230    },
    229231    new_volume          => qq{
    230         INSERT INTO volume (name, path, allocate, available)
    231         VALUES (?, ?, TRUE, TRUE)
     232        INSERT INTO volume (name, path, allocate, available, xattr)
     233        VALUES (?, ?, TRUE, TRUE, FALSE)
    232234    },
    233235    get_volume_by_name => qq{
     
    359361    allocate BOOLEAN DEFAULT FALSE,
    360362    available BOOLEAN DEFAULT FALSE,
     363    xattr BOOLEAN DEFAULT FALSE,
    361364    PRIMARY KEY(vol_id),
    362365    KEY(name(16)),
     
    396399    allocate BOOLEAN DEFAULT FALSE,
    397400    available BOOLEAN DEFAULT FALSE,
     401    xattr BOOLEAN DEFAULT FALSE,
    398402    KEY(vol_id),
    399403    KEY(allocate),
     
    411415    DECLARE allocatevar BOOLEAN;
    412416    DECLARE availablevar BOOLEAN;
     417    DECLARE xattrvar BOOLEAN;
    413418    DECLARE trans_level VARCHAR(255);
    414     DECLARE cur1 CURSOR FOR SELECT vol_id, name, path, allocate, available FROM volume;
     419    DECLARE cur1 CURSOR FOR SELECT vol_id, name, path, allocate, available, xattr FROM volume;
    415420    DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE;
    416421
     
    430435
    431436    myloop: LOOP
    432         FETCH cur1 INTO vol_idvar, namevar, pathvar, allocatevar, availablevar;
     437        FETCH cur1 INTO vol_idvar, namevar, pathvar, allocatevar, availablevar, xattrvar;
    433438        IF `done` THEN LEAVE myloop; END IF;
    434439        INSERT INTO mountedvol
    435             SELECT mountpoint, total, used, vol_idvar, namevar, pathvar, allocatevar, availablevar
     440            SELECT mountpoint, total, used, vol_idvar, namevar, pathvar, allocatevar, availablevar, xattrvar
    436441            FROM
    437442                (SELECT *, INSTR(pathvar, mountpoint) = 1 as substring
  • trunk/Nebulous-Server/t/03_server_create_object.t

    r13273 r13302  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 03_server_create_object.t,v 1.19 2007-05-05 02:25:09 jhoblitt Exp $
     5# $Id: 03_server_create_object.t,v 1.20 2007-05-08 02:27:42 jhoblitt Exp $
    66
    77use strict;
     
    1818use Test::URI;
    1919use URI::Split qw( uri_split );
     20
     21my $test_xattr = undef;
    2022
    2123my $neb = Nebulous::Server->new(
     
    3537    uri_scheme_ok($uri, 'file');
    3638
     39SKIP: {
     40    skip "requires xattr support", 1 unless $test_xattr;
    3741    is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr');
     42}
    3843}
    3944
     
    4853    uri_scheme_ok($uri, 'file');
    4954
     55SKIP: {
     56    skip "requires xattr support", 1 unless $test_xattr;
    5057    is(getfattr($path, 'user.nebulous_key'), '/foo', 'user.nebulous_key xattr');
     58}
    5159}
    5260
     
    6169    uri_scheme_ok($uri, 'file');
    6270
     71SKIP: {
     72    skip "requires xattr support", 1 unless $test_xattr;
    6373    is(getfattr($path, 'user.nebulous_key'), '/foo/', 'user.nebulous_key xattr');
     74}
    6475}
    6576
     
    7485    uri_scheme_ok($uri, 'file');
    7586
     87SKIP: {
     88    skip "requires xattr support", 1 unless $test_xattr;
    7689    is(getfattr($path, 'user.nebulous_key'), 'foo/', 'user.nebulous_key xattr');
     90}
    7791}
    7892
     
    87101    uri_scheme_ok($uri, 'file');
    88102
     103SKIP: {
     104    skip "requires xattr support", 1 unless $test_xattr;
    89105    is(getfattr($path, 'user.nebulous_key'), 'foo/bar', 'user.nebulous_key xattr');
     106}
    90107}
    91108
     
    100117    uri_scheme_ok($uri, 'file');
    101118
     119SKIP: {
     120    skip "requires xattr support", 1 unless $test_xattr;
    102121    is(getfattr($path, 'user.nebulous_key'), '/foo/bar', 'user.nebulous_key xattr');
     122}
    103123}
    104124
  • trunk/Nebulous-Server/t/04_server_replicate_object.t

    r13273 r13302  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 04_server_replicate_object.t,v 1.9 2007-05-05 02:25:09 jhoblitt Exp $
     5# $Id: 04_server_replicate_object.t,v 1.10 2007-05-08 02:27:42 jhoblitt Exp $
    66
    77use strict;
     
    1818use Test::URI;
    1919use URI::Split qw( uri_split );
     20
     21my $test_xattr = undef;
    2022
    2123my $neb = Nebulous::Server->new(
     
    3638    uri_scheme_ok($uri, 'file');
    3739
     40SKIP: {
     41    skip "requires xattr support", 1 unless $test_xattr;
    3842    is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr');
     43}
    3944}
    4045
     
    5055    uri_scheme_ok($uri, 'file');
    5156
     57SKIP: {
     58    skip "requires xattr support", 1 unless $test_xattr;
    5259    is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr');
     60}
    5361}
    5462
     
    6674        uri_scheme_ok($uri1, 'file');
    6775
     76SKIP: {
     77    skip "requires xattr support", 1 unless $test_xattr;
    6878        is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr');
     79}
    6980    }
    7081
     
    7485        uri_scheme_ok($uri2, 'file');
    7586
     87SKIP: {
     88    skip "requires xattr support", 1 unless $test_xattr;
    7689        is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr');
     90}
    7791    }
    7892}
  • trunk/Nebulous/Changes

    r13279 r13302  
    22
    330.05
     4    - make filesystem xattr support optional & disabled by default
    45    - generate instance filenames that leave the "key" at the end so as to not
    56      break a pplications that expect a certain "extension" on the filename
  • trunk/Nebulous/lib/Nebulous/Client.pm

    r13256 r13302  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Client.pm,v 1.34 2007-05-05 00:14:17 jhoblitt Exp $
     3# $Id: Client.pm,v 1.35 2007-05-08 02:27:42 jhoblitt Exp $
    44
    55package Nebulous::Client;
     
    257257
    258258        $locations = $self->find_instances($key, $vol_name);
    259         unless (scalar @{ $locations }) {
     259        unless (defined $locations) {
    260260            $log->debug( "no instances" );
    261261            $log->debug( "leaving" );
  • trunk/Nebulous/lib/Nebulous/Server.pm

    r13278 r13302  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Server.pm,v 1.40 2007-05-05 02:59:31 jhoblitt Exp $
     3# $Id: Server.pm,v 1.41 2007-05-08 02:27:42 jhoblitt Exp $
    44
    55package Nebulous::Server;
     
    1313
    1414use DBI;
     15use File::ExtAttr qw( setfattr );
    1516use Log::Log4perl;
    1617use Nebulous::Server::Config;
     
    124125    my $self = shift;
    125126
    126     my ($key, $volume) = validate_pos(@_,
     127    my ($key, $vol_name) = validate_pos(@_,
    127128        {
    128129            type        => SCALAR,
     
    143144
    144145    $log->debug( "entered - @_" );
    145 
    146     # Find the storage volume to use.  We are doing this first as there's no
    147     # point in creating a new storage object if we can't allocate a new
    148     # instance. ->_get_storage_volume() throws an exception on failure.
    149     my ($vol_id, $vol_path);
    150     eval {
    151         ($vol_id, $vol_path) = $self->_get_storage_volume($volume);
    152     };
    153     if ($@) {
    154         $log->logdie($@);
    155     }
    156146
    157147    my $ins_id;
     
    206196    # actual on disk file name we can't try to create the file until after
    207197    # we've create both a new storage_storage object and instance.
    208     my $filename = $key;
    209     # mange '/'s into ':'
    210     $filename =~ s|/|:|g;
    211     my $uri = URI::file->new("$vol_path/$ins_id.$filename");
    212     $log->debug("generated uri $uri");
    213198
    214199    # TODO add some stuff here to retry if unsucessful
    215     eval {
    216         _create_empty_file($uri->file, $key);
     200    my ($uri, $vol_id);
     201    eval {
     202        ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name);
    217203    };
    218204    if ($@) {
     
    220206        $log->logdie($@);
    221207    }
     208
     209    $log->debug("created $uri on volume ID: $vol_id");
    222210
    223211    eval {
     
    225213            my $query = $db->prepare_cached( $sql->update_instance_uri );
    226214            # vol_id, uri, ins_id
    227             $query->execute($vol_id, $uri, $ins_id);
     215            $query->execute($vol_id, "$uri", $ins_id);
    228216        }
    229217
    230218        $db->commit;
     219        $log->debug("commit");
    231220    };
    232221    if ($@) {
     
    315304
    316305    $log->debug("entered - @_");
    317 
    318     my ($vol_id, $vol_path);
    319     eval {
    320         ($vol_id, $vol_path) = $self->_get_storage_volume($vol_name);
    321     };
    322     if ($@) {
    323         $log->logdie($@);
    324     }
    325306
    326307    my $ins_id;
     
    361342    }
    362343
    363     my $filename = $key;
    364     # mange '/'s into ':'
    365     $filename =~ s|/|:|g;
    366     my $uri = URI::file->new("$vol_path/$ins_id.$filename");
    367     $log->debug("generated uri $uri");
     344    # Unfortunately, since we want to use the instance row's ID as part of the
     345    # actual on disk file name we can't try to create the file until after
     346    # we've create both a new storage_storage object and instance.
    368347
    369348    # TODO add some stuff here to retry if unsucessful
    370     eval {
    371         _create_empty_file($uri->file, $key);
     349    my ($uri, $vol_id);
     350    eval {
     351        ($uri, $vol_id) = $self->_create_empty_instance_file($key, $ins_id, $vol_name);
    372352    };
    373353    if ($@) {
     
    11071087    my $name = shift;
    11081088
    1109     my ($vol_id, $vol_path);
     1089    my ($vol_id, $vol_path, $xattr);
    11101090    eval {
    11111091        # TODO cache this?
     
    11371117
    11381118        my $free;
    1139         ($vol_id, $vol_path, $free) = $query->fetchrow_array;
     1119        ($vol_id, $vol_path, $xattr, $free) = $query->fetchrow_array;
    11401120        $query->finish;
    11411121    };
     
    11501130    $log->debug( "leaving" );
    11511131
    1152     return ($vol_id, $vol_path);
     1132    return ($vol_id, $vol_path, $xattr);
    11531133}
    11541134
     
    12101190}
    12111191
     1192sub _create_empty_instance_file
     1193{
     1194    my $self = shift;
     1195
     1196    my ($key, $ins_id, $volume) = @_;
     1197
     1198    my $log = $self->log;
     1199    my $sql = $self->sql;
     1200    my $db  =$self->db;
     1201
     1202    # Find the storage volume to use.
     1203    # ->_get_storage_volume() throws an exception on failure.
     1204    my ($vol_id, $vol_path, $xattr);
     1205    my ($storage_filename);
     1206    my ($uri);
     1207    eval {
     1208        ($vol_id, $vol_path, $xattr) = $self->_get_storage_volume($volume);
     1209        $storage_filename = $self->_generate_storage_filename($key, $ins_id);
     1210        # XXX put a hook for directory hashing here
     1211        $uri = URI::file->new("$vol_path/$storage_filename");
     1212        $log->debug("generated uri $uri");
     1213        $self->_create_empty_file($uri->file);
     1214    };
     1215    if ($@) {
     1216        $log->logdie($@);
     1217    }
     1218
     1219    if ($xattr) {
     1220        my $path = $uri->file;
     1221        die "can not set xattr on $path: $!"
     1222            unless (setfattr($path, 'user.nebulous_key', $key));
     1223    }
     1224
     1225    return ($uri, $vol_id);
     1226}
     1227
     1228
     1229sub _create_empty_file
     1230{
     1231    my $self = shift;
     1232
     1233    my ($path) = @_;
     1234
     1235    # perl's open() can't do an O_CREAT | O_EXCL
     1236    die "file $path already exists" if (-e $path);
     1237
     1238    my $fh;
     1239    die "can not open $path: $!"
     1240        unless (open($fh, '>', $path));
     1241
     1242    die "can not close $path: $!"
     1243        unless (close($fh));
     1244
     1245    die "can not chmod $path: $!"
     1246        unless (chmod 0664, $path);
     1247
     1248    return $path;
     1249}
     1250
     1251
     1252sub _generate_storage_filename
     1253{
     1254    my $self = shift;
     1255
     1256    my ($key, $ins_id) = @_;
     1257
     1258    my $filename = $key;
     1259    # mangle '/'s into ':'
     1260    $filename =~ s|/|:|g;
     1261
     1262    return "$ins_id.$filename"
     1263}
     1264
    12121265
    12131266sub DESTROY
  • trunk/Nebulous/lib/Nebulous/Server/SQL.pm

    r13251 r13302  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: SQL.pm,v 1.40 2007-05-04 23:36:46 jhoblitt Exp $
     3# $Id: SQL.pm,v 1.41 2007-05-08 02:27:42 jhoblitt Exp $
    44
    55package Nebulous::Server::SQL;
     
    204204            vol_id,
    205205            path,
     206            xattr,
    206207            total - used as free
    207208        FROM mountedvol
     
    218219            vol_id,
    219220            path,
     221            xattr,
    220222            total - used as free
    221223        FROM mountedvol
     
    228230    },
    229231    new_volume          => qq{
    230         INSERT INTO volume (name, path, allocate, available)
    231         VALUES (?, ?, TRUE, TRUE)
     232        INSERT INTO volume (name, path, allocate, available, xattr)
     233        VALUES (?, ?, TRUE, TRUE, FALSE)
    232234    },
    233235    get_volume_by_name => qq{
     
    359361    allocate BOOLEAN DEFAULT FALSE,
    360362    available BOOLEAN DEFAULT FALSE,
     363    xattr BOOLEAN DEFAULT FALSE,
    361364    PRIMARY KEY(vol_id),
    362365    KEY(name(16)),
     
    396399    allocate BOOLEAN DEFAULT FALSE,
    397400    available BOOLEAN DEFAULT FALSE,
     401    xattr BOOLEAN DEFAULT FALSE,
    398402    KEY(vol_id),
    399403    KEY(allocate),
     
    411415    DECLARE allocatevar BOOLEAN;
    412416    DECLARE availablevar BOOLEAN;
     417    DECLARE xattrvar BOOLEAN;
    413418    DECLARE trans_level VARCHAR(255);
    414     DECLARE cur1 CURSOR FOR SELECT vol_id, name, path, allocate, available FROM volume;
     419    DECLARE cur1 CURSOR FOR SELECT vol_id, name, path, allocate, available, xattr FROM volume;
    415420    DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = TRUE;
    416421
     
    430435
    431436    myloop: LOOP
    432         FETCH cur1 INTO vol_idvar, namevar, pathvar, allocatevar, availablevar;
     437        FETCH cur1 INTO vol_idvar, namevar, pathvar, allocatevar, availablevar, xattrvar;
    433438        IF `done` THEN LEAVE myloop; END IF;
    434439        INSERT INTO mountedvol
    435             SELECT mountpoint, total, used, vol_idvar, namevar, pathvar, allocatevar, availablevar
     440            SELECT mountpoint, total, used, vol_idvar, namevar, pathvar, allocatevar, availablevar, xattrvar
    436441            FROM
    437442                (SELECT *, INSTR(pathvar, mountpoint) = 1 as substring
  • trunk/Nebulous/lib/Nebulous/Util.pm

    r13277 r13302  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Util.pm,v 1.6 2007-05-05 02:54:52 jhoblitt Exp $
     3# $Id: Util.pm,v 1.7 2007-05-08 02:27:42 jhoblitt Exp $
    44
    55package Nebulous::Util;
     
    1212use base qw( Exporter );
    1313
    14 use File::ExtAttr qw( setfattr );
    1514use Log::Log4perl qw( :levels );
    1615use URI::file;
     
    2322    _get_filehandle
    2423    _open_uri
    25     _create_empty_file
    2624);
    2725
     
    8078}
    8179
    82 sub _create_empty_file
    83 {
    84     my ($path, $key) = @_;
    85 
    86     # perl's open() can't do an O_CREAT | O_EXCL
    87     die "file $path already exists" if (-e $path);
    88 
    89     my $fh;
    90     die "can not open $path: $!"
    91         unless (open($fh, '>', $path));
    92 
    93     die "can not close $path: $!"
    94         unless (close($fh));
    95 
    96     die "can not chmod $path: $!"
    97         unless (chmod 0664, $path);
    98 
    99     die "can not set xattr on $path: $!"
    100         unless (setfattr($path, 'user.nebulous_key', $key));
    101 
    102     return $path;
    103 }
    104 
    105801;
    10681
  • trunk/Nebulous/t/03_server_create_object.t

    r13273 r13302  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 03_server_create_object.t,v 1.19 2007-05-05 02:25:09 jhoblitt Exp $
     5# $Id: 03_server_create_object.t,v 1.20 2007-05-08 02:27:42 jhoblitt Exp $
    66
    77use strict;
     
    1818use Test::URI;
    1919use URI::Split qw( uri_split );
     20
     21my $test_xattr = undef;
    2022
    2123my $neb = Nebulous::Server->new(
     
    3537    uri_scheme_ok($uri, 'file');
    3638
     39SKIP: {
     40    skip "requires xattr support", 1 unless $test_xattr;
    3741    is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr');
     42}
    3843}
    3944
     
    4853    uri_scheme_ok($uri, 'file');
    4954
     55SKIP: {
     56    skip "requires xattr support", 1 unless $test_xattr;
    5057    is(getfattr($path, 'user.nebulous_key'), '/foo', 'user.nebulous_key xattr');
     58}
    5159}
    5260
     
    6169    uri_scheme_ok($uri, 'file');
    6270
     71SKIP: {
     72    skip "requires xattr support", 1 unless $test_xattr;
    6373    is(getfattr($path, 'user.nebulous_key'), '/foo/', 'user.nebulous_key xattr');
     74}
    6475}
    6576
     
    7485    uri_scheme_ok($uri, 'file');
    7586
     87SKIP: {
     88    skip "requires xattr support", 1 unless $test_xattr;
    7689    is(getfattr($path, 'user.nebulous_key'), 'foo/', 'user.nebulous_key xattr');
     90}
    7791}
    7892
     
    87101    uri_scheme_ok($uri, 'file');
    88102
     103SKIP: {
     104    skip "requires xattr support", 1 unless $test_xattr;
    89105    is(getfattr($path, 'user.nebulous_key'), 'foo/bar', 'user.nebulous_key xattr');
     106}
    90107}
    91108
     
    100117    uri_scheme_ok($uri, 'file');
    101118
     119SKIP: {
     120    skip "requires xattr support", 1 unless $test_xattr;
    102121    is(getfattr($path, 'user.nebulous_key'), '/foo/bar', 'user.nebulous_key xattr');
     122}
    103123}
    104124
  • trunk/Nebulous/t/04_server_replicate_object.t

    r13273 r13302  
    33# Copryight (C) 2004-2005  Joshua Hoblitt
    44#
    5 # $Id: 04_server_replicate_object.t,v 1.9 2007-05-05 02:25:09 jhoblitt Exp $
     5# $Id: 04_server_replicate_object.t,v 1.10 2007-05-08 02:27:42 jhoblitt Exp $
    66
    77use strict;
     
    1818use Test::URI;
    1919use URI::Split qw( uri_split );
     20
     21my $test_xattr = undef;
    2022
    2123my $neb = Nebulous::Server->new(
     
    3638    uri_scheme_ok($uri, 'file');
    3739
     40SKIP: {
     41    skip "requires xattr support", 1 unless $test_xattr;
    3842    is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr');
     43}
    3944}
    4045
     
    5055    uri_scheme_ok($uri, 'file');
    5156
     57SKIP: {
     58    skip "requires xattr support", 1 unless $test_xattr;
    5259    is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr');
     60}
    5361}
    5462
     
    6674        uri_scheme_ok($uri1, 'file');
    6775
     76SKIP: {
     77    skip "requires xattr support", 1 unless $test_xattr;
    6878        is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr');
     79}
    6980    }
    7081
     
    7485        uri_scheme_ok($uri2, 'file');
    7586
     87SKIP: {
     88    skip "requires xattr support", 1 unless $test_xattr;
    7689        is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr');
     90}
    7791    }
    7892}
Note: See TracChangeset for help on using the changeset viewer.