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 700359 - Use GFile instead of stdio in et_core.c in EasyTAG
Use GFile instead of stdio in et_core.c in EasyTAG
Status: RESOLVED FIXED
Product: easytag
Classification: Other
Component: general
master
Other Linux
: Normal enhancement
: 2.1
Assigned To: EasyTAG maintainer(s)
EasyTAG maintainer(s)
Depends on:
Blocks: 700050
 
 
Reported: 2013-05-15 05:52 UTC by Abhinav
Modified: 2013-05-18 13:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Use GIO instead of stdio in et_core.c (2.84 KB, patch)
2013-05-15 06:00 UTC, Abhinav
needs-work Details | Review
Did all the changes (8.76 KB, patch)
2013-05-15 07:52 UTC, Abhinav
needs-work Details | Review
Done!! (9.62 KB, patch)
2013-05-15 09:10 UTC, Abhinav
none Details | Review
There was whitespaces error in previous patch (9.59 KB, patch)
2013-05-15 09:18 UTC, Abhinav
needs-work Details | Review
Corrected one now!! (9.63 KB, patch)
2013-05-15 10:09 UTC, Abhinav
none Details | Review
Ignore previous one please!! (9.63 KB, patch)
2013-05-15 10:11 UTC, Abhinav
committed Details | Review
This patch will fix the above bug (941 bytes, patch)
2013-05-18 13:10 UTC, Abhinav
committed Details | Review

Description Abhinav 2013-05-15 05:52:37 UTC
EasyTAG currently uses fopen, fclose in et_core.c. Instead of this use GIO from GFile. 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-15 06:00:13 UTC
Created attachment 244271 [details] [review]
Use GIO instead of stdio in et_core.c
Comment 2 David King 2013-05-15 06:28:54 UTC
Review of attachment 244271 [details] [review]:

::: src/et_core.c
@@ +2764,2 @@
     /* Show/hide 'AccessStatusIcon' */
+    if (g_file_query_exists (file, NULL))

You need to additionally check if the file is readable by the current user, as in the switch statement in the else branch. As the g_file_query_exists() documentation mentions nothing of setting errno, you cannot assume that it does.

@@ +4586,2 @@
     {
         gchar *filename_utf8 = filename_to_display(filename);

As you have the GFileInfo, you should get the display name using g_file_info_get_display_name(). However, in this case querying the file for information has already failed. It would be best to change this function (ET_Read_File_Info) to take a GError argument and to set the error if an error occurs, so that the calling function can display a log message as necessary.

@@ +4598,3 @@
     ETFileInfo->samplerate = 0;
     ETFileInfo->mode       = 0;
+    ETFileInfo->size       = g_file_info_get_size (info);

g_file_info_get_size() returns a goffset, so you should change the size field of ET_File_Info to also be a goffset.
Comment 3 Abhinav 2013-05-15 07:52:40 UTC
Created attachment 244277 [details] [review]
Did all the changes

In ET_Display_File_Data_To_UI, compiler gives warning about message and emblem_icon. But all the cases has been covered as you can see so that message and emblem_icon could be initialized.
Also, in that case the code written could have been better to read if I would have used GFileInputStream to open the file (in this case too checking for write and execute permissions would not be possible) and check for errors. But I don't think it would be much efficient as compared to using GFileInfo.
Also, the code has been changed according to the switch case statement. I mean the way switch case statement would behave, similarly this will.
Comment 4 David King 2013-05-15 08:06:06 UTC
Review of attachment 244277 [details] [review]:

::: src/et_core.c
@@ +2781,3 @@
+    attributes = g_strjoin (",", G_FILE_ATTRIBUTE_ACCESS_CAN_READ,
+                            G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
+                            G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE, NULL);

You do not need to join the strings together dynamically. Simply concatenate the defines together like:

G_FILE_ATTRIBUTE_ACCESS_CAN_READ "," G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE "," G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE

@@ +2835,3 @@
+    gtk_entry_set_icon_from_gicon (GTK_ENTRY (FileEntry),
+                                   GTK_ENTRY_ICON_SECONDARY,
+                                   emblem_icon);

You set the icon twice here in the all-permissions case. Additionally, you use emblem_icon, which has not been initialized in the all-permissions case. I guess that this is the compiler warning that you mentioned.

@@ +2837,3 @@
+                                   emblem_icon);
+    gtk_entry_set_icon_tooltip_text (GTK_ENTRY (FileEntry),
+                                     GTK_ENTRY_ICON_SECONDARY, message);

The same comment applies here for message as it does for emblem_icon.
Comment 5 Abhinav 2013-05-15 09:10:34 UTC
Created attachment 244287 [details] [review]
Done!!

oh!! yeah I realized it for all permissions case. Apology to gcc :P.
Comment 6 Abhinav 2013-05-15 09:18:41 UTC
Created attachment 244289 [details] [review]
There was whitespaces error in previous patch

I didn't know why, but git apply --check doesn't check for whitespaces :o.
I applied the patch then got whitespace error.
Comment 7 David King 2013-05-15 09:32:48 UTC
Review of attachment 244289 [details] [review]:

::: src/et_core.c
@@ +573,3 @@
+            if (!ET_Read_File_Info (filename, ETFileInfo, &error))
+            {
+                gchar *filename_utf8 = filename_to_display(filename);

Missing a space before the opening parenthesis.

@@ +577,3 @@
+                           filename_utf8, error->message);
+                g_error_free (error);
+                g_free(filename_utf8);

Missing a space before the opening parenthesis.

@@ +2777,3 @@
 
+    file = g_file_new_for_path (cur_filename);
+    attributes = G_FILE_ATTRIBUTE_ACCESS_CAN_READ "," G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE "," G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE;

There is no need to have a separate variable for this.

@@ +2861,3 @@
     gtk_label_set_text(GTK_LABEL(FileIndex),text);
+    g_object_unref (file);
+    g_free (attributes);

You should not free something that has not been dynamically allocated.
Comment 8 Abhinav 2013-05-15 10:09:25 UTC
Created attachment 244295 [details] [review]
Corrected one now!!
Comment 9 Abhinav 2013-05-15 10:11:16 UTC
Created attachment 244296 [details] [review]
Ignore previous one please!!
Comment 10 David King 2013-05-15 16:56:59 UTC
Review of attachment 244296 [details] [review]:

I pushed a modified version of this patch to master as commit b37e622a8358864b9f2e0317ad014d709a5d6af1, and improved it a bit with commit ace584e56ab3de44a5548d920f01985cf6e36307.
Comment 11 Abhinav 2013-05-18 13:09:30 UTC
Bug is being reopened, as there is an error message.

GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed

while renaming the file(s)
Comment 12 Abhinav 2013-05-18 13:10:37 UTC
Created attachment 244613 [details] [review]
This patch will fix the above bug
Comment 13 David King 2013-05-18 13:57:06 UTC
Comment on attachment 244613 [details] [review]
This patch will fix the above bug

Thanks. I pushed a modified patch to master as commit 8f26298550ad88b62bbf7d19d986d9baf291fcc5.