IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17845 for trunk/Nebulous/lib


Ignore:
Timestamp:
May 28, 2008, 5:59:30 PM (18 years ago)
Author:
jhoblitt
Message:

move print_all_xattrs(), print_xattrs(), write_xattrs(), delete_xattrs(), and parse_xattr_pair() from neb-xattr into Nebulous::Util

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous/lib/Nebulous/Util.pm

    r17073 r17845  
    11# Copyright (c) 2004  Joshua Hoblitt
    22#
    3 # $Id: Util.pm,v 1.11 2008-03-20 23:21:58 jhoblitt Exp $
     3# $Id: Util.pm,v 1.12 2008-05-29 03:59:30 jhoblitt Exp $
    44
    55package Nebulous::Util;
     
    88use warnings FATAL => qw( all );
    99
    10 our $VERSION = '0.01';
     10our $VERSION = '0.02';
    1111
    1212use base qw( Exporter );
     
    2424    _open_uri
    2525    parse_neb_key
     26    print_xattrs
     27    print_all_xattrs
     28    write_xattrs
     29    delete_xattrs
     30    parse_xattr_pair
    2631);
    2732
     
    3944);
    4045
     46
    4147sub _nuke_file {
    4248    my $path = shift;
     
    5157}
    5258
     59
    5360sub _get_file_path {
    5461    my $uri = shift;
     
    5865    return $path;
    5966}
     67
    6068
    6169sub _get_filehandle {
     
    7078}
    7179
     80
    7281sub _open_uri {
    7382    my ( $uri , $flags ) = @_;
     
    8190
    8291
     92sub print_all_xattrs
     93{
     94    my ($neb, $key) = @_;
     95
     96    return unless defined $neb;
     97    return unless defined $key;
     98
     99    my $xattr_names = $neb->listxattr($key) or die $neb->err;
     100    foreach my $name (@$xattr_names) {
     101        print_xattrs($neb, $key, $name) or return;
     102    }
     103
     104    return 1;
     105}
     106
     107
     108sub print_xattrs
     109{
     110    my ($neb, $key, @xattr_names) = @_;
     111
     112    return unless defined $neb;
     113    return unless defined $key;
     114    return unless scalar @xattr_names;
     115
     116    foreach my $arg (@xattr_names) {
     117        my ($name, $value) = parse_xattr_pair($arg);
     118        die "can not process $arg because it is in name:value form"
     119            if defined $value;
     120        $value = $neb->getxattr($key, $name) or die $neb->err;
     121        print "$name:$value\n";
     122    }
     123
     124    return 1;
     125}
     126
     127
     128sub write_xattrs
     129{
     130    my ($neb, $key, @xattr_pairs) = @_;
     131
     132    return unless defined $neb;
     133    return unless defined $key;
     134    return unless scalar @xattr_pairs;
     135
     136    foreach my $arg (@xattr_pairs) {
     137        my ($name, $value) = parse_xattr_pair($arg);
     138        die "can not process $arg because it is not in name:value form"
     139            unless defined $name and defined $value;
     140        die "xattr name: $name is not in to the form user.name"
     141            unless $name =~ /^user\./;
     142        $neb->setxattr($key, $name, $value, "replace")
     143            or die $neb->err;
     144    }
     145
     146    return 1;
     147}
     148
     149
     150sub delete_xattrs
     151{
     152    my ($neb, $key, @xattr_names) = @_;
     153
     154    return unless defined $neb;
     155    return unless defined $key;
     156    return unless scalar @xattr_names;
     157
     158    foreach my $arg (@xattr_names) {
     159        my ($name, $value) = parse_xattr_pair($arg);
     160        die "can not process $arg because it is in name:value form"
     161            if defined $value;
     162        $neb->removexattr($key, $name)
     163            or die $neb->err;
     164    }
     165
     166    return 1;
     167}
     168
     169
     170sub parse_xattr_pair
     171{
     172    my $pair = shift;
     173   
     174    return unless defined $pair;
     175
     176    no warnings qw( uninitialized );
     177    my ($name, $value) = split(/:/, $pair);
     178    use warnings;
     179
     180    return ($name, $value);
     181}
     182
     183
    831841;
    84185
Note: See TracChangeset for help on using the changeset viewer.