author | Rich Burridge <rich.burridge@oracle.com> |
Mon, 23 Apr 2012 13:10:08 -0700 | |
changeset 794 | adae50e39183 |
permissions | -rw-r--r-- |
794
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
1 |
--- gzip-1.4/gzip.c.orig 2012-04-16 11:27:08.478456051 -0700 |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
2 |
+++ gzip-1.4/gzip.c 2012-04-23 13:06:53.395234301 -0700 |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
3 |
@@ -1699,36 +1699,25 @@ |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
4 |
int fd; |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
5 |
char *dir; |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
6 |
{ |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
7 |
+ struct dirent **namelist; |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
8 |
struct dirent *dp; |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
9 |
- DIR *dirp; |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
10 |
char nbuf[MAX_PATH_LEN]; |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
11 |
- int len; |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
12 |
+ int len, n; |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
13 |
|
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
14 |
- dirp = fdopendir (fd); |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
15 |
- |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
16 |
- if (dirp == NULL) { |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
17 |
+ /* Adjusted to use scandir to prevent compressing files multiple times |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
18 |
+ * on file systems that use a hash lookup for directory entries (such |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
19 |
+ * as btrfs and ZFS. |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
20 |
+ */ |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
21 |
+ if ((n = scandir(dir, &namelist, 0, NULL)) < 0) { |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
22 |
progerror(dir); |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
23 |
close (fd); |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
24 |
return ; |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
25 |
} |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
26 |
- /* |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
27 |
- ** WARNING: the following algorithm could occasionally cause |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
28 |
- ** compress to produce error warnings of the form "<filename>.gz |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
29 |
- ** already has .gz suffix - ignored". This occurs when the |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
30 |
- ** .gz output file is inserted into the directory below |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
31 |
- ** readdir's current pointer. |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
32 |
- ** These warnings are harmless but annoying, so they are suppressed |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
33 |
- ** with option -r (except when -v is on). An alternative |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
34 |
- ** to allowing this would be to store the entire directory |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
35 |
- ** list in memory, then compress the entries in the stored |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
36 |
- ** list. Given the depth-first recursive algorithm used here, |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
37 |
- ** this could use up a tremendous amount of memory. I don't |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
38 |
- ** think it's worth it. -- Dave Mack |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
39 |
- ** (An other alternative might be two passes to avoid depth-first.) |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
40 |
- */ |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
41 |
- |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
42 |
- while ((errno = 0, dp = readdir(dirp)) != NULL) { |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
43 |
|
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
44 |
+ while (n--) { |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
45 |
+ if (errno != 0) |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
46 |
+ break; |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
47 |
+ dp = namelist[n]; |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
48 |
if (strequ(dp->d_name,".") || strequ(dp->d_name,"..")) { |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
49 |
continue; |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
50 |
} |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
51 |
@@ -1747,6 +1736,7 @@ |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
52 |
} |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
53 |
strcpy(nbuf+len, dp->d_name); |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
54 |
treat_file(nbuf); |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
55 |
+ free(dp); |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
56 |
} else { |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
57 |
fprintf(stderr,"%s: %s/%s: pathname too long\n", |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
58 |
program_name, dir, dp->d_name); |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
59 |
@@ -1755,8 +1745,8 @@ |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
60 |
} |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
61 |
if (errno != 0) |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
62 |
progerror(dir); |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
63 |
- if (CLOSEDIR(dirp) != 0) |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
64 |
- progerror(dir); |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
65 |
+ |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
66 |
+ free(namelist); |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
67 |
} |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
68 |
#endif /* ! NO_DIR */ |
adae50e39183
7159588 gzip 1.4 -rf recursive/force option not working correctly
Rich Burridge <rich.burridge@oracle.com>
parents:
diff
changeset
|
69 |