Skip to content

Commit 7eca83d

Browse files
committed
Add ordered directory traversal
1 parent 3b99f4a commit 7eca83d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Process this file with autoconf to produce a configure script.
33

44
AC_PREREQ(2.59)
5-
AC_INIT([genext2fs], [1.4.2])
5+
AC_INIT([genext2fs], [1.5.1])
66
AC_CONFIG_SRCDIR([genext2fs.c])
77

88
builtin(include, [m4/ac_func_snprintf.m4])dnl

genext2fs.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,17 +2766,17 @@ add2fs_from_dir(filesystem *fs, uint32 this_nod, int squash_uids, int squash_per
27662766
uint32 uid, gid, mode, ctime, mtime;
27672767
const char *name;
27682768
FILE *fh;
2769-
DIR *dh;
2770-
struct dirent *dent;
2769+
struct dirent **dents = NULL;
27712770
struct stat st;
27722771
char *lnk;
2773-
uint32 save_nod;
2772+
uint32 save_nod, numdirs, i;
27742773
off_t filesize;
27752774

2776-
if(!(dh = opendir(".")))
2775+
if((numdirs = scandir(".", &dents, NULL, alphasort)) == -1)
27772776
perror_msg_and_die(".");
2778-
while((dent = readdir(dh)))
2777+
for (i = 0; i < numdirs; ++i)
27792778
{
2779+
struct dirent *dent = dents[i];
27802780
if((!strcmp(dent->d_name, ".")) || (!strcmp(dent->d_name, "..")))
27812781
continue;
27822782
lstat(dent->d_name, &st);
@@ -2907,7 +2907,7 @@ add2fs_from_dir(filesystem *fs, uint32 this_nod, int squash_uids, int squash_per
29072907
}
29082908
}
29092909
}
2910-
closedir(dh);
2910+
free(dents);
29112911
}
29122912

29132913
// Copy size blocks from src to dst, putting holes in the output

0 commit comments

Comments
 (0)