Add change up e_write() and add e_flush() also note that this super buggy atm
This commit is contained in:
parent
60646a5285
commit
0923407117
3 changed files with 95 additions and 10 deletions
8
README
Normal file
8
README
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
install Unix::Mknod-0.05 or Fuse won't install:
|
||||||
|
$ git clone <path>
|
||||||
|
$ cpanm .
|
||||||
|
|
||||||
|
super buggy:
|
||||||
|
|
||||||
|
truncate a mess
|
||||||
|
Fuse error 34
|
0
huh.txt
Normal file
0
huh.txt
Normal file
|
@ -11,6 +11,9 @@
|
||||||
# If not, see <https://www.gnu.org/licenses/>.
|
# If not, see <https://www.gnu.org/licenses/>.
|
||||||
# author: jake [a\ jakes-mail dot top
|
# author: jake [a\ jakes-mail dot top
|
||||||
# release: 29, Oct 2023
|
# release: 29, Oct 2023
|
||||||
|
#
|
||||||
|
# SETATTR -> truncate, utime, chown, chmod ?
|
||||||
|
#
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use 5.010;
|
use 5.010;
|
||||||
|
@ -22,6 +25,9 @@ use POSIX qw(ENOENT EISDIR EINVAL EEXIST ENOTEMPTY EACCES EFBIG
|
||||||
use File::Slurper qw(read_text);
|
use File::Slurper qw(read_text);
|
||||||
use Mojo::Date;
|
use Mojo::Date;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
|
use Carp::Always;
|
||||||
|
use Smart::Comments;
|
||||||
|
use File::Temp qw(tempfile);
|
||||||
|
|
||||||
my $user;
|
my $user;
|
||||||
my $pass;
|
my $pass;
|
||||||
|
@ -232,6 +238,15 @@ sub e_open {
|
||||||
return (0, $fh);
|
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 {
|
sub e_read {
|
||||||
my ($dirs, $file) = get_path_and_file(shift);
|
my ($dirs, $file) = get_path_and_file(shift);
|
||||||
my ($buf, $off, $fh) = @_;
|
my ($buf, $off, $fh) = @_;
|
||||||
|
@ -256,9 +271,52 @@ sub e_statfs { return 255, 1, 1, 1, 1, 2 }
|
||||||
sub e_write {
|
sub e_write {
|
||||||
my ($dirs, $file) = get_path_and_file(shift);
|
my ($dirs, $file) = get_path_and_file(shift);
|
||||||
my ($buf, $off, $fh) = @_;
|
my ($buf, $off, $fh) = @_;
|
||||||
|
## # e_write
|
||||||
|
## # $off
|
||||||
|
## # $fh
|
||||||
return -ENOENT() unless exists($files{$dirs}{$file});
|
return -ENOENT() unless exists($files{$dirs}{$file});
|
||||||
my $res = write_to_neocities($dirs, $file, $buf);
|
if (! exists $files{$dirs}{$file}{fh}) {
|
||||||
return res_errno($res, length($buf));
|
($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 {
|
sub e_mknod {
|
||||||
|
@ -277,13 +335,13 @@ sub e_unlink {
|
||||||
if ($pass) {
|
if ($pass) {
|
||||||
$tx = $ua->post("https://$user:$pass\@neocities.org/api/delete", => {Accept => '*/*'} => form =>
|
$tx = $ua->post("https://$user:$pass\@neocities.org/api/delete", => {Accept => '*/*'} => form =>
|
||||||
{'filenames[]' => [ "$dirs/$file" ]});
|
{'filenames[]' => [ "$dirs/$file" ]});
|
||||||
my $res = $tx->res;
|
$res = $tx->res;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $tx = $ua->build_tx(POST => 'https://neocities.org/api/delete', => {Accept => '*/*'} => form =>
|
my $tx = $ua->build_tx(POST => 'https://neocities.org/api/delete', => {Accept => '*/*'} => form =>
|
||||||
{'filenames[]' => [ "$dirs/$file" ]});
|
{'filenames[]' => [ "$dirs/$file" ]});
|
||||||
$tx->req->headers->authorization("Bearer $api");
|
$tx->req->headers->authorization("Bearer $api");
|
||||||
my $res = $ua->start($tx)->res;
|
$res = $ua->start($tx)->res;
|
||||||
}
|
}
|
||||||
|
|
||||||
$suppress_list_update = 1;
|
$suppress_list_update = 1;
|
||||||
|
@ -304,7 +362,7 @@ sub e_mkdir {
|
||||||
# my $numb = int(rand(99999999)) . 'mkdir_hopefully_no_collsions.html';
|
# my $numb = int(rand(99999999)) . 'mkdir_hopefully_no_collsions.html';
|
||||||
#
|
#
|
||||||
# $suppress_list_update = 1;
|
# $suppress_list_update = 1;
|
||||||
# my $res = e_mknod("$dirs/$file/$numb");
|
# $res = e_mknod("$dirs/$file/$numb");
|
||||||
#
|
#
|
||||||
# $suppress_list_update = 0;
|
# $suppress_list_update = 0;
|
||||||
# return res_errno($res,0) if $res != 0;
|
# return res_errno($res,0) if $res != 0;
|
||||||
|
@ -392,7 +450,7 @@ sub e_rename {
|
||||||
sub res_errno {
|
sub res_errno {
|
||||||
my ($res, $buf_len) = @_;
|
my ($res, $buf_len) = @_;
|
||||||
if ($res->is_success) {
|
if ($res->is_success) {
|
||||||
my $res = get_listing_from_neocities();
|
get_listing_from_neocities();
|
||||||
return $buf_len;
|
return $buf_len;
|
||||||
}
|
}
|
||||||
elsif ($res->code == 400) {
|
elsif ($res->code == 400) {
|
||||||
|
@ -425,10 +483,22 @@ sub res_errno {
|
||||||
|
|
||||||
# this returns mojo's 'res' thing
|
# this returns mojo's 'res' thing
|
||||||
sub write_to_neocities {
|
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 $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);
|
my ($tx, $res);
|
||||||
if ($pass) {
|
if ($pass) {
|
||||||
$tx = $ua->post("https://$user:$pass\@neocities.org/api/upload" =>
|
$tx = $ua->post("https://$user:$pass\@neocities.org/api/upload" =>
|
||||||
|
@ -441,6 +511,7 @@ sub write_to_neocities {
|
||||||
$tx->req->headers->authorization("Bearer $api");
|
$tx->req->headers->authorization("Bearer $api");
|
||||||
$res = $ua->start($tx)->res;
|
$res = $ua->start($tx)->res;
|
||||||
}
|
}
|
||||||
|
undef $asset;
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,6 +533,12 @@ Fuse::main(
|
||||||
mkdir =>"main::e_mkdir",
|
mkdir =>"main::e_mkdir",
|
||||||
rmdir =>"main::e_rmdir",
|
rmdir =>"main::e_rmdir",
|
||||||
rename =>"main::e_rename",
|
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,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue