Filesys-POSIX

 view release on metacpan or  search on metacpan

lib/Filesys/POSIX.pm  view on Meta::CPAN

The old inode is not a directory, but an existing inode found in the new path
specified, is.

=item * ENOTEMPTY (Directory not empty)

Both the old and new paths correspond to a directory, but the new path is not
of an empty directory.

=back

Upon success, a reference to the inode to be renamed will be returned.

=cut

sub rename {
    my ( $self, $old, $new ) = @_;

    my $inode = $self->lstat($old);

    my $old_hier   = Filesys::POSIX::Path->new($old);
    my $old_name   = $old_hier->basename;
    my $old_parent = $self->stat( $old_hier->dirname );
    my $old_dir    = $old_parent->directory;

    my $new_hier   = Filesys::POSIX::Path->new($new);
    my $new_name   = $new_hier->basename;
    my $new_parent = $self->stat( $new_hier->dirname );
    my $new_dir    = $new_parent->directory;

    $! = 0;

    throw &Errno::EXDEV unless $inode->{'dev'} eq $new_parent->{'dev'};

    if ( my $existing = $new_dir->get($new_name) ) {
        if ( $inode->dir ) {
            throw &Errno::ENOTDIR   unless $existing->dir;
            throw &Errno::ENOTEMPTY unless $existing->empty;
        }
        else {
            throw &Errno::EISDIR if $existing->dir;
        }
    }

    $new_dir->rename_member( $inode, $old_dir, $old_name, $new_name );

    return $inode;
}

=item C<$fs-E<gt>rmdir($path)>

Unlinks the directory inode at the specified path.  Exceptions are thrown in
the following conditions:

=over

=item * ENOENT (No such file or directory)

No inode exists by the name specified in the final component of the path in
the parent directory specified in the path.

=item * EBUSY (Device or resource busy)

The directory specified is an active mount point.

=item * ENOTDIR (Not a directory)

The inode found at C<$path> is not a directory.

=item * ENOTEMPTY (Directory not empty)

The directory is not empty.

=back

Upon success, a reference to the inode of the directory to be removed will be
returned.

=cut

sub rmdir {
    my ( $self, $path ) = @_;
    my $hier      = Filesys::POSIX::Path->new($path);
    my $name      = $hier->basename;
    my $parent    = $self->lstat( $hier->dirname );
    my $directory = $parent->directory;
    my $inode     = $directory->get($name);

    $! = 0;

    throw &Errno::ENOENT unless $inode;

    throw &Errno::EBUSY if $self->{'vfs'}->statfs(
        $self->stat($path),
        'exact' => 1, 'silent' => 1
    );

    throw &Errno::ENOTEMPTY unless $inode->empty;

    $directory->delete($name);

    return $inode;
}

=item C<$fs-E<gt>mknod($path, $mode)>

=item C<$fs-E<gt>mknod($path, $mode, $dev)>

Create a new inode at the specified C<$path>, with the inode permissions and
format specified in the C<$mode> argument.  If C<$mode> specifies a C<$S_IFCHR>
or C<$S_IFBLK> value, then the device number specified in C<$dev> will be given
to the new inode.

Code contained within the C<Filesys::POSIX> distribution assumes that the device
identifier shall contain the major and minor numbers in separate 16-bit fields,
in the following manner:

    my $major = ($dev & 0xffff0000) >> 16;
    my $minor =  $dev & 0x0000ffff;

Returns a reference to a L<Filesys::POSIX::Inode> object upon success.



( run in 0.518 second using v1.01-cache-2.11-cpan-39bf76dae61 )