0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd::fs: Add append(fd) with explicit lseek(SEEK_END).

This commit is contained in:
Jason Volk 2018-05-30 02:40:20 -07:00
parent 3854bbaedd
commit f8ea91cdee
2 changed files with 28 additions and 3 deletions

View file

@ -19,11 +19,12 @@ namespace ircd::fs
const_buffer write(const fd &, const const_buffer &, const write_opts & = write_opts_default);
const_buffer write(const string_view &path, const const_buffer &, const write_opts & = write_opts_default);
// Yields ircd::ctx to append to file from buffer; returns view of written portion
const_buffer append(const fd &, const const_buffer &, const write_opts & = write_opts_default);
const_buffer append(const string_view &path, const const_buffer &, const write_opts & = write_opts_default);
// Yields ircd::ctx to overwrite (trunc) file from buffer; returns view of written portion
const_buffer overwrite(const string_view &path, const const_buffer &, const write_opts & = write_opts_default);
// Yields ircd::ctx to append to file from buffer; returns view of written portion
const_buffer append(const string_view &path, const const_buffer &, const write_opts & = write_opts_default);
}
/// Options for a write operation

View file

@ -220,6 +220,30 @@ ircd::fs::write_opts
const ircd::fs::write_opts_default
{};
ircd::const_buffer
ircd::fs::append(const fd &fd,
const const_buffer &buf,
const write_opts &opts_)
try
{
assert(opts_.offset == 0);
auto opts(opts_);
opts.offset = syscall(::lseek, fd, 0, SEEK_END);
return write(fd, buf, opts);
}
catch(const filesystem_error &)
{
throw;
}
catch(const std::exception &e)
{
throw filesystem_error
{
"%s", e.what()
};
}
ircd::const_buffer
ircd::fs::write(const string_view &path,
const const_buffer &buf,