sub new {} sub DESTROY {] etc. ... sub unlink { my $self=shift @_; my $object_id=shift @_; unless( defined($object_id) and $self->{'pf'}->is_uuid($object_id) ) { return 0; # FAIL } # Find out if we're already in a transaction my $in_transaction=$self->{'pf'}->in_transaction; # Don't create transaction if we're already in one # Start new transaction if we aren't already in one unless ($in_transaction) { $self->{'pf'}->transaction(1); } # Get object information my $sth=$self->{'pf'}->sql('SELECT object.object_id,storage_container.fs_path,object.storage_container_id,object.size FROM object,storage_container WHER # If record is something else than 1, either multiple objects or no objects are available, either way, it's an error. unless ($sth->rows == 1) { die __("Object not available."); } # Get object metadata from database my $object=$sth->fetchrow_hashref; # Find out if object is used as header-object somewhere else my $check_header_object_sth=$self->{'pf'}->sql('SELECT container_id,title FROM container WHERE object_id=?',$object_id); # Fail if object is in use in a container. if ($check_header_object_sth->rows > 0) { (my $header_container_id,my $header_container_title)=$check_header_object_sth->fetchrow_array; die __x("Object is used as a header object in container: {title}", title=>$header_container_title); } # Remove object from container_object (child objects of container) my $delete_container_sth=$self->{'pf'}->sql('DELETE FROM container_object WHERE object_id=?',$object->{'object_id'}); # Remove metadata file if present my $delete_sth=$self->{'pf'}->sql('DELETE FROM object WHERE object_id=?',$object->{'object_id'}); # Return error if unable to delete object metadata from database unless ($delete_sth->rows == 1) { die __"Unable to find object metadata to delete."; } # Update storage_container with new used size my $container_sth=$self->{'pf'}->sql('UPDATE storage_container SET usedsize=usedsize-? WHERE storage_container_id=?',$object->{'size'},$object->{'storag my $tmpfilename=$object->{'fs_path'} . "/" . $object->{'object_id'}; # Check if storage file is owned by effective uid unless ( -r $tmpfilename) { die __"Unreadable object."; } # Remove file unless(unlink $tmpfilename) { die __"Unable to delete object."; } # Commit data and finish transaction unless ($in_transaction) { $self->{'pf'}->transaction(0); } return 1; # OK }