Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ordered directory traversal #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions genext2fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2766,17 +2766,17 @@ add2fs_from_dir(filesystem *fs, uint32 this_nod, int squash_uids, int squash_per
uint32 uid, gid, mode, ctime, mtime;
const char *name;
FILE *fh;
DIR *dh;
struct dirent *dent;
struct dirent **dents = NULL;
struct stat st;
char *lnk;
uint32 save_nod;
uint32 save_nod, numdirs, i;
off_t filesize;

if(!(dh = opendir(".")))
if((numdirs = scandir(".", &dents, NULL, alphasort)) == -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alphasort is locale aware. You need to set LC_COLLATE to a fixed value like C to produce the same output independent of the user's locale

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The man page states that this is already the default behavior. Would you rather make it explicit?

...
On startup of the main program, the portable "C" locale is selected as default.
...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right!

perror_msg_and_die(".");
while((dent = readdir(dh)))
for (i = 0; i < numdirs; ++i)
{
struct dirent *dent = dents[i];
if((!strcmp(dent->d_name, ".")) || (!strcmp(dent->d_name, "..")))
continue;
lstat(dent->d_name, &st);
Expand Down Expand Up @@ -2906,8 +2906,9 @@ add2fs_from_dir(filesystem *fs, uint32 this_nod, int squash_uids, int squash_per
fs->hdlinks.count++;
}
}
free(dent);
}
closedir(dh);
free(dents);
mpolitzer marked this conversation as resolved.
Show resolved Hide resolved
}

// Copy size blocks from src to dst, putting holes in the output
Expand Down
6 changes: 5 additions & 1 deletion test-gen.lib
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ calc_digest () {
# dgen - Exercises the -d option of genext2fs.
# Creates an image with a file of given size.
dgen () {
gen_setup
dgen_raw $@
}

dgen_raw () {
blocks=$1; blocksz=$2; size=$3
echo Testing $blocks blocks of $blocksz bytes with file of size $size
gen_setup
cd $test_dir
if [ x$size = x0 ]; then
> file.$size
Expand Down
19 changes: 19 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ dtest () {
gen_cleanup
}

dtest_s () {
expected_digest=$1
shift
reversed=$1;
shift

gen_setup
ROOTDIR=$(mktemp -d)
TZ=UTC-11 touch -t 200502070321.43 $ROOTDIR/a $ROOTDIR/b $ROOTDIR/c $ROOTDIR

disorderfs --sort-dirents=yes --reverse-dirents="$reversed" "$ROOTDIR" "$test_dir"
dgen_raw $@
fusermount -u $test_dir
md5cmp $expected_digest
gen_cleanup
}

ftest () {
expected_digest=$1
shift
Expand Down Expand Up @@ -87,3 +104,5 @@ ltest c21b5a3cad405197e821ba7143b0ea9b 200 1024 123456789 device_table_link.txt
ltest 18b04b4bea2f7ebf315a116be5b92589 200 1024 1234567890 device_table_link.txt
ltest 8aaed693b75dbdf77607f376d661027a 200 4096 12345678901 device_table_link.txt
atest 994ca42d3179c88263af777bedec0c55 200 1024 H4sIAAAAAAAAA+3WTW6DMBAF4Fn3FD6B8fj3PKAqahQSSwSk9vY1uKssGiJliFretzECJAYeY1s3JM4UKYRlLG7H5ZhdTIHZGevK+ZTYkgrypRFN17EdlKIh5/G3++5d/6N004qbA47er8/fWVduV2aLD7D7/A85C88Ba/ufA/sQIhk25VdA/2+h5t+1gx4/pd7vfv+Hm/ytmfNH/8vr+ql7e3UR8DK6uUx9L/uMtev/3P8p+KX/oyHlZMuqntX/9T34Z9yk9Gco8//xkGWf8Uj+Mbpl/Y+JVJQtq9r5/K+bj3Z474+Xk9wG4JH86/rvyzxAirfYnOw+/+vXWTb+uv9PaV3+JfiSv/WOlJVPf/f5AwAAAAAAAAAAAMD/9A0cPbO/ACgAAA==
dtest_s c2745eb185e738821acfcc4c9c92e355 no 200 1024 0
dtest_s c2745eb185e738821acfcc4c9c92e355 yes 200 1024 0