summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOthmar Gsenger <otti@wirdorange.org>2011-04-24 18:35:23 +0000
committerOthmar Gsenger <otti@wirdorange.org>2011-04-24 18:35:23 +0000
commit5f854d24b20cc0ab7cfa039aae28233ce525b5dc (patch)
tree85fa9261e2c048be4f7ae55b5ea2090b1dc3562a
parenthopfully repaired this after backup loss (diff)
added fuse support
-rwxr-xr-xfuse.pl77
1 files changed, 77 insertions, 0 deletions
diff --git a/fuse.pl b/fuse.pl
new file mode 100755
index 0000000..08b3d38
--- /dev/null
+++ b/fuse.pl
@@ -0,0 +1,77 @@
+#!/usr/bin/perl
+use Fuse;
+use POSIX qw(ENOENT ENOSYS EEXIST EPERM O_RDONLY O_RDWR O_APPEND O_CREAT);
+use local::db;
+use config;
+
+my ($mountpoint) = "";
+$mountpoint = shift(@ARGV) if @ARGV;
+Fuse::main(mountpoint=>$mountpoint, mountopts => "allow_other",getattr=>"main::my_getattr", getdir=>"main::my_getdir", debug=>0, readlink => "main::my_readlink");
+
+exit 0;
+
+sub my_getdir
+{
+ my ( $filename ) = @_;
+ my @dirs = '.';
+ if ($filename eq '/')
+ {
+ my @cat = local::db::category->retrieve_all;
+ push @dirs, map {$_->name} @cat;
+ } else {
+ my ($cat) = $filename =~ m'/(.*)$';
+ my @cat = local::db::category->search(name=>$cat);
+ my @downloads = (shift @cat)->download; #local::db::download->retrieve_all;
+ push @dirs, map {$_->name.'_'.$_->download_id} @downloads;
+ }
+ return @dirs,0;
+# return -1*ENOENT;
+}
+
+sub my_getattr
+{
+ my ( $path ) = @_;
+ my $mode = 0040 <<9| 0755;
+ my ($foo,$dirname,$filename) = split '/',$path;
+ if ($dirname and $dirname ne '.')
+ {
+ if ($filename)
+ {
+ $mode = 0120000 | 0777 if $filename;
+ return -ENOENT() if not $filename =~ m/_\d+$/;
+ } else {
+ local::db::category->search(name=>$dirname) or return -ENOENT();
+ }
+ }
+ my $nlink = 1;
+ my $uid = $<;
+ my ($gid) = split / /, $(;
+ my $size = 0;
+ my $rdev = 0;
+ my $atime = time;
+ my $mtime = $atime;
+ my $ctime = $atime;
+ my $blksize = 1024;
+ my $blocks = 1;
+ my $dev = 0;
+ my $ino = 0;
+
+ return (
+ $dev, $ino, $mode, $nlink,
+ $uid, $gid, $rdev, $size,
+ $atime, $mtime, $ctime, $blksize,
+ $blocks
+ );
+# return -1*ENOENT;
+}
+
+sub my_readlink
+{
+ my ( $path ) = @_;
+ my ($foo,$cat,$filename) = split '/',$path;
+ my ($id) = $filename =~ m/_(\d+)$/;
+# my @download = local::db::download->search(download_id=>$id);
+# my $download = shift @download or return "/dev/null";
+ return $config::config{files_dir}.'/'.$cat.'/'.$id;
+}
+