From 08e7cfd8eba4902d6749e6bcd6befc06174aa59c Mon Sep 17 00:00:00 2001 From: Max Wash Date: Mon, 24 Feb 2025 15:43:40 +0000 Subject: [PATCH] add a flag to ec3_image_ioctx_open to always delete an existing image if it already exists --- src/image.c | 6 ++++++ src/image.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/image.c b/src/image.c index fe2b8ca..1fd0ea3 100644 --- a/src/image.c +++ b/src/image.c @@ -347,6 +347,12 @@ enum ec3_status ec3_image_ioctx_open( } b_path *image_path = b_path_create_from_cstr(path); + + if (mode & EC3_IMAGE_IO_TRUNCATE) { + b_path_unlink(image_path); + mode &= ~EC3_IMAGE_IO_TRUNCATE; + } + b_file_info image_info; enum b_status status = b_path_stat(image_path, &image_info); enum ec3_status status2 = EC3_ERR_NO_ENTRY; diff --git a/src/image.h b/src/image.h index e2ab370..7700eae 100644 --- a/src/image.h +++ b/src/image.h @@ -63,6 +63,7 @@ enum ec3_image_ioctx_mode { EC3_IMAGE_IO_READ = 0x01u, EC3_IMAGE_IO_WRITE = 0x02u, EC3_IMAGE_IO_READWRITE = EC3_IMAGE_IO_READ | EC3_IMAGE_IO_WRITE, + EC3_IMAGE_IO_TRUNCATE = 0x04u, }; struct ec3_image_ioctx {