aboutsummaryrefslogtreecommitdiff
path: root/mkfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-16 19:52:42 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-18 22:44:39 +0200
commitb45850388ea5505f4fd50cd659abe2f02aeca0b5 (patch)
tree994f878caf990d1569831762f0b0f4d787ab9839 /mkfs
parent1a95478b8d340c8b6b9dbff4f38f9293388fd1a3 (diff)
cleanup: internalize deduplication list in data_writer
This change removes the need for passing a list of files around for deduplication. Also the deduplication code no longer needs to worry about order, since the file being deduplicated is only added after deduplication is done. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'mkfs')
-rw-r--r--mkfs/mkfs.c39
1 files changed, 17 insertions, 22 deletions
diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c
index 8ee2268..3dc9efb 100644
--- a/mkfs/mkfs.c
+++ b/mkfs/mkfs.c
@@ -6,26 +6,6 @@
*/
#include "mkfs.h"
-static int process_file(data_writer_t *data, file_info_t *fi, bool quiet,
- file_info_t *list)
-{
- int ret, infd;
-
- if (!quiet)
- printf("packing %s\n", fi->input_file);
-
- infd = open(fi->input_file, O_RDONLY);
- if (infd < 0) {
- perror(fi->input_file);
- return -1;
- }
-
- ret = write_data_from_fd(data, fi, infd, 0, list);
-
- close(infd);
- return ret;
-}
-
static int set_working_dir(options_t *opt)
{
const char *ptr;
@@ -51,12 +31,27 @@ static int restore_working_dir(options_t *opt)
static int pack_files(data_writer_t *data, fstree_t *fs, options_t *opt)
{
file_info_t *fi;
+ int ret, infd;
if (set_working_dir(opt))
return -1;
- for (fi = fs->files; fi != NULL; fi = fi->next) {
- if (process_file(data, fi, opt->quiet, fs->files))
+ while (fs->files != NULL) {
+ fi = fs->files;
+ fs->files = fi->next;
+
+ if (!opt->quiet)
+ printf("packing %s\n", fi->input_file);
+
+ infd = open(fi->input_file, O_RDONLY);
+ if (infd < 0) {
+ perror(fi->input_file);
+ return -1;
+ }
+
+ ret = write_data_from_fd(data, fi, infd, 0);
+ close(infd);
+ if (ret)
return -1;
}