#include "array.h"
#include "module-dir.h"
#include "str.h"
+#include "hash-method.h"
#include "istream.h"
#include "istream-seekable.h"
#include "ostream.h"
i_stream_unref(&file->copy_input);
(void)fs_write_stream_abort(file, &file->copy_output);
}
+ i_free_and_null(file->write_digest);
if (file->fs->v.file_close != NULL) T_BEGIN {
file->fs->v.file_close(file);
} T_END;
file->fs->v.get_path(file);
}
+struct fs *fs_file_fs(struct fs_file *file)
+{
+ return file->fs;
+}
+
static void ATTR_FORMAT(2, 0)
fs_set_verror(struct fs *fs, const char *fmt, va_list args)
{
} T_END;
}
+void fs_write_set_hash(struct fs_file *file, const struct hash_method *method,
+ const void *digest)
+{
+ file->write_digest_method = method;
+
+ i_free(file->write_digest);
+ file->write_digest = i_malloc(method->digest_size);
+ memcpy(file->write_digest, digest, method->digest_size);
+}
+
void fs_file_set_async_callback(struct fs_file *file,
fs_file_async_callback_t *callback,
void *context)
struct fs;
struct fs_file;
struct fs_lock;
+struct hash_method;
enum fs_properties {
FS_PROPERTY_METADATA = 0x01,
FS_PROPERTY_RELIABLEITER= 0x40,
/* Backend uses directories, which aren't automatically deleted
when its children are deleted. */
- FS_PROPERTY_DIRECTORIES = 0x80
+ FS_PROPERTY_DIRECTORIES = 0x80,
+ FS_PROPERTY_WRITE_HASH_MD5 = 0x100,
+ FS_PROPERTY_WRITE_HASH_SHA256 = 0x200
};
enum fs_open_mode {
FS_OPEN_MODE_CREATE_UNIQUE_128 and the write has already finished,
return the path including the generated filename. */
const char *fs_file_path(struct fs_file *file);
+/* Returns the file's fs. */
+struct fs *fs_file_fs(struct fs_file *file);
/* Return the error message for the last failed operation. */
const char *fs_last_error(struct fs *fs);
/* Abort writing via stream. Anything written to the stream is discarded. */
void fs_write_stream_abort(struct fs_file *file, struct ostream **output);
+/* Set a hash to the following write. The storage can then verify that the
+ input data matches the specified hash, or fail if it doesn't. Typically
+ implemented by Content-MD5 header. */
+void fs_write_set_hash(struct fs_file *file, const struct hash_method *method,
+ const void *digest);
+
/* Call the specified callback whenever the file can be read/written to.
May call the callback immediately. */
void fs_file_set_async_callback(struct fs_file *file,