IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 29, 2009, 12:21:43 PM (17 years ago)
Author:
jhoblitt
Message:

add chmod_object() method

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r23932 r24276  
    1515use DBI;
    1616use Digest::SHA1 qw( sha1_hex );
     17use Fcntl ':mode';
    1718use File::Basename qw( basename dirname fileparse );
    1819use File::ExtAttr qw( setfattr );
     
    15761577}
    15771578
     1579sub chmod_object
     1580{
     1581    my $self = shift;
     1582
     1583    my ($key, $mode) = validate_pos( @_,
     1584        {
     1585            type        => SCALAR,
     1586            callbacks   => {
     1587                'is valid object key' => sub { $self->_is_valid_object_key($_[0]) },
     1588            },
     1589        },
     1590        {
     1591            type        => SCALAR,
     1592            regex       => qr/\d{3,4}/,
     1593            callbacks   => {
     1594                'is allowable mode' => sub {
     1595                    $_[0] == (S_IRUSR | S_IRGRP)
     1596                },
     1597            },
     1598        },
     1599    );
     1600
     1601    # ignore volume
     1602    $key = parse_neb_key($key);
     1603
     1604    my $log = $self->log;
     1605    my $sql = $self->sql;
     1606    my $db  = $self->db($key);
     1607
     1608    $log->debug("entered - @_");
     1609
     1610    # find all instances of this object
     1611    my $locations;
     1612    eval {
     1613        $locations = $self->find_instances("$key");
     1614    };
     1615    $log->logdie("error: $@") if $@;
     1616
     1617    # update each instances
     1618    foreach my $inst (@$locations) {
     1619        chmod $mode, URI->new($inst)->path
     1620            or $log->logdie("chmod() failed: $!");
     1621    }
     1622
     1623    # stick an xattr on this object with the mode
     1624    # XXX this would probably be better as a field in the storage_object_attr
     1625    # table but since we're not planning to use this for very many objects (as
     1626    # a %) it may not be worth adding the extra field at this time.
     1627    eval {
     1628        $self->setxattr_object("$key", 'user.mode', $mode, 'replace');
     1629    };
     1630    $log->logdie("error: $@") if $@;
     1631
     1632    $log->debug("leaving");
     1633
     1634    return $mode;
     1635}
    15781636
    15791637sub _get_storage_volume
Note: See TracChangeset for help on using the changeset viewer.