Fuse-PDF
view release on metacpan or search on metacpan
lib/Fuse/PDF/FS.pm view on Meta::CPAN
my $src = $srcdirs->[-1];
my $dest = $destdirs->[-1];
my $root = $self->{fs}->{root}->{value};
return -EACCESS if $root == $src;
if ($dest) {
return 0 if $dest == $src; # rename to self always works
return -EACCESS if $root == $dest;
my $srctype = $src->{type}->{value};
my $desttype = $dest->{type}->{value};
return -ENOTDIR() if 'd' eq $srctype && 'd' ne $desttype;
return -EISDIR() if 'd' ne $srctype && 'd' eq $desttype;
if ('d' eq $desttype && 0 != scalar keys %{$dest->{content}->{value}}) {
return -ENOTEMPTY();
}
}
# Ensure dest is not inside src
if (@{$srcpaths} < @{$destpaths}) {
my $match = 1;
for my $i (0 .. $#{$srcpaths}) {
if ($srcpaths->[$i] ne $destpaths->[$i]) {
$match = 0;
last;
}
}
return -EINVAL() if $match;
}
my $srcparent = $srcdirs->[-2]; ## no critic(MagicNumber)
my $destparent = $destdirs->[-2]; ## no critic(MagicNumber)
my $srcname = $srcpaths->[-1];
my $destname = $destpaths->[-1];
# supposed to set dest before removing src to avoid data loss, but meh...
$destparent->{content}->{value}->{$destname} = delete $srcparent->{content}->{value}->{$srcname};
my $mtime = time;
$srcparent->{mtime}->{value} = $mtime;
$destparent->{mtime}->{value} = $mtime; # harmless if $srcparent == $destparent
$self->{fs}->{mtime}->{value} = $mtime;
$self->{dirty} = 1;
return 0;
}
sub fs_link {
return -EIO();
}
sub fs_chmod {
my ($self, $abspath, $perms) = @_;
my $f = $self->_file($abspath);
return -$f if !ref $f;
$f->{mode}->{value} = S_IFMT($f->{mode}->{value}) | S_IMODE($perms);
$self->{fs}->{mtime}->{value} = time;
$self->{dirty} = 1;
return 0;
}
sub fs_chown {
my ($self, $abspath, $uid, $gid) = @_;
my $f = $self->_file($abspath);
return -$f if !ref $f;
#$f->{uid}->{value} = $uid;
#$f->{gid}->{value} = $gid;
#$self->{dirty} = 1;
return 0;
}
sub fs_truncate {
my ($self, $abspath, $length) = @_;
my $f = $self->_file($abspath);
return -$f if !ref $f;
my $type = $f->{type}->{value};
return -EISDIR() if 'd' eq $type;
if ($length <= 0) {
$f->{content}->{value} = q{};
} else {
my $l = length $f->{content}->{value};
if ($length < $l) {
$f->{content}->{value} = substr $f->{content}->{value}, 0, $length;
} elsif ($length > $l) {
$f->{content}->{value} .= "\0" x ($length - $l);
}
}
my $mtime = time;
$f->{mtime}->{value} = $mtime;
$self->{fs}->{mtime}->{value} = $mtime;
$self->{dirty} = 1;
return 0;
}
sub fs_utime {
my ($self, $abspath, $atime, $mtime) = @_;
my $f = $self->_file($abspath);
return -$f if !ref $f;
# Ignore atime
# Set utime, if changed
if ($f->{mtime}->{value} != $mtime) {
$f->{mtime}->{value} = $mtime;
$self->{fs}->{mtime}->{value} = time;
$self->{dirty} = 1;
}
return 0;
}
sub fs_open {
my ($self, $abspath, $flags) = @_;
my $f = $self->_file($abspath);
return -$f if !ref $f;
# check flags?
return 0;
}
sub fs_read {
my ($self, $abspath, $size, $offset) = @_;
my $f = $self->_file($abspath);
return -$f if !ref $f;
lib/Fuse/PDF/FS.pm view on Meta::CPAN
=item $self->all_revisions()
Return a list of one instance for each revision of the PDF. The first
item on the list is this instance (the newest) and the last item on
the list is the first revision of the PDF (the oldest).
=item $self->previous_revision()
If there is an older version of the PDF, extract that and return a new
C<Fuse::PDF::FS> instance which applies to that revision. Multiple
versions is feature supported by the PDF specification, so this action
is consistent with other PDF revision editing tools.
If this is a new filesystem or if the C<compact()> option was used,
then there will be no previous revisions and this will return
C<undef>.
=item $self->statistics()
Return a hashref with some global information about the filesystem.
This is currently meant for humans and the exact list of statistics is
not yet locked down. See the code for more details.
=item $self->to_string()
Return a human-readable representation of the statistics for each
revision of the filesystem.
=back
=head1 FUSE-COMPATIBLE METHODS
The following methods are independent of L<Fuse>, but uses almost the
exact same API expected by that package (except for fs_setxattr), so
they can easily be converted to a FUSE implementation.
=over
=item $self->fs_getattr($file)
=item $self->fs_readlink($file)
=item $self->fs_getdir($file)
=item $self->fs_mknod($file, $modes, $dev)
=item $self->fs_mkdir($file, $perms)
=item $self->fs_unlink($file)
=item $self->fs_rmdir($file)
=item $self->fs_symlink($link, $file)
=item $self->fs_rename($oldfile, $file)
=item $self->fs_link($srcfile, $file)
=item $self->fs_chmod($file, $perms)
=item $self->fs_chown($file, $uid, $gid)
=item $self->fs_truncate($file, $length)
=item $self->fs_utime($file, $atime, $mtime)
=item $self->fs_open($file, $mode)
=item $self->fs_read($file, $size, $offset)
=item $self->fs_write($file, $str, $offset)
=item $self->fs_statfs()
=item $self->fs_flush($file)
=item $self->fs_release($file, $mode)
=item $self->fs_fsync($file, $flags)
=item $self->fs_setxattr($file, $key, $value, \%flags)
=item $self->fs_getxattr($file, $key)
=item $self->fs_listxattr($file)
=item $self->fs_removexattr($file, $key)
=back
=head1 HACKS
=over
=item ENOATTR()
L<POSIX> is missing a constant this error number (at least, not on Mac
10.4). If we detect that it is missing at runtime, we attempt to replace it
by: 1) reading F<errno.h>, 2) falling back to EIO.
See L<Fuse::PDF::ErrnoHacks>.
=back
=head1 SEE ALSO
L<Fuse::PDF>
L<CAM::PDF>
=head1 AUTHOR
Chris Dolan, I<cdolan@cpan.org>
=cut
# Local Variables:
# mode: perl
# perl-indent-level: 3
# cperl-indent-level: 3
# fill-column: 78
( run in 0.665 second using v1.01-cache-2.11-cpan-71847e10f99 )