changeset 500:ba50a7085d93

2004-7-13 Brian Masney <masneyb@gftp.org> * lib/gftp.h lib/local.c lib/protocols.c lib/rfc2068.c lib/rfc959.c lib/sshv2.c - added gftp_stat_filename(). This will retrieve the attributes for the selected file. When downloading a list of items, if one of the items is a symlink, check to see if it points to a directory or file * src/gtk/misc-gtk.c - fix for displaying the folder icon for directories
author masneyb
date Wed, 14 Jul 2004 02:33:42 +0000
parents 39e9945288ea
children 3be2cec1ec28
files ChangeLog lib/gftp.h lib/local.c lib/protocols.c lib/rfc2068.c lib/rfc959.c lib/sshv2.c src/gtk/misc-gtk.c
diffstat 8 files changed, 108 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Jul 13 20:17:42 2004 +0000
+++ b/ChangeLog	Wed Jul 14 02:33:42 2004 +0000
@@ -1,4 +1,13 @@
 2004-7-13 Brian Masney <masneyb@gftp.org>
+	* lib/gftp.h lib/local.c lib/protocols.c lib/rfc2068.c lib/rfc959.c
+	lib/sshv2.c - added gftp_stat_filename(). This will retrieve the
+	attributes for the selected file. When downloading a list of items,
+	if one of the items is a symlink, check to see if it points to a 
+	directory or file
+
+	* src/gtk/misc-gtk.c - fix for displaying the folder icon for
+	directories
+
 	* lib/gftp.h lib/local.c lib/misc.c lib/protocols.c lib/rfc2068.c
 	lib/rfc959.c lib/sshv2.c src/gtk/chmod_dialog.c src/gtk/delete_dialog.c
 	src/gtk/dnd.c src/gtk/gftp-gtk.c src/gtk/gtkui_transfer.c
@@ -2558,7 +2567,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.278 2004/07/13 20:17:42 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.279 2004/07/14 02:33:42 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/lib/gftp.h	Tue Jul 13 20:17:42 2004 +0000
+++ b/lib/gftp.h	Wed Jul 14 02:33:42 2004 +0000
@@ -424,6 +424,8 @@
 					  size_t size );
   int (*end_transfer) 			( gftp_request * request );
   int (*abort_transfer) 		( gftp_request * request );
+  mode_t (*stat_filename) 		( gftp_request * request,
+					  const char *filename );
   int (*list_files) 			( gftp_request * request );
   int (*get_next_file)			( gftp_request * request, 
 					  gftp_file *fle, 
@@ -888,6 +890,9 @@
 
 int gftp_abort_transfer 		( gftp_request * request );
 
+mode_t gftp_stat_filename		( gftp_request * request,
+					  const char *filename );
+
 void gftp_set_hostname 			( gftp_request * request, 
 					  const char *hostname );
 
--- a/lib/local.c	Tue Jul 13 20:17:42 2004 +0000
+++ b/lib/local.c	Wed Jul 14 02:33:42 2004 +0000
@@ -220,6 +220,18 @@
 }
 
 
+static mode_t
+local_stat_filename (gftp_request * request, const char *filename)
+{
+  struct stat st;
+
+  if (stat (filename, &st) != 0)
+    return (GFTP_ERETRYABLE);
+
+  return (st.st_mode);
+}
+
+
 static int
 local_get_next_file (gftp_request * request, gftp_file * fle, int fd)
 {
@@ -577,6 +589,7 @@
   request->put_next_file_chunk = NULL;
   request->end_transfer = local_end_transfer;
   request->abort_transfer = local_end_transfer; /* NOTE: uses end_transfer */
+  request->stat_filename = local_stat_filename;
   request->list_files = local_list_files;
   request->get_next_file = local_get_next_file;
   request->get_next_dirlist_line = NULL;
--- a/lib/protocols.c	Tue Jul 13 20:17:42 2004 +0000
+++ b/lib/protocols.c	Wed Jul 14 02:33:42 2004 +0000
@@ -339,6 +339,22 @@
 }
 
 
+mode_t
+gftp_stat_filename (gftp_request * request, const char *filename)
+{
+  mode_t ret;
+
+  g_return_val_if_fail (request != NULL, GFTP_EFATAL);
+
+  if (request->stat_filename != NULL)
+    ret = request->stat_filename (request, filename);
+  else
+    ret = 0;
+
+  return (ret);
+}
+
+
 int
 gftp_list_files (gftp_request * request)
 {
@@ -1881,6 +1897,7 @@
   unsigned long *newsize;
   GHashTable * dirhash;
   gftp_file * curfle;
+  mode_t st_mode;
 
   g_return_val_if_fail (transfer != NULL, GFTP_EFATAL);
   g_return_val_if_fail (transfer->fromreq != NULL, GFTP_EFATAL);
@@ -1940,7 +1957,14 @@
     {
       curfle = templist->data;
 
-      if (S_ISDIR (curfle->st_mode))
+      if (S_ISLNK (curfle->st_mode) && !S_ISDIR (curfle->st_mode))
+        {
+          st_mode = gftp_stat_filename (transfer->fromreq, curfle->file);
+          if (S_ISDIR (st_mode))
+            curfle->st_mode = st_mode;
+        }
+
+      if (curfle->st_mode & S_IFDIR)
         {
           oldfromdir = transfer->fromreq->directory;
           transfer->fromreq->directory = curfle->file;
--- a/lib/rfc2068.c	Tue Jul 13 20:17:42 2004 +0000
+++ b/lib/rfc2068.c	Wed Jul 14 02:33:42 2004 +0000
@@ -919,6 +919,7 @@
   request->put_next_file_chunk = NULL;
   request->end_transfer = rfc2068_end_transfer;
   request->abort_transfer = rfc2068_end_transfer; /* NOTE: uses end_transfer */
+  request->stat_filename = NULL;
   request->list_files = rfc2068_list_files;
   request->get_next_file = rfc2068_get_next_file;
   request->get_next_dirlist_line = NULL;
--- a/lib/rfc959.c	Tue Jul 13 20:17:42 2004 +0000
+++ b/lib/rfc959.c	Wed Jul 14 02:33:42 2004 +0000
@@ -1809,6 +1809,7 @@
   request->put_next_file_chunk = rfc959_put_next_file_chunk;
   request->end_transfer = rfc959_end_transfer;
   request->abort_transfer = rfc959_abort_transfer;
+  request->stat_filename = NULL;
   request->list_files = rfc959_list_files;
   request->get_next_file = rfc959_get_next_file;
   request->get_next_dirlist_line = rfc959_get_next_dirlist_line;
--- a/lib/sshv2.c	Tue Jul 13 20:17:42 2004 +0000
+++ b/lib/sshv2.c	Wed Jul 14 02:33:42 2004 +0000
@@ -1211,6 +1211,8 @@
     {
       if ((num = sshv2_buffer_get_int32 (request, message, -1)) < 0)
         return (num);
+
+      fle->st_mode = num;
     }
 
   if (attrs & SSH_FILEXFER_ATTR_ACMODTIME)
@@ -1229,7 +1231,6 @@
       if ((count = sshv2_buffer_get_int32 (request, message, -1)) < 0)
         return (GFTP_EFATAL);
 
-      printf ("FIXME - file %d extended attributes\n", count);
       for (i=0; i<count; i++)
         {
           if ((num = sshv2_buffer_get_int32 (request, message, -1)) < 0 ||
@@ -1672,22 +1673,21 @@
 }
 
 
-static off_t
-sshv2_get_file_size (gftp_request * request, const char *file)
+static int
+sshv2_send_stat_command (gftp_request * request, const char *filename,
+                         gftp_file * fle)
 {
   sshv2_message message;
-  gftp_file fle;
   char *tempstr;
-  int serv_ret;
   gint32 len;
-  off_t ret;
+  int ret;
 
   g_return_val_if_fail (request != NULL, GFTP_EFATAL);
   g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
-  g_return_val_if_fail (file != NULL, GFTP_EFATAL);
+  g_return_val_if_fail (filename != NULL, GFTP_EFATAL);
 
   len = 0;
-  tempstr = sshv2_initialize_string_with_path (request, file, &len, NULL);
+  tempstr = sshv2_initialize_string_with_path (request, filename, &len, NULL);
 
   ret = sshv2_send_command (request, SSH_FXP_STAT, tempstr, len);
 
@@ -1695,28 +1695,61 @@
   if (ret < 0)
     return (ret);
 
-  serv_ret = sshv2_read_status_response (request, &message, -1, SSH_FXP_STATUS,
-                                         SSH_FXP_ATTRS);
-  if (serv_ret < 0)
-    return (serv_ret);
+  ret = sshv2_read_status_response (request, &message, -1, SSH_FXP_STATUS,
+                                    SSH_FXP_ATTRS);
+  if (ret < 0)
+    return (ret);
 
   if (message.length < 5)
     return (GFTP_EFATAL);
 
   message.pos += 4;
-  memset (&fle, 0, sizeof (fle));
-  if ((serv_ret = sshv2_decode_file_attributes (request, &message, &fle)) < 0)
+  if ((ret = sshv2_decode_file_attributes (request, &message, fle)) < 0)
     {
-      gftp_file_destroy (&fle);
-      return (serv_ret);
+      gftp_file_destroy (fle);
+      return (ret);
     }
 
-  ret = fle.size;
-  gftp_file_destroy (&fle);
   sshv2_message_free (&message);
 
+  return (0);
+}
+
+
+static mode_t
+sshv2_stat_filename (gftp_request * request, const char *filename)
+{
+  gftp_file fle;
+  mode_t ret;
+
+  memset (&fle, 0, sizeof (fle));
+  ret = sshv2_send_stat_command (request, filename, &fle);
+  if (ret < 0)
+    return (ret);
+
+  ret = fle.st_mode;
+  gftp_file_destroy (&fle);
+
   return (ret);
+}
 
+
+static off_t
+sshv2_get_file_size (gftp_request * request, const char *file)
+{
+  gftp_file fle;
+  off_t size;
+  int ret;
+
+  memset (&fle, 0, sizeof (fle));
+  ret = sshv2_send_stat_command (request, file, &fle);
+  if (ret < 0)
+    return (ret);
+
+  size = fle.size;
+  gftp_file_destroy (&fle);
+
+  return (size);
 }
 
 
@@ -2047,6 +2080,7 @@
   request->put_next_file_chunk = sshv2_put_next_file_chunk;
   request->end_transfer = sshv2_end_transfer;
   request->abort_transfer = sshv2_end_transfer; /* NOTE: uses sshv2_end_transfer */
+  request->stat_filename = sshv2_stat_filename;
   request->list_files = sshv2_list_files;
   request->get_next_file = sshv2_get_next_file;
   request->get_next_dirlist_line = NULL;
--- a/src/gtk/misc-gtk.c	Tue Jul 13 20:17:42 2004 +0000
+++ b/src/gtk/misc-gtk.c	Wed Jul 14 02:33:42 2004 +0000
@@ -693,7 +693,7 @@
     gftp_get_pixmap (wdata->listbox, "linkdir.xpm", &pix, &bitmap);
   else if (S_ISLNK (fle->st_mode))
     gftp_get_pixmap (wdata->listbox, "linkfile.xpm", &pix, &bitmap);
-  else if (S_ISLNK (fle->st_mode))
+  else if (S_ISDIR (fle->st_mode))
     gftp_get_pixmap (wdata->listbox, "dir.xpm", &pix, &bitmap);
   else if ((fle->st_mode & S_IXUSR) ||
            (fle->st_mode & S_IXGRP) ||