From charles@comm.polymtl.ca  Thu Aug 26 14:28:18 1999
Return-Path: <charles@comm.polymtl.ca>
Received: from mail.redhat.com (mail.redhat.com [199.183.24.239])
	by developer.redhat.com (8.8.7/8.8.7) with ESMTP id OAA26562
	for <bugzilla@developer.redhat.com>; Thu, 26 Aug 1999 14:28:18 -0400
Received: from lacrosse.corp.redhat.com (root@lacrosse.corp.redhat.com [207.175.42.154])
	by mail.redhat.com (8.8.7/8.8.7) with ESMTP id OAA26105
	for <bugzilla@developer.redhat.com>; Thu, 26 Aug 1999 14:28:17 -0400
Received: from mail.redhat.com (mail.redhat.com [199.183.24.239])
	by lacrosse.corp.redhat.com (8.9.3/8.9.3) with ESMTP id OAA20589
	for <bugzilla@lacrosse.redhat.com>; Thu, 26 Aug 1999 14:28:16 -0400
Received: from comm.polymtl.ca (inconnu@comm.polymtl.ca [132.207.7.20])
	by mail.redhat.com (8.8.7/8.8.7) with ESMTP id OAA26096
	for <bugzilla@redhat.com>; Thu, 26 Aug 1999 14:28:16 -0400
Received: from faucon.comm.polymtl.ca (charles@faucon.comm.polymtl.ca [132.207.20.24])
	by comm.polymtl.ca (8.8.7/8.8.7) with SMTP id OAA06425;
	Thu, 26 Aug 1999 14:28:11 -0400 (EDT)
Date: Thu, 26 Aug 1999 14:28:11 -0400 (EDT)
Message-Id: <199908261828.OAA06425@comm.polymtl.ca>
Received: by faucon.comm.polymtl.ca (4.1/SMI-4.1)
	id AA09514; Thu, 26 Aug 99 14:28:09 EDT
From: Charles Levert <charles@comm.polymtl.ca>
To: bugzilla@redhat.com
Subject: BUG ID #4725

--- wget-1.5.3/src/ChangeLog.orig-1.5.3	Mon Sep 21 13:01:05 1998
+++ wget-1.5.3/src/ChangeLog	Sat Jun 19 16:09:40 1999
@@ -1,3 +1,17 @@
+1999-06-19  Charles Levert  <charles@comm.polymtl.ca>
+
+	* ftp.c (touch_and_chmod): New static function from code in
+	ftp_retrieve_list.
+
+	* ftp.c (ftp_retrieve_list): use touch_and_chmod instead.
+
+	* ftp.c (ftp_retrieve_dirs): chmod 0700 each dir, process it,
+	and touch_and_chmod it properly afterwards.
+
+1999-06-14  Charles Levert  <charles@comm.polymtl.ca>
+
+	* ftp.c (ftp_retrieve_list): Do not use chmod on a symlink.
+
 1998-09-21  Hrvoje Niksic  <hniksic@srce.hr>
 
 	* version.c: Wget 1.5.3 is released.
--- wget-1.5.3/src/ftp.c.orig-1.5.3	Thu Sep 10 08:21:36 1998
+++ wget-1.5.3/src/ftp.c	Sat Jun 19 16:00:31 1999
@@ -1023,6 +1023,7 @@
 static struct fileinfo *delelement PARAMS ((struct fileinfo *,
 					    struct fileinfo **));
 static void freefileinfo PARAMS ((struct fileinfo *f));
+static void touch_and_chmod PARAMS ((char *local_name, 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
@@ -1178,24 +1179,8 @@
 	  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 (!opt.dfp
-	  && !(f->type == FT_SYMLINK && !opt.retr_symlinks)
-	  && f->tstamp != -1
-          && dlthis
-	  && file_exists_p (u->local))
-	{
-	  touch (u->local, f->tstamp);
-	}
-      else if (f->tstamp == -1)
-	logprintf (LOG_NOTQUIET, _("%s: corrupt time-stamp.\n"), u->local);
-
-      if (f->perms && dlthis)
-	chmod (u->local, f->perms);
-      else
-	DEBUGP (("Unrecognized permissions for %s.\n", u->local));
+      if (!opt.dfp && dlthis)
+	touch_and_chmod (u->local, f);
 
       free (u->local);
       u->local = olocal;
@@ -1224,6 +1209,8 @@
 ftp_retrieve_dirs (struct urlinfo *u, struct fileinfo *f, ccon *con)
 {
   char *odir;
+  char *ofile;
+  char *ulocal;
   char *current_container = NULL;
   int current_length = 0;
 
@@ -1235,6 +1222,12 @@
 	break;
       if (f->type != FT_DIRECTORY)
 	continue;
+
+      ofile = u->file;
+      u->file = f->name;
+      ulocal = url_filename (u);
+      u->file = ofile;
+
       odir = u->dir;
       len = 1 + strlen (u->dir) + 1 + strlen (f->name) + 1;
       /* Allocate u->dir off stack, but reallocate only if a larger
@@ -1251,12 +1244,23 @@
 	{
 	  logprintf (LOG_VERBOSE, _("\
 Not descending to `%s' as it is excluded/not-included.\n"), u->dir);
+	  free (ulocal);
 	  u->dir = odir;
 	  continue;
 	}
       con->st &= ~DONE_CWD;
+
+      /* Make sure we can write in there.  */
+      if (!opt.dfp)
+	chmod (ulocal, 0700);
+
       ftp_retrieve_glob (u, con, GETALL);
-      /* Set the time-stamp?  */
+
+      /* Now that everything that had to be done there is done...  */
+      if (!opt.dfp)
+	touch_and_chmod (ulocal, f);
+
+      free (ulocal);
       u->dir = odir;
     }
   if (opt.quota && opt.downloaded > opt.quota)
@@ -1472,5 +1476,28 @@
 	free (f->linkto);
       free (f);
       f = next;
+    }
+}
+
+static void
+touch_and_chmod(char *local_name, 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.  :( */
+  /* Symlinks always have 0777 perms.  Chmod would affect
+     linked file. */
+  if (!(f->type == FT_SYMLINK && !opt.retr_symlinks)
+      && file_exists_p (local_name))
+    {
+      if (f->tstamp != -1)
+	touch (local_name, f->tstamp);
+      else
+	logprintf (LOG_NOTQUIET, _("%s: corrupt time-stamp.\n"), local_name);
+
+      if (f->perms)
+	chmod (local_name, f->perms);
+      else
+	DEBUGP (("Unrecognized permissions for %s.\n", local_name));
     }
 }

