aboutsummaryrefslogtreecommitdiff
path: root/mime-node.c
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2022-07-01 18:45:44 -0300
committerDavid Bremner <david@tethera.net>2022-07-30 08:41:50 -0300
commit4612f3eb3dbf16bf98ccbadef77d7a6f6361e692 (patch)
tree11f6350c5731fe3777d66cbb87e198377c0c342e /mime-node.c
parentcef5eaaef61b1f4dde6276ef267fb923f1b16680 (diff)
CLI/show: support --duplicate for structured output
This introduces a new mandatory key for message structures, namely "duplicate". Per convention in devel/schemata this does _not_ increase the format version. This means that clients are responsible for checking that it exists, and not crashing if it does not. The main functional change is teaching mime_node_open to understand a 'duplicate' argument. Support for --duplicate in notmuch-reply would make sense, but we defer it to a later commit.
Diffstat (limited to 'mime-node.c')
-rw-r--r--mime-node.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/mime-node.c b/mime-node.c
index d29c4e48..1c5d619b 100644
--- a/mime-node.c
+++ b/mime-node.c
@@ -78,13 +78,14 @@ mime_node_get_message_crypto_status (mime_node_t *node)
notmuch_status_t
mime_node_open (const void *ctx, notmuch_message_t *message,
+ int duplicate,
_notmuch_crypto_t *crypto, mime_node_t **root_out)
{
const char *filename = notmuch_message_get_filename (message);
mime_node_context_t *mctx;
mime_node_t *root;
notmuch_status_t status;
- int fd;
+ int fd = -1;
root = talloc_zero (ctx, mime_node_t);
if (root == NULL) {
@@ -103,20 +104,33 @@ mime_node_open (const void *ctx, notmuch_message_t *message,
talloc_set_destructor (mctx, _mime_node_context_free);
/* Fast path */
- fd = open (filename, O_RDONLY);
+ if (duplicate <= 0)
+ fd = open (filename, O_RDONLY);
if (fd == -1) {
- /* Slow path - for some reason the first file in the list is
- * not available anymore. This is clearly a problem in the
+ /* Slow path - Either we are trying to open a specific file, or
+ * for some reason the first file in the list is
+ * not available anymore. The latter is clearly a problem in the
* database, but we are not going to let this problem be a
* show stopper */
notmuch_filenames_t *filenames;
+ int i = 1;
+
for (filenames = notmuch_message_get_filenames (message);
notmuch_filenames_valid (filenames);
- notmuch_filenames_move_to_next (filenames)) {
- filename = notmuch_filenames_get (filenames);
- fd = open (filename, O_RDONLY);
- if (fd != -1)
- break;
+ notmuch_filenames_move_to_next (filenames), i++) {
+ if (i >= duplicate) {
+ filename = notmuch_filenames_get (filenames);
+ fd = open (filename, O_RDONLY);
+ if (fd != -1) {
+ break;
+ } else {
+ if (duplicate > 0) {
+ fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));
+ status = NOTMUCH_STATUS_FILE_ERROR;
+ goto DONE;
+ }
+ }
+ }
}
talloc_free (filenames);