Fuse-Filesys-Virtual

 view release on metacpan or  search on metacpan

lib/Fuse/Filesys/Virtual.pm  view on Meta::CPAN

Same as Fuse.

=cut

sub mknod {
    my $self = shift;
    my ($fname, $modes) = @_;

    eval {
	if ($self->{_filesys}->stat($fname)) {
	    $! = EEXIST;
	    die "file exists";
	}
	else {
	    my $fh = $self->{_filesys}->open_write($fname, 0);
	    die "cannot create $fname: $!" unless($fh);
	    $self->{_filesys}->close_write($fh);
	}
    };
    if ($@) {
	$self->_debug($@);
	$! = EPERM if ($! == 0);
	return -$!;
    }

    return 0;
}

=head2 mkdir

Same as Fuse.

=cut

sub mkdir {
    my $self = shift;
    my ($dirname, $modes) = @_;

    eval {
	$self->{_filesys}->mkdir($dirname);
    };
    if ($@) {
	$self->_debug($@);
	$! = EPERM if ($! == 0);
	return -$!;
    }

    return 0;
}

=head2 unlink

Same as Fuse.

=cut

sub unlink {
    my $self = shift;
    my ($fname) = @_;

    my $busy = eval {
	return -EBUSY() if ($self->{_cache}->is_busy($fname));
    };
    return $busy if ($busy);

    eval {
	unless ($self->{_filesys}->delete($fname)) {
	    $! = EPERM;
	    die "failure";
	}
    };
    if ($@) {
	$self->_debug($@);
	$! = EPERM if ($! == 0);
	return -$!;
    }

    return 0;
}

=head2 rmdir

Same as Fuse.

=cut

sub rmdir {
    my $self = shift;
    my ($dirname) = @_;

    my $busy = eval {
	return -EBUSY() if ($self->{_cache}->is_busy($dirname));
    };
    return $busy if ($busy);

    eval {
	$self->{_filesys}->rmdir($dirname);
    };
    if ($@) {
	$self->_debug($@);
	$! = EPERM if ($! == 0);
	return -$!;
    }

    return 0;
}

=head2 symlink

Always returns -EPERM.
This function is not supported by Virtual::Filesys.

=cut

sub symlink {
    my $self = shift;
    return -EPERM();
}

=head2 rename

Same as Fuse.
But his function is implemented by Copy & Delete.

=cut

sub rename {
    my $self = shift;
    my ($oldname, $newname) = @_;

    my $busy = eval {
	return -EBUSY() if ($self->{_cache}->is_busy($oldname));
    };
    return $busy if ($busy);

    $busy = eval {
	return -EBUSY() if (!$self->{_filesys}->test('d', $newname)
			    && $self->{_cache}->is_busy($newname));
    };
    return $busy if ($busy);

    eval {
	$self->{_filesys}->rename($oldname, $newname)
	    or die "cannot rename: $!";
    };
    if ($@) {
	$self->_debug($@);
	$! = EPERM if ($! == 0);
	return -$!;
    }

    return 0;
}

=head2 link

Always returns -EPERM.
This function is not supported by Virtual::Filesys.

=cut

sub link {
    my $self = shift;
    return -EPERM();
}

=head2 chmod

Always returns 0(success), but nothing is done.
This function is not supported by Virtual::Filesys.

=cut

sub chmod {
    my $self = shift;
    return 0;
}

=head2 chown

Always returns -EPERM.
This function is not supported by Virtual::Filesys.

=cut

sub chown {
    my $self = shift;
    return -EPERM();
}

=head2 truncate

Always returns -EPERM.
This function is not supported by Virtual::Filesys.

=cut

sub truncate {
    my $self = shift;
    my ($fname) = @_;



( run in 2.081 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )