aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-04-16 05:13:50 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-04-16 05:17:29 +0200
commit6b3e6d299d5298a5936dbba57f67cdfc4a406789 (patch)
tree28efefb83f05abbe4edd3944e2019a1d79669833
parent943dc3fa216913bff7e2dd267a9f52f082c04663 (diff)
tar2sqfs & gensquashfs: Delete the output file on failure
This commit changes the tar2sqfs & gensquashfs code to pass the exit status on to sqfs_writer_cleanup in libcommon. The function sqfs writer code in libcommon is changed to retain the output file name and delete it if the status passed to the cleanup function is anything other than EXIT_SUCCESS. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/common.h3
-rw-r--r--lib/common/writer.c17
-rw-r--r--mkfs/mkfs.c2
-rw-r--r--tar/tar2sqfs.c2
4 files changed, 20 insertions, 4 deletions
diff --git a/include/common.h b/include/common.h
index 2ecea42..0cc45c8 100644
--- a/include/common.h
+++ b/include/common.h
@@ -35,6 +35,7 @@
#include <stddef.h>
typedef struct {
+ const char *filename;
sqfs_block_writer_t *blkwr;
sqfs_frag_table_t *fragtbl;
sqfs_block_processor_t *data;
@@ -125,7 +126,7 @@ int sqfs_writer_init(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *wrcfg);
int sqfs_writer_finish(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *cfg);
-void sqfs_writer_cleanup(sqfs_writer_t *sqfs);
+void sqfs_writer_cleanup(sqfs_writer_t *sqfs, int status);
void sqfs_perror(const char *file, const char *action, int error_code);
diff --git a/lib/common/writer.c b/lib/common/writer.c
index 84a98a5..a446c41 100644
--- a/lib/common/writer.c
+++ b/lib/common/writer.c
@@ -70,6 +70,8 @@ int sqfs_writer_init(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *wrcfg)
sqfs_compressor_config_t cfg;
int ret, flags;
+ sqfs->filename = wrcfg->filename;
+
if (compressor_cfg_init_options(&cfg, wrcfg->comp_id,
wrcfg->block_size,
wrcfg->comp_extra)) {
@@ -296,7 +298,7 @@ int sqfs_writer_finish(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *cfg)
return 0;
}
-void sqfs_writer_cleanup(sqfs_writer_t *sqfs)
+void sqfs_writer_cleanup(sqfs_writer_t *sqfs, int status)
{
if (sqfs->xwr != NULL)
sqfs_destroy(sqfs->xwr);
@@ -311,4 +313,17 @@ void sqfs_writer_cleanup(sqfs_writer_t *sqfs)
sqfs_destroy(sqfs->cmp);
fstree_cleanup(&sqfs->fs);
sqfs_destroy(sqfs->outfile);
+
+ if (status != EXIT_SUCCESS) {
+#if defined(_WIN32) || defined(__WINDOWS__)
+ WCHAR *path = path_to_windows(sqfs->filename);
+
+ if (path != NULL)
+ DeleteFileW(path);
+
+ free(path);
+#else
+ unlink(sqfs->filename);
+#endif
+ }
}
diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c
index 0ef65ca..9ffbb94 100644
--- a/mkfs/mkfs.c
+++ b/mkfs/mkfs.c
@@ -211,6 +211,6 @@ int main(int argc, char **argv)
status = EXIT_SUCCESS;
out:
- sqfs_writer_cleanup(&sqfs);
+ sqfs_writer_cleanup(&sqfs, status);
return status;
}
diff --git a/tar/tar2sqfs.c b/tar/tar2sqfs.c
index 6186930..1ebe642 100644
--- a/tar/tar2sqfs.c
+++ b/tar/tar2sqfs.c
@@ -539,6 +539,6 @@ int main(int argc, char **argv)
status = EXIT_SUCCESS;
out:
- sqfs_writer_cleanup(&sqfs);
+ sqfs_writer_cleanup(&sqfs, status);
return status;
}