Browse Source

static's added, do_reget hack removed

Pavel Machek 26 years ago
parent
commit
176dc1f70d
10 changed files with 118 additions and 90 deletions
  1. 6 6
      config.h.in
  2. 11 0
      src/ChangeLog
  3. 3 0
      src/achown.c
  4. 4 0
      src/chmod.c
  5. 3 0
      src/chown.c
  6. 28 46
      src/file.c
  7. 2 14
      src/main.c
  8. 11 7
      src/screen.c
  9. 25 0
      vfs/ChangeLog
  10. 25 17
      vfs/extfs.c

+ 6 - 6
config.h.in

@@ -101,9 +101,9 @@
 /* If using the C implementation of alloca, define if you know the
    direction of stack growth for your system; otherwise it will be
    automatically deduced at run-time.
- STACK_DIRECTION > 0 => grows toward higher addresses
- STACK_DIRECTION < 0 => grows toward lower addresses
- STACK_DIRECTION = 0 => direction of growth unknown
+	STACK_DIRECTION > 0 => grows toward higher addresses
+	STACK_DIRECTION < 0 => grows toward lower addresses
+	STACK_DIRECTION = 0 => direction of growth unknown
  */
 #undef STACK_DIRECTION
 
@@ -113,9 +113,6 @@
 /* Define to `int' if <sys/types.h> doesn't define.  */
 #undef uid_t
 
-/* Define if the X Window System is missing or not being used.  */
-#undef X_DISPLAY_MISSING
-
 #undef VERSION
 #undef PACKAGE
 
@@ -408,6 +405,9 @@
 /* Define if you have the truncate function.  */
 #undef HAVE_TRUNCATE
 
+/* Define if you have the valloc function.  */
+#undef HAVE_VALLOC
+
 /* Define if you have the <argz.h> header file.  */
 #undef HAVE_ARGZ_H
 

+ 11 - 0
src/ChangeLog

@@ -1,3 +1,14 @@
+Mon Oct 12 22:47:53 1998  Pavel Machek  <pavel@bug.ucw.cz>
+
+	* file.c (copy_file_file): MCCTL_SETREMOTECOPY is no longer used
+	
+	* file.c (copy_file_file): do_reget is now correctly done using
+ 	open()/lseek() pair
+
+Wed Oct  7 22:20:37 1998  Pavel Machek  <pavel@bug.ucw.cz>
+
+	* file.c: Ask user if (s)he wants to delete incomplete file
+
 Sun Oct 11 20:21:20 1998  Peter Kleiweg <kleiweg@let.rug.nl>
 
 	* mfmt.c (main): When there are an even number of empty lines 

+ 3 - 0
src/achown.c

@@ -642,6 +642,8 @@ void chown_advanced_cmd (void)
 
     files_on_begin = cpanel->marked;
 
+#if 0
+    /* I think that this code is trying to be much too clever  -- pavel@ucw.cz */
     if (!vfs_current_is_local ()) {
 	if (vfs_current_is_extfs ()) {
 	    message (1, _(" Oops... "),
@@ -653,6 +655,7 @@ void chown_advanced_cmd (void)
 	    return;
 	}
     }
+#endif
 
     do {			/* do while any files remaining */
 	init_chown_advanced ();

+ 4 - 0
src/chmod.c

@@ -324,6 +324,9 @@ void chmod_cmd (void)
     int i;
     struct stat sf_stat;
 
+#if 0
+    /* Don't do things like this: you do not want to enumerate all
+       filesystems that can not support chmod, here. */
     if (!vfs_current_is_local ()) {
 	if (vfs_current_is_extfs ()) {
 	    message (1, _(" Oops... "),
@@ -335,6 +338,7 @@ void chmod_cmd (void)
 	    return;
 	}
     }
+#endif
 
     do {			/* do while any files remaining */
 	init_chmod ();

+ 3 - 0
src/chown.c

@@ -251,6 +251,8 @@ void chown_cmd (void)
     gid_t new_group;
     char  buffer [15];
 
+#if 0
+    /* Please no */
     if (!vfs_current_is_local ()) {
 	if (vfs_current_is_extfs ()) {
 	    message (1, _(" Oops... "),
@@ -262,6 +264,7 @@ void chown_cmd (void)
 	    return;
 	}
     }
+#endif
 
     do {			/* do while any files remaining */
 	init_chown ();

+ 28 - 46
src/file.c

@@ -110,13 +110,7 @@
 
 /* }}} */
 
-#if USE_VFS && USE_NETCODE
-extern
-#else
-static
-#endif
-
-int do_reget;
+static int do_reget;
 
 /* rcsid [] = "$Id$" */
 int verbose = 1;
@@ -718,36 +712,25 @@ free_linklist (struct link **linklist)
     *linklist = NULL;
 }
 
-#ifdef USE_VFS
 int 
 is_in_linklist (struct link *lp, char *path, struct stat *sb)
 {
    ino_t ino = sb->st_ino;
    dev_t dev = sb->st_dev;
+#ifdef USE_VFS
    vfs *vfs = vfs_type (path);
+#endif
    
    while (lp) {
-      if (lp->vfs == vfs && lp->ino == ino && lp->dev == dev )
-          return 1;
-      lp = lp->next;
-   }
-   return 0;
-}
-#else
-int 
-is_in_linklist (struct link *lp, char *path, struct stat *sb)
-{
-   ino_t ino = sb->st_ino;
-   dev_t dev = sb->st_dev;
-   
-   while (lp) {
-      if (lp->ino == ino && lp->dev == dev )
-          return 1;
+#ifdef USE_VFS
+      if (lp->vfs == vfs)
+#endif
+	  if (lp->ino == ino && lp->dev == dev )
+	      return 1;
       lp = lp->next;
    }
    return 0;
 }
-#endif
 
 /* Returns 0 if the inode wasn't found in the cache and 1 if it was found
    and a hardlink was succesfully made */
@@ -761,8 +744,10 @@ check_hardlinks (char *src_name, char *dst_name, struct stat *pstat)
     struct stat link_stat;
     char *p;
 
+#if 1	/* What will happen if we kill this line? mc_link() will fail on this and it is right behaivour... */
     if (vfs_file_is_ftp (src_name))
         return 0;
+#endif
     for (lp = linklist; lp != NULL; lp = lp -> next)
         if (lp->vfs == my_vfs && lp->ino == ino && lp->dev == dev){
             if (!mc_stat (lp->name, &link_stat) && link_stat.st_ino == ino &&
@@ -776,7 +761,7 @@ check_hardlinks (char *src_name, char *dst_name, struct stat *pstat)
             	    }
             	}
             }
-            /* FIXME: Announce we couldn't make the hardlink */
+	    message_1s(1, MSG_ERROR, _(" Could not make the hardlink "));
             return 0;
         }
     lp = (struct link *) xmalloc (sizeof (struct link) + strlen (src_name) 
@@ -905,6 +890,7 @@ copy_file_file (char *src_path, char *dst_path, int ask_overwrite)
        A single goto label is much easier to handle than a bunch of gotos ;-). */ 
     unsigned resources = 0; 
 
+    do_reget = 0; /* FIXME: We should not be using global variables! */
     return_status = FILE_RETRY;
 
     if (show_source (src_path) == FILE_ABORT
@@ -949,10 +935,7 @@ copy_file_file (char *src_path, char *dst_path, int ask_overwrite)
 
 	/* Should we replace destination? */
 	if (ask_overwrite) {
-	    if (vfs_file_is_ftp (src_path))
-		do_reget = -1;
-	    else
-		do_reget = 0;
+	    do_reget = 0;
 		    
 	    return_status = query_replace (dst_path, &sb, &sb2);
 	    if (return_status != FILE_CONT)
@@ -1010,10 +993,6 @@ copy_file_file (char *src_path, char *dst_path, int ask_overwrite)
         }
     }
     
-    if (!do_append && !vfs_file_is_local (src_path) && vfs_file_is_local (dst_path)){
-	mc_setctl (src_path, MCCTL_SETREMOTECOPY, dst_path);
-    }
-
     gettimeofday (&tv_transfer_start, (struct timezone *) NULL);
 
  retry_src_open:
@@ -1027,6 +1006,12 @@ copy_file_file (char *src_path, char *dst_path, int ask_overwrite)
     }
 
     resources |= 1;
+    if (do_reget) {
+        if (mc_lseek (src_desc, do_reget, SEEK_SET) != do_reget) {
+	    message_1s (1, _(" Warning "), _(" Reget failed, about to overwrite file "));
+	    do_reget = do_append = 0;
+	}
+    }
     
  retry_src_fstat:
     if (mc_fstat (src_desc, &sb)){
@@ -1080,7 +1065,6 @@ copy_file_file (char *src_path, char *dst_path, int ask_overwrite)
 
     buf = (char *) xmalloc (buf_size, "copy_file_file");
 
-
     eta_secs = 0.0;
     bps = 0;
     return_status = show_file_progress (0, file_size);
@@ -1090,7 +1074,7 @@ copy_file_file (char *src_path, char *dst_path, int ask_overwrite)
 
     {
 	struct timeval tv_current, tv_last_update, tv_last_input;
-        int    i, size, secs, update_secs;
+        int    secs, update_secs;
 	long   dt;
 	char   *stalled_msg;
 
@@ -1208,7 +1192,10 @@ ret:
 	
     if (resources & 4) {
         /* Remove short file */
-	mc_unlink (dst_path);
+        int result;
+        result = query_dialog ("Copy", _("Incomplete file was retrieved. Keep it?"), D_ERROR, 2, _("&Delete"), _("&Keep"));
+	if (!result)
+	    mc_unlink (dst_path);
     } else if (resources & (2|8)) {
         /* no short file and destination file exists */
 #ifndef OS2_NT 
@@ -1513,11 +1500,6 @@ move_file_file (char *s, char *d)
 	}
 
 	if (confirm_overwrite){
-	    if (vfs_file_is_ftp (s))
-		do_reget = -1;
-	    else
-		do_reget = 0;
-	    
 	    return_status = query_replace (d, &src_stats, &dst_stats);
 	    if (return_status != FILE_CONT)
 		return return_status;
@@ -2350,8 +2332,8 @@ panel_operate (void *source_panel, int operation, char *thedefault)
 
 	/* If we are the parent */
 	if (v == 1){
-	    vfs_force_expire (panel->cwd);
-	    vfs_force_expire (dest);
+	    mc_setctl (panel->cwd, MCCTL_FORGET_ABOUT, NULL);
+	    mc_setctl (dest,       MCCTL_FORGET_ABOUT, NULL);
 	    return 0;
 	}
     }
@@ -2745,7 +2727,7 @@ init_replace (enum OperationMode mode)
     /* "this target..." widgets */
     tk_new_frame (replace_dlg, "p.");
 	if (!S_ISDIR (d_stat->st_mode)){
-		if ((do_reget == -1 && d_stat->st_size && s_stat->st_size > d_stat->st_size))
+		if ((d_stat->st_size && s_stat->st_size > d_stat->st_size))
 			ADD_RD_BUTTON(7);
 
 		ADD_RD_BUTTON(8);
@@ -2792,7 +2774,7 @@ real_query_replace (enum OperationMode mode, char *destname, struct stat *_s_sta
 	    return FILE_CONT;
 	
     case REPLACE_REGET:
-	do_reget = _d_stat->st_size;
+	do_reget = _d_stat->st_size;	/* Carefull: we fall through and set do_append */
 	
     case REPLACE_APPEND:
         do_append = 1;

+ 2 - 14
src/main.c

@@ -906,18 +906,6 @@ directory_history_add (WPanel * panel, char *s)
     panel_update_marks (panel);
 }
 
-/* Translate ftp://user:password@host/directory to 
-              /#ftp:user:password@host/directory.
- */
-static char *
-translate_url_to_new_syntax (const char *p)
-{
-    if (strncmp (p, "ftp://", 6) == 0)
-        return copy_strings ("/#ftp:", p + 6, 0);
-    else
-        return strdup (p);
-}
-
 /*
  *  If we moved to the parent directory move the selection pointer to
  *  the old directory name; If we leave VFS dir, remove FS specificator.
@@ -949,7 +937,7 @@ _do_panel_cd (WPanel *panel, char *new_dir, enum cd_enum cd_type)
     struct vfs_stamping *parent;
 #endif    
     olddir = strdup (panel->cwd);
-    translated_url = new_dir = translate_url_to_new_syntax (new_dir);
+    translated_url = new_dir = vfs_translate_url (new_dir);
 
     /* Convert *new_path to a suitable pathname, handle ~user */
     
@@ -1463,7 +1451,7 @@ translated_mc_chdir (char *dir)
 {
 	char *newdir;
 
-	newdir = translate_url_to_new_syntax (dir);
+	newdir = vfs_translate_url (dir);
 	mc_chdir (newdir);
 	free (newdir);
 }

+ 11 - 7
src/screen.c

@@ -2053,13 +2053,17 @@ do_enter (WPanel *panel)
 	        free (cmd);
 	    } 
 #ifdef USE_VFS	    	    
-	    else if (vfs_current_is_extfs ()) {
-	        char *tmp = vfs_get_current_dir();
-	        char *tmp2;
+	    else {
+	      /* if (vfs_current_is_extfs ()) - I see no reason why
+                 filesystems other than extfs could not implement same
+                 call...                              -- pavel@ucw.cz*/
+	        char *tmp;
 
-		tmp2 = concat_dir_and_file (tmp, selection (panel)->fname);
-	        extfs_run(tmp2);
-	        free (tmp2);
+		tmp = concat_dir_and_file (vfs_get_current_dir(), selection (panel)->fname);
+		if (!mc_setctl (tmp, MCCTL_EXTFS_RUN, NULL))
+		    message (1, _(" Warning "), _(" No action taken "));
+
+	        free (tmp);
 	    }
 #endif /* USE_VFS */	    
 	    return 1;
@@ -2290,7 +2294,7 @@ panel_callback (Dlg_head *h, WPanel *panel, int msg, int par)
 #endif
 	panel->active = 1;
 	if (mc_chdir (panel->cwd) != 0){
-	    message (1, " Error ", " Can't chdir to %s \n %s ",
+	    message (1, _(" Error "), _(" Can't chdir to %s \n %s "),
 		     panel->cwd, unix_error_string (errno));
 	} else
 	    subshell_chdir (panel->cwd);

+ 25 - 0
vfs/ChangeLog

@@ -1,3 +1,28 @@
+Mon Oct 12 22:42:30 1998  Pavel Machek  <pavel@bug.ucw.cz>
+
+	* sfs.c: reuse mmap from local.c
+
+	* ftpfs.c, fish.c, shared_ftp_fish.c: horrible reget hack removed,
+ 	and replaced with open(,O_LINEAR); lseek() combination
+
+Sun Oct 11 01:44:37 1998  Pavel Machek  <pavel@bug.ucw.cz>
+
+	* mcfs.c (open_tcp_link): Moved: it used to be in utilvfs.c, but
+ 	as it deals with portmapper, it is probably usefull for mcfs
+
+	* vfs.h (MCERR_*): these are no longer needed
+
+	* vfs.c (vfs_translate_url): translating of url's moved to vfs
+ 	code
+
+	* all around: trying to reduce namespace pollution. All special
+ 	functions (like extfs_run) should be done using mc_setctl()
+ 	interface. At the end, all non-static functions in vfs layer
+ 	should begin with vfs_ and should be declared in vfs.h (however
+ 	that goal is far away).
+
+	* all over the code: replace X_vfs_ops to vfs_X_ops
+	
 Mon Oct  5 20:11:01 1998  Pavel Machek  <pavel@bug.ucw.cz>
 
 	* vfs.c: added stat to avoid hiding files by naming them

+ 25 - 17
vfs/extfs.c

@@ -18,6 +18,8 @@
    License along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
+/* Namespace: exports only vfs_extfs_ops */
+
 #include <config.h>
 #include <stdio.h>
 #include <ctype.h>
@@ -42,7 +44,6 @@
 #include "../src/mem.h"
 #include "../src/mad.h"
 #include "../src/main.h"	/* For shell_execute */
-#define WANT_PARSE_LS_LGA
 #include "vfs.h"
 #include "extfs.h"
 
@@ -61,7 +62,7 @@ static char *extfs_prefixes [MAXEXTFS];
 static char extfs_need_archive [MAXEXTFS];
 static int extfs_no = 0;
 
-void extfs_fill_names (vfs *me, void (*func)(char *))
+static void extfs_fill_names (vfs *me, void (*func)(char *))
 {
     struct archive *a = first_archive;
     char *name;
@@ -261,7 +262,7 @@ static FILE *open_archive (int fstype, char *name, struct archive **pparc)
  * Main loop for reading an archive.
  * Returns 0 on success, -1 on error.
  */
-int read_archive (int fstype, char *name, struct archive **pparc)
+static int read_archive (int fstype, char *name, struct archive **pparc)
 {
     FILE *extfsd;
     char *buffer;
@@ -276,7 +277,7 @@ int read_archive (int fstype, char *name, struct archive **pparc)
     buffer = xmalloc (4096, "Extfs: buffer");
     while (fgets (buffer, 4096, extfsd) != NULL) {
         current_link_name = NULL;
-        if (parse_ls_lga (buffer, &hstat, &current_file_name, &current_link_name)) {
+        if (vfs_parse_ls_lga (buffer, &hstat, &current_file_name, &current_link_name)) {
             struct entry *entry, *pent;
             struct inode *inode;
             char *p, *q, *cfn = current_file_name;
@@ -421,7 +422,7 @@ static char *get_path_mangle (char *inname, struct archive **archive, int is_dir
  /* This is not too secure - in some cases (/#mtools) files created
     under user a are probably visible to everyone else since / usually
     has permissions 755 */
-	        vfs_stamp (&extfs_vfs_ops, (vfsid) parc);
+	        vfs_stamp (&vfs_extfs_ops, (vfsid) parc);
 		goto return_success;
 	    }
 	}
@@ -431,7 +432,7 @@ static char *get_path_mangle (char *inname, struct archive **archive, int is_dir
 
     if (archive_name){
 	v = vfs_type (archive_name);
-	if (v == &local_vfs_ops) {
+	if (v == &vfs_local_ops) {
 	    parent = NULL;
 	} else {
 	    parent = xmalloc (sizeof (struct vfs_stamping), "vfs stamping");
@@ -439,7 +440,7 @@ static char *get_path_mangle (char *inname, struct archive **archive, int is_dir
 	    parent->next = 0;
 	    parent->id = (*v->getid) (v, archive_name, &(parent->parent));
 	}
-	vfs_add_noncurrent_stamps (&extfs_vfs_ops, (vfsid) parc, parent);
+	vfs_add_noncurrent_stamps (&vfs_extfs_ops, (vfsid) parc, parent);
 	vfs_rm_parents (parent);
     }
  return_success:
@@ -554,6 +555,9 @@ static char *get_archive_name (struct archive *archive)
 	return archive_name;
 }
 
+/* FIXME: we really should not have non-static procedures - it
+ * pollutes namespace.  */
+
 void extfs_run (char *file)
 {
     struct archive *archive;
@@ -634,7 +638,7 @@ static void *extfs_open (vfs *me, char *file, int flags, int mode)
     extfs_info->local_handle = local_handle;
 
     /* i.e. we had no open files and now we have one */
-    vfs_rmstamp (&extfs_vfs_ops, (vfsid) archive, 1);
+    vfs_rmstamp (&vfs_extfs_ops, (vfsid) archive, 1);
     archive->fd_usage++;
     return extfs_info;
 }
@@ -695,7 +699,7 @@ static int extfs_close (void *data)
         struct vfs_stamping *parent;
         vfs *v;
         
-	if (!file->archive->name || !*file->archive->name || (v = vfs_type (file->archive->name)) == &local_vfs_ops) {
+	if (!file->archive->name || !*file->archive->name || (v = vfs_type (file->archive->name)) == &vfs_local_ops) {
 	    parent = NULL;
 	} else {
 	    parent = xmalloc (sizeof (struct vfs_stamping), "vfs stamping");
@@ -703,7 +707,7 @@ static int extfs_close (void *data)
 	    parent->next = 0;
 	    parent->id = (*v->getid) (v, file->archive->name, &(parent->parent));
 	}
-        vfs_add_noncurrent_stamps (&extfs_vfs_ops, (vfsid) (file->archive), parent);
+        vfs_add_noncurrent_stamps (&vfs_extfs_ops, (vfsid) (file->archive), parent);
 	vfs_rm_parents (parent);
     }
 	
@@ -939,11 +943,6 @@ static int extfs_which (vfs *me, char *path)
     return -1;
 }
 
-static char *extfs_get_prefix (int idx)
-{
-    return extfs_prefixes [idx];
-}
-
 static void extfs_done (vfs *me)
 {
     int i;
@@ -956,7 +955,16 @@ static void extfs_done (vfs *me)
     extfs_current_dir = 0;
 }
 
-vfs extfs_vfs_ops = {
+static int extfs_setctl (vfs *me, char *path, int ctlop, char *arg)
+{
+    if (ctlop == MCCTL_EXTFS_RUN) {
+        extfs_run (path);
+	return 1;
+    }
+    return 0;
+}
+
+vfs vfs_extfs_ops = {
     NULL,	/* This is place of next pointer */
     "Extended filesystems",
     F_EXEC,	/* flags */
@@ -1009,7 +1017,7 @@ vfs extfs_vfs_ops = {
     NULL,		/* mkdir */
     NULL,
     NULL,
-    NULL
+    extfs_setctl
 
 MMAPNULL
 };

Some files were not shown because too many files changed in this diff