[patch] Fix ftpfs uploading behavior.



Hi!

This patch fixes ftpfs uploading behavior.
Now if file is opened for writting only it will be not retrieved
to temporary file before uploading.

This is first approximation.
Test it carefully please.

Regards,
Andrew V. Samoilov.

ChangeLog:

* ftpfs.c (ftpfs_fh_open): Open data connection and remove localfile
if file is opened for writing only.
(ftpfs_fh_close): New function to close data connection opened in
ftpfs_fh_open().

--- vfs/ftpfs.c	Fri Feb  8 11:42:38 2002
+++ vfs/ftpfs.c	Wed Mar  6 10:05:00 2002
@@ -1683,6 +1686,35 @@ static void my_forget (char *file)
 
 static int ftpfs_fh_open (vfs *me, vfs_s_fh *fh, int flags, int mode)
 {
+    if (((flags & O_WRONLY) == O_WRONLY) && !(flags & (O_RDONLY|O_RDWR))){
+#ifdef HAVE_STRUCT_LINGER
+	struct linger li;
+#else
+	int li = 1;
+#endif
+	char *name = vfs_s_fullpath (me, fh->ino);
+
+	if (!name)
+	    return -1;
+	fh->handle = open_data_connection(me, fh->ino->super,
+		    (flags & O_APPEND) ? "APPE" : "STOR", name, TYPE_BINARY, 0);
+	g_free (name);
+
+	if (fh->handle < 0)
+	    return -1;
+#ifdef HAVE_STRUCT_LINGER
+	li.l_onoff = 1;
+	li.l_linger = 120;
+#endif
+	setsockopt(fh->handle, SOL_SOCKET, SO_LINGER, &li, sizeof(li));
+
+	if (fh->ino->localname){
+	    unlink (fh->ino->localname);
+	    g_free (fh->ino->localname);
+	    fh->ino->localname = NULL;
+	}
+	return 0;
+    }
     if (!fh->ino->localname)
 	if (vfs_s_retrieve_file (me, fh->ino)==-1)
 	    return -1;
@@ -1691,6 +1723,18 @@ static int ftpfs_fh_open (vfs *me, vfs_s
     return 0;
 }
 
+static int ftpfs_fh_close (vfs *me, vfs_s_fh *fh)
+{
+    if (fh->handle != -1){
+	close (fh->handle);
+	fh->handle = -1;
+	fh->changed = 0;
+	if (get_reply (me, fh->ino->SUP.sock, NULL, 0) != COMPLETE)
+	    ERRNOR (EIO, -1);
+    }
+    return 0;
+}
+
 static struct vfs_s_data ftp_data = {
     NULL,
     0,
@@ -1707,7 +1751,7 @@ static struct vfs_s_data ftp_data = {
     free_archive,
 
     ftpfs_fh_open, /* fh_open */
-    NULL, /* fh_close */
+    ftpfs_fh_close, /* fh_close */
 
     vfs_s_find_entry_linear,
     dir_load,



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