Skip to content

Commit

Permalink
freemount-server: Support slurp-only file reads
Browse files Browse the repository at this point in the history
  • Loading branch information
jjuran committed Feb 6, 2021
1 parent 4c907eb commit ce06d29
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion server/freemount-server/freemount/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "vfs/primitives/hardlink.hh"
#include "vfs/primitives/listdir.hh"
#include "vfs/primitives/open.hh"
#include "vfs/primitives/slurp.hh"
#include "vfs/primitives/stat.hh"

// freemount
Expand Down Expand Up @@ -172,6 +173,27 @@ int close( session& s, uint8_t r_id, const request& r )
return 0;
}

static
int read_slurp( session& s, uint8_t r_id, const vfs::node& that )
{
// No need to try/catch, because we're called from read()'s try block

plus::string bytes = slurp( that );

const uint64_t size = bytes.size();

data_transmitting( size );

send_lock lock;

queue_int ( s.queue(), Frame_stat_size, size, r_id );
queue_string( s.queue(), Frame_recv_data, bytes.data(), size, r_id );

s.queue().flush();

return 0;
}

static
int read( session& s, uint8_t r_id, const request& r )
{
Expand All @@ -181,7 +203,19 @@ int read( session& s, uint8_t r_id, const request& r )
{
vfs::node_ptr that = vfs::resolve_pathname( s.root(), r.path, s.cwd() );

file = open( *that, O_RDONLY, 0 );
try
{
file = open( *that, O_RDONLY, 0 );
}
catch ( const p7::errno_t& err )
{
if ( err == ENOENT )
{
return read_slurp( s, r_id, *that );
}

return -err;
}

if ( S_ISREG( that->filemode() ) )
{
Expand Down

0 comments on commit ce06d29

Please sign in to comment.