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 644358 - Cannot save over read-only file
Cannot save over read-only file
Status: RESOLVED OBSOLETE
Product: tepl
Classification: Other
Component: File loading and saving
unspecified
Other Linux
: Low minor
: ---
Assigned To: Gtef maintainer(s)
Gtef maintainer(s)
Depends on: 786831
Blocks:
 
 
Reported: 2011-03-09 23:42 UTC by James "Doc" Livingston
Modified: 2018-02-27 09:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gtksourcefilesaver.c: Fix overwriting a readonly file (4.17 KB, patch)
2017-08-26 16:13 UTC, Nelson Benitez
none Details | Review
gtksourcefilesaver.c: Support overwriting a readonly file (5.61 KB, patch)
2017-08-29 17:37 UTC, Nelson Benitez
reviewed Details | Review

Description James "Doc" Livingston 2011-03-09 23:42:40 UTC
Steps to reproduce:
1) Create a read-only file somewhere you have write access to
2) Save a document, and in the file picker try to save it over the read-only file
3) See the 'The file "/path/to/file" is read-only. Do you want to try to replace it with the one you are saving?' dialog, and click Replace.

Expected Results:
The read-only file is overwritten, since I explicitly said I wanted to do that.

Actual Results:
It fails to save, and the info bar has the message "You do not have the permissions necessary to save the file. Please check that you typed the location correctly and try again."
Comment 1 Anirudh S 2011-03-13 17:43:29 UTC
I think the Expected Result should not happen due to the following reason.

A file is saved as read-only because it is not supposed to be written into. This means that, when the user opens it in a text editor, he should not be able to modify the contents of the text editor.

But, opening a blank text editor and typing contents and saving it under the same name effectively means the same thing i.e. the original file under that particular name, is being modified.

Since both are the same, it defeats the purpose of making the original file as read-only and the Expected Result must not happen.

I hope that my argument is correct and I'd suggest that this issue be closed.
Comment 2 James "Doc" Livingston 2011-03-18 23:14:34 UTC
I'm not opposed to not being able to overwrite a readonly file in a writable location, however a lot of other applications let you do it.

More importantly, the GTK save dialog explicitly asked me if I want to replace the read-only file. It shouldn't do that if the application is not going to let me replace it.
Comment 3 jessevdk@gmail.com 2011-03-19 08:36:34 UTC
This requires a bit more investigation, I'm not sure why gio refuses to save the file in this case, maybe we are just missing some flag
Comment 4 Sébastien Wilmet 2015-06-16 09:32:54 UTC
Still a bug with gedit 3.14.
Comment 5 Nelson Benitez 2017-08-26 16:09:29 UTC
This bug it's better fixed at gtksourceview level, so in Gedit or in any other editor using gtksourceview this works as expected without any change.

Changed product to gtksourceview.
Comment 6 Nelson Benitez 2017-08-26 16:13:49 UTC
Created attachment 358487 [details] [review]
gtksourcefilesaver.c: Fix overwriting a readonly file

When asked to 'save as' over a readonly file, do the
appropiate and pass G_FILE_CREATE_REPLACE_DESTINATION
to g_file_replace_async() so the operation does not
fail and performs succesfully.


This patch together with the glib patch makes Gedit don't fail when saving over a readonly file.
Comment 7 Sébastien Wilmet 2017-08-27 09:46:03 UTC
I wanted the file loading and saving code in GtkSourceView to be frozen, to deprecate them later. I'm working on a new file loader implementation in the Tepl library, with a higher-level API.
Comment 8 Sébastien Wilmet 2017-08-28 08:34:27 UTC
Review of attachment 358487 [details] [review]:

The G_FILE_CREATE_REPLACE_DESTINATION flag must be set only when the user has confirmed that the file can be replaced. I don't know if the GTK+ file chooser API permits to know that, but it would be required for this bug to be fixed properly.

Because the file saving API in GtkSourceView or Tepl can be used without launching a GtkFileChooserDialog, for example it can be used in a script, or the auto-save, in which case we must not replace a read-only file without asking the user first.
Comment 9 Sébastien Wilmet 2017-08-28 19:10:53 UTC
If the file saving operation comes from a "save as" action with a GtkFileChooser, configured with gtk_file_chooser_set_do_overwrite_confirmation(true), then we can probably assume that GTK+ has already asked the user whether to overwrite the read-only file (I say "probably" because I've not tested).

So what would be useful in the TeplFileSaver API is a way to configure the GFileCreateFlags.
Comment 10 Nelson Benitez 2017-08-29 17:36:45 UTC
(In reply to Sébastien Wilmet from comment #8)
> Review of attachment 358487 [details] [review] [review]:
> 
> The G_FILE_CREATE_REPLACE_DESTINATION flag must be set only when the user
> has confirmed that the file can be replaced. I don't know if the GTK+ file
> chooser API permits to know that, but it would be required for this bug to
> be fixed properly.
> 
> Because the file saving API in GtkSourceView or Tepl can be used without
> launching a GtkFileChooserDialog, for example it can be used in a script, or
> the auto-save, in which case we must not replace a read-only file without
> asking the user first.

The patch only works when 'saving as', so the auto-save does not trigger this.

I made patch so to avoid apps having to provide an explicit flag for this, as they usually are graphical apps using filechooser, but as you say this can be used in scripts, I'm attaching new patch that just adds a new flag to activate the feature, so scripts and Gedit and others will have to provide the flag to confirm they want this feature.
Comment 11 Nelson Benitez 2017-08-29 17:37:57 UTC
Created attachment 358712 [details] [review]
gtksourcefilesaver.c: Support overwriting a readonly file

When doing a 'save as' operation over a readonly file, and given
the flag GTK_SOURCE_FILE_SAVER_FLAGS_REPLACE_READONLY is passed,
do the appropiate and pass G_FILE_CREATE_REPLACE_DESTINATION to
g_file_replace_async() so the operation does not fail and performs
succesfully.
Comment 12 Sébastien Wilmet 2017-08-29 18:33:15 UTC
I was more thinking about adding a create-flags property (with type GFileCreateFlags). With getters and setters. Otherwise each time that a new enum value is added to GFileCreateFlags, it would need to be duplicated in TeplFileSaverFlags.

And note: TeplFileSaver, not GtkSourceFileSaver.
Comment 13 Sébastien Wilmet 2017-08-29 18:36:02 UTC
Anyway, I'm not really interested right now to fix this bug, it's a low-priority minor bug. When the GIO bug will be fixed, then we can think about using that in Tepl, in the future. But it's the kind of thing that takes me more time to review your patches than doing the actual work myself…
Comment 14 GNOME Infrastructure Team 2018-02-27 09:58:22 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/tepl/issues/1.