vfs: add append mode to New_file

genodelabs/genode#4352
This commit is contained in:
Johannes Schlatow
2021-08-02 17:17:28 +02:00
committed by Christian Helmuth
parent 2e266dfe3c
commit cf904e0a5d

View File

@@ -683,7 +683,9 @@ class Genode::New_file : Noncopyable
Vfs::File_system &_fs; Vfs::File_system &_fs;
Vfs::Vfs_handle &_handle; Vfs::Vfs_handle &_handle;
Vfs::Vfs_handle &_init_handle(Directory &dir, Directory::Path const &rel_path) Vfs::Vfs_handle &_init_handle(Directory &dir,
Directory::Path const &rel_path,
bool append)
{ {
/* create compound directory */ /* create compound directory */
{ {
@@ -708,7 +710,11 @@ class Genode::New_file : Noncopyable
throw Create_failed(); throw Create_failed();
} }
handle_ptr->fs().ftruncate(handle_ptr, 0); Vfs::Directory_service::Stat stat { };
if (!append)
handle_ptr->fs().ftruncate(handle_ptr, 0);
else if (handle_ptr->ds().stat(path.string(), stat) == Vfs::Directory_service::STAT_OK)
handle_ptr->seek(stat.size);
return *handle_ptr; return *handle_ptr;
} }
@@ -720,10 +726,10 @@ class Genode::New_file : Noncopyable
* *
* \throw Create_failed * \throw Create_failed
*/ */
New_file(Directory &dir, Directory::Path const &path) New_file(Directory &dir, Directory::Path const &path, bool append = false)
: :
_ep(dir._ep), _alloc(dir._alloc), _fs(dir._fs), _ep(dir._ep), _alloc(dir._alloc), _fs(dir._fs),
_handle(_init_handle(dir, path)) _handle(_init_handle(dir, path, append))
{ } { }
~New_file() ~New_file()