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:
parent
3854bbaedd
commit
f8ea91cdee
|
@ -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
|
||||
|
|
24
ircd/fs.cc
24
ircd/fs.cc
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue