diff --git a/README b/README new file mode 100644 index 0000000..2a7b707 --- /dev/null +++ b/README @@ -0,0 +1,8 @@ +install Unix::Mknod-0.05 or Fuse won't install: + $ git clone + $ cpanm . + +super buggy: + +truncate a mess +Fuse error 34 diff --git a/huh.txt b/huh.txt new file mode 100644 index 0000000..e69de29 diff --git a/neocitiesfs.pl b/neocitiesfs.pl index 0ee4e78..048f37a 100755 --- a/neocitiesfs.pl +++ b/neocitiesfs.pl @@ -11,6 +11,9 @@ # If not, see . # author: jake [a\ jakes-mail dot top # release: 29, Oct 2023 +# +# SETATTR -> truncate, utime, chown, chmod ? +# use strict; use warnings; use 5.010; @@ -22,6 +25,9 @@ use POSIX qw(ENOENT EISDIR EINVAL EEXIST ENOTEMPTY EACCES EFBIG use File::Slurper qw(read_text); use Mojo::Date; use Getopt::Long; +use Carp::Always; +use Smart::Comments; +use File::Temp qw(tempfile); my $user; my $pass; @@ -232,6 +238,15 @@ sub e_open { return (0, $fh); } +sub e_create { + my $path = shift; + my ($dirs, $file) = get_path_and_file($path); + return -EEXIST if exists($files{$dirs}{$file}); + + my $res = write_to_neocities($dirs, $file, ''); + return res_errno($res, 0); +} + sub e_read { my ($dirs, $file) = get_path_and_file(shift); my ($buf, $off, $fh) = @_; @@ -256,9 +271,52 @@ sub e_statfs { return 255, 1, 1, 1, 1, 2 } sub e_write { my ($dirs, $file) = get_path_and_file(shift); my ($buf, $off, $fh) = @_; + ## # e_write + ## # $off + ## # $fh return -ENOENT() unless exists($files{$dirs}{$file}); - my $res = write_to_neocities($dirs, $file, $buf); - return res_errno($res, length($buf)); + if (! exists $files{$dirs}{$file}{fh}) { + ($files{$dirs}{$file}{fh}, $files{$dirs}{$file}{fn}) = tempfile(); + } + my $fh2 = $files{$dirs}{$file}{fh}; + seek $fh2, $off, 0; + print $fh2 $buf; + +# my $res = write_to_neocities($dirs, $file, $buf); + return length $buf; +} + +sub e_flush { + ### @_ + ### %files + my ($path, $_fh) = @_; + my ($dirs, $file) = get_path_and_file($path); + if (exists $files{$dirs}{$file}{fh}) { + my $fn = $files{$dirs}{$file}{fn}; + my $res = write_to_neocities($dirs, $file, $fn, 1); + close $files{$dirs}{$file}{fh}; + delete $files{$dirs}{$file}{fh}; + delete $files{$dirs}{$file}{fn}; + unlink $files{$dirs}{$file}{fn}; + return res_errno($res, 0); + } +} + +sub e_not_implimented { return -ENOSYS; } + +sub e_lie_implimented { return 0; } + +sub e_truncate { + my ($path, $how_much) = @_; + my ($dirs, $file) = get_path_and_file($path); + return -ENOENT if ! exists $files{$dirs}{$file}; + ### XXX DRAGONS HERE + my $path_to_thing = $mountpoint ."/$path"; + ### $path_to_thing + open my $fh, '>', $path_to_thing or return -ENOENT; + truncate $fh, $how_much; + close $fh; + return 0; } sub e_mknod { @@ -277,13 +335,13 @@ sub e_unlink { if ($pass) { $tx = $ua->post("https://$user:$pass\@neocities.org/api/delete", => {Accept => '*/*'} => form => {'filenames[]' => [ "$dirs/$file" ]}); - my $res = $tx->res; + $res = $tx->res; } else { my $tx = $ua->build_tx(POST => 'https://neocities.org/api/delete', => {Accept => '*/*'} => form => {'filenames[]' => [ "$dirs/$file" ]}); $tx->req->headers->authorization("Bearer $api"); - my $res = $ua->start($tx)->res; + $res = $ua->start($tx)->res; } $suppress_list_update = 1; @@ -304,7 +362,7 @@ sub e_mkdir { # my $numb = int(rand(99999999)) . 'mkdir_hopefully_no_collsions.html'; # # $suppress_list_update = 1; -# my $res = e_mknod("$dirs/$file/$numb"); +# $res = e_mknod("$dirs/$file/$numb"); # # $suppress_list_update = 0; # return res_errno($res,0) if $res != 0; @@ -392,7 +450,7 @@ sub e_rename { sub res_errno { my ($res, $buf_len) = @_; if ($res->is_success) { - my $res = get_listing_from_neocities(); + get_listing_from_neocities(); return $buf_len; } elsif ($res->code == 400) { @@ -425,10 +483,22 @@ sub res_errno { # this returns mojo's 'res' thing sub write_to_neocities { - my ($dirs, $file, $buffer) = @_; + my ($dirs, $file, $buffer, $is_buf_fn) = @_; + defined $is_buf_fn or $is_buf_fn = 0; my $ua = Mojo::UserAgent->new(); - my $asset = Mojo::Asset::Memory->new->add_chunk($buffer); + my $asset; + if (! $is_buf_fn) { + ### write_to_neocities + ### buf _IS NOT_ fn + $asset = Mojo::Asset::Memory->new->add_chunk($buffer); + } + else { + ### write_to_neocities + ### buf _IS_ fn + $asset = Mojo::Asset::File->new(path => $buffer); + } + my ($tx, $res); if ($pass) { $tx = $ua->post("https://$user:$pass\@neocities.org/api/upload" => @@ -441,6 +511,7 @@ sub write_to_neocities { $tx->req->headers->authorization("Bearer $api"); $res = $ua->start($tx)->res; } + undef $asset; return $res; } @@ -462,6 +533,12 @@ Fuse::main( mkdir =>"main::e_mkdir", rmdir =>"main::e_rmdir", rename =>"main::e_rename", - threaded=>0 - + create =>"main::e_create", + flush =>"main::e_flush", + truncate => "main::e_truncate", + utime =>"main::e_not_implimented", + chown =>"main::e_not_implimented", + chmod =>"main::e_not_implimented", + threaded=>0, + debug=>1, );