After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 711620 - curlftpsink: Create a temporary file during FTP transfer/upload
curlftpsink: Create a temporary file during FTP transfer/upload
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other Linux
: Normal enhancement
: 1.3.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-11-07 15:04 UTC by Haridass
Modified: 2014-01-14 19:28 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
This is the patch which will have this temporary file feature while uploading FTP files (9.51 KB, patch)
2013-11-07 15:04 UTC, Haridass
needs-work Details | Review
I have modified the code such rename_from will be freed in the end. (9.31 KB, patch)
2013-11-08 13:07 UTC, Haridass
needs-work Details | Review
Added comments given by Olivier Crete (9.36 KB, patch)
2013-12-06 11:11 UTC, Haridass
needs-work Details | Review
Patch with "git format-patch" (9.63 KB, patch)
2013-12-17 11:11 UTC, Haridass
committed Details | Review

Description Haridass 2013-11-07 15:04:04 UTC
Created attachment 259195 [details] [review]
This is the patch which will have this temporary file feature while uploading FTP files

Use temporary file - Some FTP servers do not allow an existing file 
to be overwritten by a new file with the same name. When this option 
is enabled, the new file will be uploaded with a temporary name. The 
original file is then deleted and the new file is given the original 
file name.

Problem can be observerd when using a bad 3G connection because:

If you upload the file, overwriting the existing one directly and the connection is lost, you end up in a corrupted file. If you work with the temporary upload instead, the file is only overwritten in case of a successful upload. So no corrupted files at all.
Comment 1 Sebastian Dröge (slomo) 2013-11-07 17:41:28 UTC
Review of attachment 259195 [details] [review]:

::: ext/curl/gstcurlftpsink.c
@@ +206,3 @@
+    timeinfo = localtime (&rawtime);
+    strftime (timeinfo_buffer, TIMEINFO_BUFFERSIZE, "%d_%B_%Y_%I_%M_%S_%p", timeinfo);
+    rename_from = g_strdup_printf ("%s%s%s", RENAME_FROM, tmpfile_name, timeinfo_buffer);

rename_from is only needed in the "if" part below, and leaked otherwise

@@ +208,3 @@
+    rename_from = g_strdup_printf ("%s%s%s", RENAME_FROM, tmpfile_name, timeinfo_buffer);
+
+    last_slash = strrchr (basesink->file_name, G_DIR_SEPARATOR);

You probably want to use "/" as a separator always here, instead of "\\" on Windows. But isn't the filename here guaranteed to be just a filename and the path is separate from that?
Comment 2 Haridass 2013-11-08 13:07:40 UTC
Created attachment 259266 [details] [review]
I have modified the code such rename_from will be freed in the end.

To answer your question, the basesink->file_name can contain either filename alone or with the pathname. It depends on the user needs. I have modified the code accordingly.

rename_from is ensured that, it is cleared in the end.

Eg. "filename.jpg" or "directory/filename.jpg".
Comment 3 Haridass 2013-11-08 13:09:10 UTC
Please see the attached patch.
Comment 4 Haridass 2013-11-18 11:39:26 UTC
Hi,

Any inputs for me?

Thanks,
Hari.
Comment 5 Haridass 2013-11-28 13:41:20 UTC
Hi,

Any inputs for me?

Thanks,
Hari.
Comment 6 Olivier Crête 2013-12-06 00:13:48 UTC
Review of attachment 259266 [details] [review]:

::: ext/curl/gstcurlftpsink.c
@@ +139,3 @@
+  g_object_class_install_property (gobject_class, PROP_CREATE_TEMP_FILE,
+      g_param_spec_boolean ("create-tmpfile", "Enable or disable temporary file transfer",
+          "Creating a temporary file ensures a proper file transfer",

Might benefit from something more descriptive like "Upload to a temporary file then replace the original file"

@@ +197,3 @@
+        tmpfile_name = g_strdup_printf ("%s", sink->tmpfile_name);
+    } else {
+        tmpfile_name = g_strdup_printf ("%s", UPLOAD_FILE_AS);

Might be better to have something random as the default ? Along the files of rename_to + ".tmp.%04%04X", g_random_int(), g_random_int()
Comment 7 Haridass 2013-12-06 11:11:19 UTC
Created attachment 263654 [details] [review]
Added comments given by Olivier Crete

Hi,

  I have added commments given by Olivier Crete. kindly review my patch.

  

Regards,
Haridass.
Comment 8 Olivier Crête 2013-12-06 19:18:10 UTC
Review of attachment 263654 [details] [review]:

::: ext/curl/gstcurlftpsink.h
@@ +46,2 @@
   /*< private > */
+  struct curl_slist *headerlist;

Do you need to keep the list alive after setting it on libcurl?
Comment 9 Haridass 2013-12-09 13:48:32 UTC
Hi,

I did not get your point, can you please explain a bit more? What do you mean by keeping the list alive?

Regards,
Haridass.
Comment 10 Olivier Crête 2013-12-09 17:19:42 UTC
(In reply to comment #9)
> I did not get your point, can you please explain a bit more? What do you mean
> by keeping the list alive?

Why do you put this list in the pbject structure instead of keeping it local to the function ?
Comment 11 Haridass 2013-12-10 10:57:20 UTC
(In reply to comment #10)
> (In reply to comment #9)
> > I did not get your point, can you please explain a bit more? What do you mean
> > by keeping the list alive?
> 
> Why do you put this list in the pbject structure instead of keeping it local to
> the function ?

I got your point now. Yes, this list should be kept alive. We cannot keep this local to the function.
Comment 12 Sebastian Dröge (slomo) 2013-12-17 09:53:01 UTC
Comment on attachment 263654 [details] [review]
Added comments given by Olivier Crete

Now only attach this in "git format-patch" style with your real name and mail address and it can be included :)
Comment 13 Haridass 2013-12-17 11:11:58 UTC
Created attachment 264403 [details] [review]
Patch with "git format-patch"

Hi,

Added the patch with "git format-patch". 


Regards,
Haridass.
Comment 14 Sebastian Dröge (slomo) 2013-12-17 11:18:38 UTC
commit 23ab7d8c4979bff05e37e2e4aff5a74da2b36c3a
Author: Haridass Selvaraj <haridasj@axis.com>
Date:   Tue Dec 17 12:06:13 2013 +0100

    curlftpsink: Optionally create a temporary file during FTP transfer/upload
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711620