Blame SOURCES/0027-Delete-files-when-upload-fails.patch

bd689f
From 6224ecc5ac209323baa775880c0602c3fde3590a Mon Sep 17 00:00:00 2001
bd689f
From: Martin Sehnoutka <msehnout@redhat.com>
bd689f
Date: Thu, 17 Nov 2016 13:10:41 +0100
bd689f
Subject: [PATCH 27/59] Delete files when upload fails.
bd689f
bd689f
Previously the uploaded file wasn't removed when the network was
bd689f
disconnected. Now it is successfully deleted.
bd689f
---
bd689f
 ftpcodes.h  |  3 ++-
bd689f
 ftpdataio.c |  8 ++++++++
bd689f
 main.c      |  2 +-
bd689f
 postlogin.c |  9 ++++++++-
bd689f
 session.h   |  1 +
bd689f
 sysutil.c   | 10 ++++++++++
bd689f
 sysutil.h   |  1 +
bd689f
 7 files changed, 31 insertions(+), 3 deletions(-)
bd689f
bd689f
diff --git a/ftpcodes.h b/ftpcodes.h
bd689f
index 81e25c5..54dfae7 100644
bd689f
--- a/ftpcodes.h
bd689f
+++ b/ftpcodes.h
bd689f
@@ -15,7 +15,8 @@
bd689f
 #define FTP_PBSZOK            200
bd689f
 #define FTP_PROTOK            200
bd689f
 #define FTP_OPTSOK            200
bd689f
-#define FTP_ALLOOK            202
bd689f
+#define FTP_ALLOOK            200
bd689f
+#define FTP_ALLOIGN           202
bd689f
 #define FTP_FEAT              211
bd689f
 #define FTP_STATOK            211
bd689f
 #define FTP_SIZEOK            213
bd689f
diff --git a/ftpdataio.c b/ftpdataio.c
bd689f
index 00f9021..c859d80 100644
bd689f
--- a/ftpdataio.c
bd689f
+++ b/ftpdataio.c
bd689f
@@ -242,6 +242,10 @@ init_data_sock_params(struct vsf_session* p_sess, int sock_fd)
bd689f
   /* Start the timeout monitor */
bd689f
   vsf_sysutil_install_io_handler(handle_io, p_sess);
bd689f
   start_data_alarm(p_sess);
bd689f
+  if(tunable_delete_failed_uploads)
bd689f
+  {
bd689f
+    vsf_sysutil_rcvtimeo(sock_fd);
bd689f
+  }
bd689f
 }
bd689f
 
bd689f
 static void
bd689f
@@ -615,6 +619,10 @@ do_file_recv(struct vsf_session* p_sess, int file_fd, int is_ascii)
bd689f
     else if (retval == 0 && !prev_cr)
bd689f
     {
bd689f
       /* Transfer done, nifty */
bd689f
+      if (tunable_delete_failed_uploads &&
bd689f
+          !is_ascii && p_sess->upload_size > 0 &&
bd689f
+          p_sess->upload_size != ret_struct.transferred)
bd689f
+        ret_struct.retval = -2;
bd689f
       return ret_struct;
bd689f
     }
bd689f
     num_to_write = (unsigned int) retval;
bd689f
diff --git a/main.c b/main.c
bd689f
index f1e2f69..f039081 100644
bd689f
--- a/main.c
bd689f
+++ b/main.c
bd689f
@@ -44,7 +44,7 @@ main(int argc, const char* argv[])
bd689f
     /* Login */
bd689f
     1, 0, INIT_MYSTR, INIT_MYSTR,
bd689f
     /* Protocol state */
bd689f
-    0, 1, INIT_MYSTR, 0, 0,
bd689f
+    0, 0, 1, INIT_MYSTR, 0, 0,
bd689f
     /* HTTP hacks */
bd689f
     0, INIT_MYSTR,
bd689f
     /* Session state */
bd689f
diff --git a/postlogin.c b/postlogin.c
bd689f
index 29958c0..e473c34 100644
bd689f
--- a/postlogin.c
bd689f
+++ b/postlogin.c
bd689f
@@ -356,7 +356,14 @@ process_post_login(struct vsf_session* p_sess)
bd689f
     }
bd689f
     else if (str_equal_text(&p_sess->ftp_cmd_str, "ALLO"))
bd689f
     {
bd689f
-      vsf_cmdio_write(p_sess, FTP_ALLOOK, "ALLO command ignored.");
bd689f
+      if (tunable_delete_failed_uploads && !p_sess->is_ascii)
bd689f
+      {
bd689f
+        p_sess->upload_size = (filesize_t)vsf_sysutil_atoi(str_getbuf(&p_sess->ftp_cmd_str)+5);
bd689f
+        vsf_cmdio_write(p_sess, FTP_ALLOOK, "The filesize has been allocated.");
bd689f
+      }
bd689f
+      else {
bd689f
+        vsf_cmdio_write(p_sess, FTP_ALLOIGN, "ALLO command ignored.");
bd689f
+      }
bd689f
     }
bd689f
     else if (str_equal_text(&p_sess->ftp_cmd_str, "REIN"))
bd689f
     {
bd689f
diff --git a/session.h b/session.h
bd689f
index 3e8fdd5..4eccf46 100644
bd689f
--- a/session.h
bd689f
+++ b/session.h
bd689f
@@ -41,6 +41,7 @@ struct vsf_session
bd689f
   struct mystr anon_pass_str;
bd689f
 
bd689f
   /* Details of the FTP protocol state */
bd689f
+  filesize_t upload_size;
bd689f
   filesize_t restart_pos;
bd689f
   int is_ascii;
bd689f
   struct mystr rnfr_filename_str;
bd689f
diff --git a/sysutil.c b/sysutil.c
bd689f
index 099748f..42bcdf8 100644
bd689f
--- a/sysutil.c
bd689f
+++ b/sysutil.c
bd689f
@@ -680,6 +680,16 @@ vsf_sysutil_activate_keepalive(int fd)
bd689f
   }
bd689f
 }
bd689f
 
bd689f
+void
bd689f
+vsf_sysutil_rcvtimeo(int fd)
bd689f
+{
bd689f
+  struct timeval tv;
bd689f
+
bd689f
+  tv.tv_sec = tunable_data_connection_timeout;
bd689f
+  tv.tv_usec = 0;
bd689f
+  setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval));
bd689f
+}
bd689f
+
bd689f
 void
bd689f
 vsf_sysutil_activate_reuseaddr(int fd)
bd689f
 {
bd689f
diff --git a/sysutil.h b/sysutil.h
bd689f
index 13153cd..2886bbc 100644
bd689f
--- a/sysutil.h
bd689f
+++ b/sysutil.h
bd689f
@@ -266,6 +266,7 @@ void vsf_sysutil_dns_resolve(struct vsf_sysutil_sockaddr** p_sockptr,
bd689f
                              const char* p_name);
bd689f
 /* Option setting on sockets */
bd689f
 void vsf_sysutil_activate_keepalive(int fd);
bd689f
+void vsf_sysutil_rcvtimeo(int fd);
bd689f
 void vsf_sysutil_set_iptos_throughput(int fd);
bd689f
 void vsf_sysutil_activate_reuseaddr(int fd);
bd689f
 void vsf_sysutil_set_nodelay(int fd);
bd689f
-- 
bd689f
2.14.4
bd689f