From 71ff0620ce4841ff2e846441b30dd4f1dd3cc3e5 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Fri, 11 Jul 2014 19:59:01 +0200 Subject: [PATCH] Sort the dir alphabetically if explicitely requested. This ensures that the test is independent of the directory order of the files. --- Makefile.am | 23 +++++++++++++++++++++-- cmdline/scan.c | 18 ++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index bb560eb1..3b405bc4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -121,11 +121,30 @@ maintainer-clean-local: # Automatic testing +# Base options +# --test-skip-device +# Is required to allow testing in the same disk +# +# --test-skip-self +# It just makes the test a little faster +# +# --test-force-order-alpha +# Ensures to process files always in the same order despites +# the inode, physical location, and dir order assigned by the OS. CHECKFLAGS_BASE = --test-skip-device --test-skip-self --test-force-order-alpha + +# Verbose options CHECKFLAGS_VERBOSE = $(CHECKFLAGS_BASE) -v -G + +# Quiet options CHECKFLAGS = $(CHECKFLAGS_BASE) -q + +# Number of files to create CHECKCOUNT = 1000 + +# Size of files to create CHECKSIZE = 4000 + CONF = $(srcdir)/test/test-par6.conf HOLE = $(srcdir)/test/test-par6-hole.conf PAR1 = $(srcdir)/test/test-par1.conf @@ -174,7 +193,7 @@ endif echo DUP > bench/disk1/DUP1 echo DUP > bench/disk1/DUP2 $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) diff > output.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-force-order-physical sync + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) sync echo --- Some commands with a not empty array $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) dup -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(CONF) list -l test.log > output.log @@ -241,7 +260,7 @@ endif ln bench/disk3/file_hardlink1 bench/disk3/file_hardlink2 ln bench/disk3/file_hardlink1 bench/disk3/file_hardlink3 $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS_VERBOSE) -c $(PAR1) diff > output.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-fallocate -c $(PAR1) --test-force-order-inode sync + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-fallocate -c $(PAR1) sync $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-sequential -c $(PAR1) check echo --- Some commands with a not empty array diff --git a/cmdline/scan.c b/cmdline/scan.c index 59a9ec15..9773541e 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -894,6 +894,14 @@ static int dd_ino_compare(const void* void_a, const void* void_b) } #endif +static int dd_name_compare(const void* void_a, const void* void_b) +{ + const struct dirent_sorted* a = void_a; + const struct dirent_sorted* b = void_b; + + return strcmp(a->d_name, b->d_name); +} + /** * Returns the stat info of a dir entry. */ @@ -1024,11 +1032,17 @@ static int scan_dir(struct snapraid_scan* scan, int output, const char* dir, con } #if HAVE_STRUCT_DIRENT_D_INO - /* if inodes are persistent */ - if (!disk->has_volatile_inodes) { + if (state->opt.force_order == SORT_ALPHA) { + /* if requested sort alphabetically */ + /* this is mainly done for testing to ensure to always */ + /* process in the same way in different platforms */ + tommy_list_sort(&list, dd_name_compare); + } else if (!disk->has_volatile_inodes) { + /* if inodes are persistent */ /* sort the list of dir entries by inodes */ tommy_list_sort(&list, dd_ino_compare); } + /* otherwise just keep the insertion order */ #endif /* process the sorted dir entries */