diff options
-rwxr-xr-x | neocitiesfs.pl | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/neocitiesfs.pl b/neocitiesfs.pl index 048f37a..c9c0225 100755 --- a/neocitiesfs.pl +++ b/neocitiesfs.pl @@ -279,6 +279,7 @@ sub e_write { ($files{$dirs}{$file}{fh}, $files{$dirs}{$file}{fn}) = tempfile(); } my $fh2 = $files{$dirs}{$file}{fh}; + $fh2->autoflush( 1 ); # perl doesnt 'print line' until it sees "\n" normally seek $fh2, $off, 0; print $fh2 $buf; @@ -287,8 +288,6 @@ sub e_write { } sub e_flush { - ### @_ - ### %files my ($path, $_fh) = @_; my ($dirs, $file) = get_path_and_file($path); if (exists $files{$dirs}{$file}{fh}) { @@ -296,8 +295,8 @@ sub e_flush { 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}; + delete $files{$dirs}{$file}{fn}; return res_errno($res, 0); } } @@ -307,15 +306,21 @@ sub e_not_implimented { return -ENOSYS; } sub e_lie_implimented { return 0; } sub e_truncate { - my ($path, $how_much) = @_; + my ($path, $length) = @_; 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; + + if ($length == 0) { # truncate entire file + e_write($path, ''); + my $res = e_flush($path); + return $res; + } + else { + e_write($path, e_read($path,0,0), 0, 0); + truncate $files{$dirs}{$file}{fh}, $length; + my $res = e_flush($path); + return $res; + } return 0; } @@ -485,20 +490,18 @@ sub res_errno { sub write_to_neocities { my ($dirs, $file, $buffer, $is_buf_fn) = @_; defined $is_buf_fn or $is_buf_fn = 0; + my $ua = Mojo::UserAgent->new(); 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" => @@ -540,5 +543,5 @@ Fuse::main( chown =>"main::e_not_implimented", chmod =>"main::e_not_implimented", threaded=>0, - debug=>1, + #debug=>1, ); |