/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "str.h"
#include "strescape.h"
#include "istream.h"
#include "istream-private.h"
#include "istream-concat.h"
#include "istream-metawrap.h"
#include "ostream.h"
#include "ostream-metawrap.h"
#include "iostream-temp.h"
#include "fs-api-private.h"
struct metawrap_fs {
bool wrap_metadata;
};
struct metawrap_fs_file {
bool metadata_read;
};
{
}
static int
struct fs_settings *set)
{
if (*args == '\0') {
return -1;
}
if (parent_args == NULL) {
parent_name = args;
parent_args = "";
} else {
parent_args++;
}
return -1;
}
return 0;
}
{
}
{
if (fs->wrap_metadata) {
/* we don't have a quick stat() to see the file's size,
because of the metadata header */
props &= ~FS_PROPERTY_STAT;
/* Copying can copy the whole metadata. */
}
return props;
}
{
}
static void
{
/* avoid unnecessarily creating two seekable streams */
(flags & FS_OPEN_FLAG_ASYNC) == 0) {
/* use async stream for parent, so fs_read_stream() won't create
another seekable stream needlessly */
} else {
}
}
{
}
{
}
static void
const char *value)
{
else {
}
}
static int
{
char c;
if (file->metadata_read) {
/* we have the metadata */
return -1;
} else {
/* use the existing istream to read it */
if (file->metadata_read)
break;
}
return -1;
}
}
return 0;
}
{
else
}
{
}
static void
{
return;
}
T_BEGIN {
} T_END;
}
static struct istream *
{
}
}
{
}
static void
{
strlen(FS_METADATA_INTERNAL_PREFIX)) == 0)
continue;
}
}
static void
{
if (ret < 0)
else
}
{
}
{
} else {
file->temp_output =
}
}
static struct istream *
{
else
i_stream_unref(&inputs[0]);
return input2;
}
{
int ret;
else
}
if (!success) {
/* no metawrap */
} else {
}
return -1;
}
/* no metawrap */
}
/* finishing up */
}
/* finish writing the temporary file */
/* empty file - temp_output is already finished,
so we can't write to it. */
} else {
}
if (file->metadata_changed_since_write) {
/* we'll need to recreate the metadata. do this by creating a
new istream combining the new metadata header and the
old body. */
}
/* because of the "end of metadata" LF, there's always at least
1 byte */
return ret;
}
{
if (file->metadata_write_size != 0) {
/* fs_stat() after a write. we can do this quickly. */
return -1;
"Just-written %s shrank unexpectedly "
return -1;
}
return 0;
}
else {
}
return -1;
}
if (ret == 0) {
/* we shouldn't get here */
return -1;
}
return -1;
}
return 0;
}
{
else
}
.name = "metawrap",
.v = {
NULL,
}
};