attached is a patch file that changes the fnmatch function in order to
achieve uniform behavior between the -I,-X,-A,-R options and the names in
the filesystem. that is, the handling of %xx escapes is inconsistent in the
current version, such that, e.g., -I/foo\ bar and -Ifoo%20bar do not mean
the same thing. in particular, -Ifoo%20bar will *not* match the name
foo%20bar after all; only the escaped space character will work. [i think
i've got that right; it's been a while since i made this fix.]
this patch remedies the problem, and makes comparisons match correctly
between escaped and hexified character strings. this patch has also been
submitted to redhat.
in addition, redhat is using another patch, which i have brought up to date
for 1.6, dealing with permissions handling and symlnks, which also does some
code consolidation that was alluded to in the comments in 1.5.3 but never
occurred. i have attached that patch as well.
thanks for the software. the patches are my way of trying to make it even
better. :)
--
Alan Eldridge
#include <std_disclaimer.h>
diff -ru wget-1.6.or/src/fnmatch.c wget-1.6/src/fnmatch.c
--- wget-1.6.or/src/fnmatch.c Thu Dec 2 02:42:28 1999
+++ wget-1.6/src/fnmatch.c Sat Jan 6 01:38:53 2001
@@ -24,17 +24,28 @@
#include <config.h>
#include <errno.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
+#else
+# include <strings.h>
+#endif /* HAVE_STRING_H */
+
#include "wget.h"
#include "fnmatch.h"
-
+
/* Match STRING against the filename pattern PATTERN, returning zero
if it matches, FNM_NOMATCH if not. */
int
fnmatch (const char *pattern, const char *string, int flags)
{
- register const char *p = pattern, *n = string;
+ register char *p, *pat, *n, *str;
register char c;
+ strcpy(n = alloca(strlen(string)+1), string);
+ decode_string(str = n);
+ strcpy(p = alloca(strlen(pattern)+1), pattern);
+ decode_string(pat = p);
+
if ((flags & ~__FNM_FLAGS) != 0)
{
errno = EINVAL;
@@ -51,7 +62,7 @@
else if ((flags & FNM_PATHNAME) && *n == '/')
return (FNM_NOMATCH);
else if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/')))
+ (n == str || ((flags & FNM_PATHNAME) && n[-1] == '/')))
return (FNM_NOMATCH);
break;
@@ -64,7 +75,7 @@
case '*':
if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/')))
+ (n == str || ((flags & FNM_PATHNAME) && n[-1] == '/')))
return (FNM_NOMATCH);
for (c = *p++; c == '?' || c == '*'; c = *p++, ++n)
@@ -94,7 +105,7 @@
return (FNM_NOMATCH);
if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/')))
+ (n == str || ((flags & FNM_PATHNAME) && n[-1] == '/')))
return (FNM_NOMATCH);
/* Make sure there is a closing `]'. If there isn't,
diff -ru wget-1.6.or/src/url.c wget-1.6/src/url.c
--- wget-1.6.or/src/url.c Sun Dec 17 14:28:20 2000
+++ wget-1.6/src/url.c Sat Jan 6 01:36:10 2001
@@ -192,7 +192,7 @@
hex-digits or `%' precedes `\0', the sequence is inserted
literally. */
-static void
+void
decode_string (char *s)
{
char *p = s;
diff -ru wget-1.6.or/src/url.h wget-1.6/src/url.h
--- wget-1.6.or/src/url.h Tue Oct 31 14:23:59 2000
+++ wget-1.6/src/url.h Sat Jan 6 01:36:10 2001
@@ -81,6 +81,7 @@
int skip_url PARAMS ((const char *));
+void decode_string PARAMS ((char *));
int contains_unsafe PARAMS ((const char *));
char *encode_string PARAMS ((const char *));
diff -ru wget-1.6.or/src/ChangeLog wget-1.6/src/ChangeLog
--- wget-1.6.or/src/ChangeLog Sat Dec 30 23:20:11 2000
+++ wget-1.6/src/ChangeLog Mon Jan 1 21:38:10 2001
@@ -1,3 +1,17 @@
+2001-01-01 Alan Eldridge <[EMAIL PROTECTED]>
+
+ * ftp.c (touch_and_chmod): new function from existing code
+ (update to Charles Levant's patch to 1.5.3 in Redhat 6.x/7.0)
+ to set timestamp and perms on a file iff it's not a symlink.
+
+ * ftp.c (ftp_retrieve_list): use touch_and_chmod instead of
+ code that was moved out to create touch_and_chmod (from CL's
+ patch).
+
+ * ftp.c (ftp_retrieve_dirs): chmod each dir to 0700, process
+ it, then touch_and_chmod it to proper values (update to CL's
+ patch).
+
2000-12-30 Dan Harkless <[EMAIL PROTECTED]>
* ftp.c, http.c: Applied Hack Kampbjørn <[EMAIL PROTECTED]>'s
diff -ru wget-1.6.or/src/ftp.c wget-1.6/src/ftp.c
--- wget-1.6.or/src/ftp.c Sat Dec 30 22:47:33 2000
+++ wget-1.6/src/ftp.c Mon Jan 1 21:38:16 2001
@@ -1089,6 +1089,7 @@
static struct fileinfo *delelement PARAMS ((struct fileinfo *,
struct fileinfo **));
static void freefileinfo PARAMS ((struct fileinfo *f));
+static void touch_and_chmod PARAMS ((char *locname, struct fileinfo *f));
/* Retrieve a list of files given in struct fileinfo linked list. If
a file is a symbolic link, do not retrieve it, but rather try to
@@ -1249,34 +1250,9 @@
break;
} /* switch */
- /* Set the time-stamp information to the local file. Symlinks
- are not to be stamped because it sets the stamp on the
- original. :( */
- if (!(f->type == FT_SYMLINK && !opt.retr_symlinks)
- && f->tstamp != -1
- && dlthis
- && file_exists_p (u->local))
- {
- /* #### This code repeats in http.c and ftp.c. Move it to a
- function! */
- const char *fl = NULL;
- if (opt.output_document)
- {
- if (opt.od_known_regular)
- fl = opt.output_document;
- }
- else
- fl = u->local;
- if (fl)
- touch (fl, f->tstamp);
- }
- else if (f->tstamp == -1)
- logprintf (LOG_NOTQUIET, _("%s: corrupt time-stamp.\n"), u->local);
-
- if (f->perms && f->type == FT_PLAINFILE && dlthis)
- chmod (u->local, f->perms);
- else
- DEBUGP (("Unrecognized permissions for %s.\n", u->local));
+ if (dlthis) {
+ touch_and_chmod(u->local, f);
+ }
free (u->local);
u->local = olocal;
@@ -1308,6 +1284,8 @@
char *odir;
char *current_container = NULL;
int current_length = 0;
+ char *ofile;
+ char *ulocal;
for (; f; f = f->next)
{
@@ -1318,6 +1296,7 @@
if (f->type != FT_DIRECTORY)
continue;
odir = u->dir;
+
len = 1 + strlen (u->dir) + 1 + strlen (f->name) + 1;
/* Allocate u->dir off stack, but reallocate only if a larger
string is needed. */
@@ -1337,8 +1316,22 @@
continue;
}
con->st &= ~DONE_CWD;
+
+ ofile = u->file;
+ u->file = f->name;
+ ulocal = url_filename(u);
+ if (!opt.dfp) {
+ chmod(ulocal, 0700);
+ }
+
ftp_retrieve_glob (u, con, GETALL);
- /* Set the time-stamp? */
+
+ /* Set the time-stamp */
+ if (!opt.dfp) {
+ touch_and_chmod(ulocal, f);
+ }
+ free(ulocal);
+ u->file = ofile;
u->dir = odir;
}
if (opt.quota && opt.downloaded > opt.quota)
@@ -1556,3 +1549,36 @@
f = next;
}
}
+
+static void
+touch_and_chmod(char *locname, struct fileinfo *f)
+{
+ /* Set the time-stamp information to the local file. Symlinks
+ are not to be stamped because it sets the stamp on the
+ original. :( */
+ if (!(f->type == FT_SYMLINK && !opt.retr_symlinks)
+ && f->tstamp != -1
+ && file_exists_p (locname))
+ {
+ /* #### This code repeats in http.c and ftp.c. Move it to a
+ function! */
+ const char *fl = NULL;
+ if (opt.output_document)
+ {
+ if (opt.od_known_regular)
+ fl = opt.output_document;
+ }
+ else
+ fl = locname;
+ if (fl)
+ touch (fl, f->tstamp);
+ }
+ else if (f->tstamp == -1)
+ logprintf (LOG_NOTQUIET, _("%s: corrupt time-stamp.\n"), locname);
+
+ if (f->perms && f->type == FT_PLAINFILE)
+ chmod (locname, f->perms);
+ else
+ DEBUGP (("Unrecognized permissions for %s.\n", locname));
+}
+