fix bug that cut files short (wasn't hot flushing and then file handle closed before perl saw a newline) and make truncate less spooky
yoink naughty file
This commit is contained in:
parent
d58be4e039
commit
3dcbb3251f
1 changed files with 18 additions and 15 deletions
|
@ -279,6 +279,7 @@ sub e_write {
|
||||||
($files{$dirs}{$file}{fh}, $files{$dirs}{$file}{fn}) = tempfile();
|
($files{$dirs}{$file}{fh}, $files{$dirs}{$file}{fn}) = tempfile();
|
||||||
}
|
}
|
||||||
my $fh2 = $files{$dirs}{$file}{fh};
|
my $fh2 = $files{$dirs}{$file}{fh};
|
||||||
|
$fh2->autoflush( 1 ); # perl doesnt 'print line' until it sees "\n" normally
|
||||||
seek $fh2, $off, 0;
|
seek $fh2, $off, 0;
|
||||||
print $fh2 $buf;
|
print $fh2 $buf;
|
||||||
|
|
||||||
|
@ -287,8 +288,6 @@ sub e_write {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub e_flush {
|
sub e_flush {
|
||||||
### @_
|
|
||||||
### %files
|
|
||||||
my ($path, $_fh) = @_;
|
my ($path, $_fh) = @_;
|
||||||
my ($dirs, $file) = get_path_and_file($path);
|
my ($dirs, $file) = get_path_and_file($path);
|
||||||
if (exists $files{$dirs}{$file}{fh}) {
|
if (exists $files{$dirs}{$file}{fh}) {
|
||||||
|
@ -296,8 +295,8 @@ sub e_flush {
|
||||||
my $res = write_to_neocities($dirs, $file, $fn, 1);
|
my $res = write_to_neocities($dirs, $file, $fn, 1);
|
||||||
close $files{$dirs}{$file}{fh};
|
close $files{$dirs}{$file}{fh};
|
||||||
delete $files{$dirs}{$file}{fh};
|
delete $files{$dirs}{$file}{fh};
|
||||||
delete $files{$dirs}{$file}{fn};
|
|
||||||
unlink $files{$dirs}{$file}{fn};
|
unlink $files{$dirs}{$file}{fn};
|
||||||
|
delete $files{$dirs}{$file}{fn};
|
||||||
return res_errno($res, 0);
|
return res_errno($res, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -307,15 +306,21 @@ sub e_not_implimented { return -ENOSYS; }
|
||||||
sub e_lie_implimented { return 0; }
|
sub e_lie_implimented { return 0; }
|
||||||
|
|
||||||
sub e_truncate {
|
sub e_truncate {
|
||||||
my ($path, $how_much) = @_;
|
my ($path, $length) = @_;
|
||||||
my ($dirs, $file) = get_path_and_file($path);
|
my ($dirs, $file) = get_path_and_file($path);
|
||||||
return -ENOENT if ! exists $files{$dirs}{$file};
|
return -ENOENT if ! exists $files{$dirs}{$file};
|
||||||
### XXX DRAGONS HERE
|
|
||||||
my $path_to_thing = $mountpoint ."/$path";
|
if ($length == 0) { # truncate entire file
|
||||||
### $path_to_thing
|
e_write($path, '');
|
||||||
open my $fh, '>', $path_to_thing or return -ENOENT;
|
my $res = e_flush($path);
|
||||||
truncate $fh, $how_much;
|
return $res;
|
||||||
close $fh;
|
}
|
||||||
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,20 +490,18 @@ sub res_errno {
|
||||||
sub write_to_neocities {
|
sub write_to_neocities {
|
||||||
my ($dirs, $file, $buffer, $is_buf_fn) = @_;
|
my ($dirs, $file, $buffer, $is_buf_fn) = @_;
|
||||||
defined $is_buf_fn or $is_buf_fn = 0;
|
defined $is_buf_fn or $is_buf_fn = 0;
|
||||||
|
|
||||||
|
|
||||||
my $ua = Mojo::UserAgent->new();
|
my $ua = Mojo::UserAgent->new();
|
||||||
my $asset;
|
my $asset;
|
||||||
if (! $is_buf_fn) {
|
if (! $is_buf_fn) {
|
||||||
### write_to_neocities
|
|
||||||
### buf _IS NOT_ fn
|
|
||||||
$asset = Mojo::Asset::Memory->new->add_chunk($buffer);
|
$asset = Mojo::Asset::Memory->new->add_chunk($buffer);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
### write_to_neocities
|
|
||||||
### buf _IS_ fn
|
|
||||||
$asset = Mojo::Asset::File->new(path => $buffer);
|
$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" =>
|
||||||
|
@ -540,5 +543,5 @@ Fuse::main(
|
||||||
chown =>"main::e_not_implimented",
|
chown =>"main::e_not_implimented",
|
||||||
chmod =>"main::e_not_implimented",
|
chmod =>"main::e_not_implimented",
|
||||||
threaded=>0,
|
threaded=>0,
|
||||||
debug=>1,
|
#debug=>1,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue