[patch] vfs copy resume



Hello,
this is an attempt to make "Reget" work again with ftp (and other) fs. This patch adds another argument with source offset to mc_open, which is checked when O_LINEAR flag is set. As mc_open has variable number of arguments, only one occurence of mc_open had to be modified in the source.

Regards,

--
Jindrich Makovicka
Index: file.c
===================================================================
RCS file: /cvs/gnome/mc/src/file.c,v
retrieving revision 1.99
diff -u -b -B -r1.99 file.c
--- file.c	26 Mar 2003 09:59:38 -0000	1.99
+++ file.c	4 May 2003 07:34:32 -0000
@@ -608,22 +608,20 @@
 
     gettimeofday (&tv_transfer_start, (struct timezone *) NULL);
 
-    while ((src_desc = mc_open (src_path, O_RDONLY | O_LINEAR)) < 0) {
+    while ((src_desc = mc_open (src_path, O_RDONLY | O_LINEAR, ctx->do_reget)) < 0) {
 	return_status =
 	    file_error (_(" Cannot open source file \"%s\" \n %s "),
 			src_path);
 	if (return_status == FILE_RETRY)
 	    continue;
-	ctx->do_append = 0;
-	return return_status;
-    }
-
     if (ctx->do_reget) {
-	if (mc_lseek (src_desc, ctx->do_reget, SEEK_SET) != ctx->do_reget) {
 	    message_1s (1, _("Warning"),
 			_(" Reget failed, about to overwrite file "));
 	    ctx->do_reget = ctx->do_append = 0;
+	    continue;
 	}
+	ctx->do_append = 0;
+	return return_status;
     }
 
     while (mc_fstat (src_desc, &sb)) {
Index: direntry.c
===================================================================
RCS file: /cvs/gnome/mc/vfs/direntry.c,v
retrieving revision 1.58
diff -u -b -B -r1.58 direntry.c
--- direntry.c	19 Feb 2003 14:04:36 -0000	1.58
+++ direntry.c	4 May 2003 07:34:36 -0000
@@ -735,7 +735,7 @@
 }
 
 void *
-vfs_s_open (vfs *me, char *file, int flags, int mode)
+vfs_s_open (vfs *me, char *file, int flags, int mode, off_t offset)
 {
     int was_changed = 0;
     struct vfs_s_fh *fh;
@@ -787,12 +787,12 @@
     if (IS_LINEAR(flags)) {
 	if (MEDATA->linear_start) {
 	    print_vfs_message (_("Starting linear transfer..."));
-	    if (!MEDATA->linear_start (me, fh, 0)){
+	    if (!MEDATA->linear_start (me, fh, offset)){
 		g_free(fh);
 		return NULL;
 	    }
 	}
-    } else if ((MEDATA->fh_open) && (MEDATA->fh_open (me, fh, flags, mode))){
+    } else if ((MEDATA->fh_open) && (MEDATA->fh_open (me, fh, flags, mode))) {
 	    g_free(fh);
 	    return NULL;
 	}
@@ -803,7 +803,15 @@
 	    g_free(fh);
 	    ERRNOR (errno, NULL);
 	}
+	if (IS_LINEAR(flags) && (offset > 0)) {
+	    if (lseek(fh->handle, offset, SEEK_SET) != offset) {
+		close(fh->handle);
+		g_free(fh);
+		return NULL;
+	    }
     }
+    }
+
 
      /* i.e. we had no open files and now we have one */
     vfs_rmstamp (me, (vfsid) super, 1);
Index: extfs.c
===================================================================
RCS file: /cvs/gnome/mc/vfs/extfs.c,v
retrieving revision 1.68
diff -u -b -B -r1.68 extfs.c
--- extfs.c	11 Mar 2003 00:01:56 -0000	1.68
+++ extfs.c	4 May 2003 07:34:36 -0000
@@ -636,7 +636,7 @@
 }
 
 static void *
-extfs_open (vfs *me, char *file, int flags, int mode)
+extfs_open (vfs *me, char *file, int flags, int mode, off_t offset)
 {
     struct pseudofile *extfs_info;
     struct archive *archive;
@@ -693,6 +693,13 @@
     if (local_handle == -1)
 	ERRNOR (EIO, NULL);
 
+    if (IS_LINEAR(flags) && (offset > 0)) {
+	if (lseek(local_handle, offset, SEEK_SET) != offset) {
+	    close(local_handle);
+	    return 0;
+	}
+    }
+
     extfs_info = g_new (struct pseudofile, 1);
     extfs_info->archive = archive;
     extfs_info->entry = entry;
@@ -1252,7 +1259,7 @@
 static char *extfs_getlocalcopy (vfs *me, char *path)
 {
     struct pseudofile *fp = 
-        (struct pseudofile *) extfs_open (me, path, O_RDONLY, 0);
+        (struct pseudofile *) extfs_open (me, path, O_RDONLY, 0, 0);
     char *p;
     
     if (fp == NULL)
@@ -1270,7 +1277,7 @@
 static int extfs_ungetlocalcopy (vfs *me, char *path, char *local, int has_changed)
 {
     struct pseudofile *fp = 
-        (struct pseudofile *) extfs_open (me, path, O_RDONLY, 0);
+        (struct pseudofile *) extfs_open (me, path, O_RDONLY, 0, 0);
     
     if (fp == NULL)
         return 0;
Index: local.c
===================================================================
RCS file: /cvs/gnome/mc/vfs/local.c,v
retrieving revision 1.14
diff -u -b -B -r1.14 local.c
--- local.c	23 Sep 2002 06:45:33 -0000	1.14
+++ local.c	4 May 2003 07:34:37 -0000
@@ -17,7 +17,7 @@
  * */
     
 static void *
-local_open (vfs *me, char *file, int flags, int mode)
+local_open (vfs *me, char *file, int flags, int mode, off_t offset)
 {
     int *local_info;
     int fd;
@@ -25,6 +25,13 @@
     fd = open (file, NO_LINEAR(flags), mode);
     if (fd == -1)
 	return 0;
+
+    if (IS_LINEAR(flags) && (offset > 0)) {
+	if (lseek(fd, offset, SEEK_SET) != offset) {
+	    close(fd);
+	    return 0;
+	}
+    }
 
     local_info = g_new (int, 1);
     *local_info = fd;
Index: sfs.c
===================================================================
RCS file: /cvs/gnome/mc/vfs/sfs.c,v
retrieving revision 1.41
diff -u -b -B -r1.41 sfs.c
--- sfs.c	6 Dec 2002 02:18:10 -0000	1.41
+++ sfs.c	4 May 2003 07:34:37 -0000
@@ -147,7 +147,7 @@
 }
 
 static void *
-sfs_open (vfs *me, char *path, int flags, int mode)
+sfs_open (vfs *me, char *path, int flags, int mode, off_t offset)
 {
     int *sfs_info;
     int fd;
@@ -156,6 +156,13 @@
     fd = open (path, NO_LINEAR(flags), mode);
     if (fd == -1)
 	return 0;
+
+    if (IS_LINEAR(flags) && (offset > 0)) {
+	if (lseek(fd, offset, SEEK_SET) != offset) {
+	    close(fd);
+	    return 0;
+	}
+    }
 
     sfs_info = g_new (int, 1);
     *sfs_info = fd;
Index: vfs.c
===================================================================
RCS file: /cvs/gnome/mc/vfs/vfs.c,v
retrieving revision 1.109
diff -u -b -B -r1.109 vfs.c
--- vfs.c	26 Feb 2003 17:43:18 -0000	1.109
+++ vfs.c	4 May 2003 07:34:37 -0000
@@ -386,6 +386,7 @@
 {
     int  handle;
     int  mode;
+    off_t offset;
     void *info;
     va_list ap;
 
@@ -394,7 +395,12 @@
 
     /* Get the mode flag */	/* FIXME: should look if O_CREAT is present */
     va_start (ap, flags);
+    if (flags & O_CREAT) {
     mode = va_arg (ap, int);
+    }
+    if (flags & O_LINEAR) {
+	offset = va_arg (ap, off_t);
+    }
     va_end (ap);
     
     if (!vfs->open) {
@@ -402,7 +408,7 @@
 	return -1;
     }
 
-    info = (*vfs->open) (vfs, file, flags, mode);	/* open must be supported */
+    info = (*vfs->open) (vfs, file, flags, mode, offset);	/* open must be supported */
     g_free (file);
     if (!info){
 	errno = ferrno (vfs);
Index: vfs.h
===================================================================
RCS file: /cvs/gnome/mc/vfs/vfs.h,v
retrieving revision 1.73
diff -u -b -B -r1.73 vfs.h
--- vfs.h	11 Dec 2002 09:36:51 -0000	1.73
+++ vfs.h	4 May 2003 07:34:37 -0000
@@ -43,7 +43,7 @@
 			       
         int   (*which)         (vfs *me, char *path);
 			       
-	void  *(*open) 	       (vfs *me, char *fname, int flags, int mode);
+	void  *(*open) 	       (vfs *me, char *fname, int flags, int mode, off_t offset);
 	int   (*close) 	       (void *vfs_info);
 	int   (*read)  	       (void *vfs_info, char *buffer, int count);
 	int   (*write) 	       (void *vfs_info, char *buf, int count);
Index: xdirentry.h
===================================================================
RCS file: /cvs/gnome/mc/vfs/xdirentry.h,v
retrieving revision 1.24
diff -u -b -B -r1.24 xdirentry.h
--- xdirentry.h	1 Oct 2002 17:03:55 -0000	1.24
+++ xdirentry.h	4 May 2003 07:34:37 -0000
@@ -224,7 +224,7 @@
 int vfs_s_lstat (vfs *me, char *path, struct stat *buf);
 int vfs_s_fstat (void *fh, struct stat *buf);
 int vfs_s_readlink (vfs *me, char *path, char *buf, int size);
-void *vfs_s_open (vfs *me, char *file, int flags, int mode);
+void *vfs_s_open (vfs *me, char *file, int flags, int mode, off_t offset);
 int vfs_s_read (void *fh, char *buffer, int count);
 int vfs_s_write (void *fh, char *buffer, int count);
 int vfs_s_lseek (void *fh, off_t offset, int whence);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]