GNOME Bugzilla – Bug 569061
crash with write protected file
Last modified: 2009-08-21 15:08:19 UTC
crash while saving to a write proteced file: Distribution: Gentoo Base System release 2.0.0 Gnome Release: 2.24.3 2009-01-24 (Gentoo) BugBuddy Version: 2.24.2 System: Linux 2.6.28-gentoo #3 SMP Mon Jan 5 15:41:04 CET 2009 x86_64 X Vendor: The X.Org Foundation X Vendor Release: 10599003 Selinux: No Accessibility: Disabled GTK+ Theme: Clearlooks Icon Theme: gnome Memory status: size: 214798336 vsize: 214798336 resident: 47321088 share: 12464128 rss: 47321088 rss_rlim: 18446744073709551615 CPU usage: start_time: 1232882814 rtime: 48 utime: 43 stime: 5 cutime:0 cstime: 0 timeout: 0 it_real_value: 0 frequency: 100 Backtrace was generated from '/usr/bin/gtranslator' [?1034h[Thread debugging using libthread_db enabled] [New Thread 0x7f47b6d8e6f0 (LWP 4122)] 0x00007f47b66b43b5 in __libc_waitpid (pid=4124, stat_loc=0x7fffbedb73d0, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:32 in ../sysdeps/unix/sysv/linux/waitpid.c
+ Trace 211845
Thread 1 (Thread 0x7f47b6d8e6f0 (LWP 4122))
Created attachment 127204 [details] [review] gtranslator-file-readonly
Thanks for the patch. I think we should convert the C++ sytle comments //"error querying file info for %s: %s", location, error->message; to C style /* */. This is also copy & paste four times. Is it worth using a function four times here?
I would like to readuce those test to one (in po.c) . Then I tried to test for the readonly file in po.c but gtranslator crashed again. Those GTR_PO_* error are not fatal?
Created attachment 127693 [details] [review] gtranslator-file-readonly Fixed error in previous patch. - Only one readonly check - Display fatal error
Hmm its odd the patch does not compile for me po.c: In Funktion »gtranslator_po_save_file«: po.c:789: Fehler: Anfrage nach Element »code« in etwas, was keine Struktur oder Variante ist po.c:790: Warnung: format »%s« erwartet Typ »char *«, aber Argument 4 hat Typ »struct GFile *« po.c:794: Fehler: Anfrage nach Element »message« in etwas, was keine Struktur oder Variante ist po.c:794: Warnung: format »%s« erwartet Typ »char *«, aber Argument 4 hat Typ »struct GFile *« make[4]: *** [po.lo] Fehler 1
I rewrite the patch provided by Florian and i think that works, but i think that can be improved. Now same error is displayed when try to overwrite a read-only (ro) file, or when the current file is ro and we modified and try to save it. Gedit makes it in a different way, when you open a file if it is ro "Save" button can't be clicked you must used "Save as". I think this is the more correct solution.
Created attachment 141094 [details] [review] Before write the file checks if it is read only, in this case displays an error message. This can be a provisional fix of bug 569061
Some things about your patch: +static gboolean +is_read_only (gchar *filename) It should be const gchar * + location = g_file_new_for_path(filename); here the coding style is wrong + info = g_file_query_info (location, + G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, + G_FILE_QUERY_INFO_NONE, + NULL, + NULL); it is missing the g_object_unref for location + if (is_read_only(filename)) + { + g_set_error(error, + GTR_PO_ERROR, + GTR_PO_ERROR_READONLY, + _("The file %s is read-only, and can not be overwritten"), + filename); + g_free (filename); + return; + } + here you are using a different coding style.
Created attachment 141275 [details] [review] Before save a file checks if it is read only, in this case displays an error message. I correct missing g_object_unref and correct the code style following gnu style as psanxiao recommended me.
The patch has been applied into master. It will be available in the next major software release. Thank you.