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 700874 - Use GFile instead of stdio in vcedit.c in EasyTAG
Use GFile instead of stdio in vcedit.c in EasyTAG
Status: RESOLVED FIXED
Product: easytag
Classification: Other
Component: general
master
Other Linux
: Normal normal
: 2.1
Assigned To: EasyTAG maintainer(s)
EasyTAG maintainer(s)
Depends on:
Blocks: 700050
 
 
Reported: 2013-05-23 06:58 UTC by Abhinav
Modified: 2013-05-23 18:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
This patch will fix the above bug (27.75 KB, patch)
2013-05-23 07:31 UTC, Abhinav
needs-work Details | Review
Did the changes (30.34 KB, patch)
2013-05-23 13:37 UTC, Abhinav
needs-work Details | Review
I added Error Codes and Domain to ogg_header.h and ogg_header.c (30.16 KB, patch)
2013-05-23 17:45 UTC, Abhinav
committed Details | Review

Description Abhinav 2013-05-23 06:58:56 UTC
Currently EasyTAG uses stdio functions fread, fopen, fclose, feof in
src/vedit.c. These stdio functions could be replaced with much better and high
level GFile from GIO. This will simplify file handling, name of file handling
encoding, could also help in making Asynchronous I/O and with this EasyTAG
could be used over NFS and CIFS/Samba shares.
Comment 1 Abhinav 2013-05-23 07:31:22 UTC
Created attachment 245102 [details] [review]
This patch will fix the above bug

Here, I have used GDataInputStream and GDataOutputStream to do to IO operations in binary mode, as FILE *file was opened in binary mode.
vedit_open and vcedit_save functions will accept GError and GFile. Also, state will have GDataInputStream *in as member not GFile *in, because in _fetch_next_packet state->in has to be read, hence it will better that state->in is read directly instead of first opening another GDataInputStream from GFile and at the end closing it, this would ofcourse affect the performance.
Also, here I have edited vcedit.c, ogg_header.c and ogg_tag.c. ogg_header.c and ogg_tag.c are edited only upto the level of supporting vcedit.c. These files have to be changed, but they will be changed fully in their own Bugs and patches.
Also, at many places where GError **error has to be set and no Domain and Type is available for them, I have used G_IO_ERROR and G_IO_ERROR_FAILED and set the message accordingly.
I have also removed state->lasterror member because in every function GError ** is passed and it will take the responsibility of error reporting.
I also deleted state->read and state->write and function vcedit_open_callback, as vcedit_open will handle everything from now.
Also, please check error messages in _fetch_next_packet, although I have set them by reading the documentation of libvorbis and ogg_*, but still I think they are not elaborative as they should be.
Also, I have checked and in my case everything runs fine about ogg files.
Comment 2 David King 2013-05-23 08:51:28 UTC
Review of attachment 245102 [details] [review]:

(In reply to comment #1)
> Also, at many places where GError **error has to be set and no Domain and Type
> is available for them, I have used G_IO_ERROR and G_IO_ERROR_FAILED and set the
> message accordingly.

You should add a new error domain for the errors which you wish to report, rather than reuse an existing one that is inappropriate.

::: src/ogg_header.c
@@ +186,1 @@
         fclose(file);

There is little point in continuing to open the file with fopen() only to close it here. Remove the code that opens the file with stdio if it is not needed.

::: src/vcedit.c
@@ +175,3 @@
         if(s->eosin)
+        {
+            g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,

As I said in the general comments, create a new GError domain for these errors.
Comment 3 Abhinav 2013-05-23 13:37:26 UTC
Created attachment 245128 [details] [review]
Did the changes

I created a new Error domain and codes as according to glib-Error-Reporting.html.
Also, I have removed that code using file, as it was unnecessary. File was also closed earlier in some other places also, where it was not required to make it remain open.
Comment 4 David King 2013-05-23 14:36:07 UTC
Review of attachment 245128 [details] [review]:

::: src/et_core.h
@@ +335,3 @@
+ * Error domain and codes for errors while reading/writing OGG files
+ */
+GQuark et_ogg_error_quark (void);

As this is an error fro OGG tags, it should be in either ogg_tag.h or ogg_header.h.

@@ +341,3 @@
+typedef enum
+{
+    ET_OGG_ERROR_EOS,     /* reached end of logical bitstream */

The gtk-doc documentation syntax for enums is a little bit awkward, but you should use it rather than this syntax. See the gtk-doc manual for more details:

https://developer.gnome.org/gtk-doc-manual/unstable/documenting_symbols.html

@@ +354,3 @@
+    ET_OGG_ERROR_FAILED,  /* corrupt or missing data */
+    ET_OGG_ERROR_OUTPUT   /* error writing stream to output */
+}ETOGGError;

Use "EtOGGError" not "ETOGGError".

::: src/ogg_tag.c
@@ +114,2 @@
 /*************
+ * Functions *make

Oops, slip of the fingers.

@@ +184,3 @@
     state = vcedit_new_state();    // Allocate memory for 'state'
+    gfile = g_file_new_for_path (filename);
+    if (!vcedit_open (state, gfile, &error))

Add an empty line before the if.

@@ +702,1 @@
         fclose(file_in);

The file was already closed above.

@@ +835,3 @@
 
+    /* Write tag to 'gfile_in' in all cases */
+    if ( Ogg_Tag_Write_File (gfile_in, filename, state, &error) == FALSE)

No space after the first parenthesis.

::: src/vcedit.c
@@ +497,3 @@
+    ostream = g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE,
+                              NULL, error);
+    if (!ostream)

Add an empty line before the if.

@@ +549,3 @@
     }
 
+    while (_fetch_next_packet(state, &op, &ogin, error))

Add a space before the opening parenthesis.

@@ +554,3 @@
         {
+            if (g_output_stream_write (G_OUTPUT_STREAM (dostream), ogout.header,
+                                       ogout.header_len, NULL, error) !=

Put the "!=" on the next line.

@@ +562,3 @@
+
+            if (g_output_stream_write (G_OUTPUT_STREAM (dostream), ogout.body,
+                                       ogout.body_len, NULL, error) !=

Same comment here, and all following instances.

@@ +714,3 @@
+        bytes = g_input_stream_read (G_INPUT_STREAM (state->in), buffer,
+                                     CHUNKSIZE, NULL, error);
+        if (bytes == -1)

Add an empty line before the if.
Comment 5 Abhinav 2013-05-23 17:45:23 UTC
Created attachment 245159 [details] [review]
I added Error Codes and Domain to ogg_header.h and ogg_header.c
Comment 6 David King 2013-05-23 18:48:19 UTC
Comment on attachment 245159 [details] [review]
I added Error Codes and Domain to ogg_header.h and ogg_header.c

Pushed a slightly modified version to master as commit 94b6a68b51347d10e6a5c9a07dc035a3e3ce025c, thanks.