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 92896 - gedit won't save file in some instances
gedit won't save file in some instances
Status: RESOLVED FIXED
Product: gedit
Classification: Applications
Component: general
2.0.2
Other other
: Normal major
: ---
Assigned To: Gedit maintainers
Gedit maintainers
: 111100 148039 (view as bug list)
Depends on:
Blocks: 130389
 
 
Reported: 2002-09-10 00:08 UTC by Travis Saling
Modified: 2009-11-22 19:22 UTC
See Also:
GNOME target: ---
GNOME version: 2.9/2.10


Attachments
revised to fix bug 92896 following behavior of nedit (50.11 KB, patch)
2003-01-16 11:57 UTC, dsr
none Details | Review
patch against CVS for nedit behavior (3.63 KB, patch)
2003-06-06 20:47 UTC, Eric Ritezel
none Details | Review
Works fine while saving changed file in a directory that doesnt have write permission, but belongs to the user (6.59 KB, patch)
2004-05-08 18:04 UTC, Shreejith B L
rejected Details | Review
gnome-vfs based saving using auto backup strategy (19.28 KB, patch)
2004-11-13 04:11 UTC, David A Knight
none Details | Review
fixed version of vfs save patch (19.29 KB, patch)
2004-11-16 01:27 UTC, David A Knight
rejected Details | Review

Description Travis Saling 2002-09-10 00:09:21 UTC
Package: gedit
Severity: normal
Version: 2.0.2
Synopsis: gedit won't save file in some instances
Bugzilla-Product: gedit
Bugzilla-Component: general

Description:
Description of Problem:

If you own a file, and that file is in a directory for which you don't
have write permission, gedit will not let you save your changes.

Steps to reproduce the problem:
1. Find a directory that you don't have write permission in, but that
you can access (i.e. /usr/local/bin).
2. As root, touch a file and chown it to yourself (or chown an existing
file).
3. As yourself: open this file in gedit, make some changes and then hit
"save".

Actual Results:

An error box will pop up saying 'could not save the file "xxxxxx"'.

Expected Results:

You should be able to save the changes to the file.

How often does this happen?

Every time.

Additional Information:

If you make the directory writeable to yourself, then you can save the
document - no surprises there I guess. This does seem to be specific to
gedit, not to the filesystem, since I can open the same file in nedit
and it can save changes.




------- Bug moved to this database by unknown@bugzilla.gnome.org 2002-09-09 20:09 -------

Reassigning to the default owner of the component, maggi@athena.polito.it.

Comment 1 Andrew Sobala 2002-09-10 15:03:16 UTC
Confirming with 2.0.5. This may be gnome-vfs?
Comment 2 Paolo Maggi 2002-09-11 08:07:09 UTC
No, it is not a gnome-vfs problem since we are not using it for saving
files.
Comment 3 Paolo Maggi 2002-09-12 07:05:15 UTC
This is due to the way gedit saves files.

ATM, it needs that the file directory is writable since it saves a
temp file in the directory.

If a backup file has to be created, then the original file "test.txt"
is renamed "test.txt~".

Finally, the temp file is renamed "test.txt" (ad the original howner
and permissions are restored).

I don't see an easy way to fix this bug using the current algorithm.

Probably we should change the algo we are using but we should be very
careful in order to do not have regressions on other old problems.

Federico: Any idea? A part from "Man, Unix sucks" :-)
Comment 4 Matt Brubeck 2002-09-15 18:43:52 UTC
I am currently working on a fix for this bug.  I'll post a patch
hopefully within the next couple days.
Comment 5 Travis Saling 2002-09-15 19:04:19 UTC
What nedit does under these circumstances - when it discovers it can't
save the backup version of the file - is to notify the user that "the
backup file cannot be saved, so for this session backups are now
disabled" (or words to that effect). So you can still save your
changes to the existing file, but there's no fall-back in that instance. 

Comment 6 Paolo Maggi 2002-09-16 07:00:51 UTC
Ok, I like the nedit behavior, i.e. we should tell the user that gedit
is not able to create the backup file and ask her if she wants to save
the file anyway.

Matt: please note that gedit-document is a non-GUI class, so you need
to manage this problem using exceptions (i.e. GError).

Have you thought about using gnome-vfs to save files? You should be
able to find a preliminary patch on the gedit mailing list.

Thanks.
Comment 7 Paolo Maggi 2002-09-27 14:29:37 UTC
Matt: are you still working on it?
Comment 8 Matt Brubeck 2002-09-27 14:55:26 UTC
Yes, I am.  I'll have an initial patch soon.  I'm also addressing the
issue of backups for special files (e.g. links) and files owned by
other users -- these can't safely be backed up by renaming the
original file, because their attributes cannot be preserved.  I'm
planning to emulate the default "backupcopy=auto" behavior of the Vim
editor:

http://vimdoc.sourceforge.net/cgi-bin/vim2html2.pl?page=options.txt#'backupcopy'

That page has a good discussion of the issues.  Hopefully in the long
run we can get some of this code into a gnome-vfs API, so that each
app doesn't have to reinvent it.
Comment 9 Matt Brubeck 2002-10-05 19:40:13 UTC
Status update:  Still working on this.  Fell behind a bit because it
takes a long time for my computer to download and compile the GNOME
2.1.0 libraries now required for CVS gedit.
Comment 10 Paolo Maggi 2002-11-01 11:18:12 UTC
Matt: any news?
Comment 11 Matt Brubeck 2002-11-01 21:01:09 UTC
No, sorry -- I haven't had much time for hacking and have had trouble
keeping up with Gnome 2.1 CVS.  I may pick this up again in a few
weeks, but for now if someone else wants to work on it please go ahead.
Comment 12 Paolo Maggi 2002-12-30 14:12:11 UTC
Matt: any news?
Comment 13 Matt Brubeck 2002-12-30 18:23:15 UTC
No, still not working on this, and no plans for it right now.
Comment 14 dsr 2003-01-12 20:10:05 UTC
I couldn't access the vimtohtml discussion, and apologize
if I am repeating what was said there.

The attempt to write the temp file could fail 
  a) because the temp file name exists and is read only
  b) because the directory is read only

One solution is to reset the edited file to zero length
(equivalent to cat /dev/null > /usr/local/bin/fred.txt)
and then write the file directly. This would preserve the
file's flags.

This runs the risk that a failure occurs and the user is
left without the old or new versions of the file. To offset
that one might try copying the original file somewhere else
before updating it, e.g.

   cp /usr/local/bin/fred.txt > ~/.gedit/backup/fred.txt
   and now write new data to /usr/local/bin/fred.txt

mv's don't work if the directory is read only but cat's do.
by writing to the original file the flags are preserved.

I would recommend informing the user where the backup of the
original file has been placed and why it couldn't have been
placed at the usual location.
Comment 15 Paolo Maggi 2003-01-14 18:02:56 UTC
From VIM documentation:

'backupcopy' 'bkc'	string	(Vi default for Unix: "yes", otherwise: "auto")
			global
			{not in Vi}
	When writing a file and a backup is made, this option tells how it's
	done:
	"yes"	make a copy of the file and overwrite the original one
	"no"	rename the file and write a new one
	"auto"	one of the previous, what works best

	Making a copy and overwriting the original file:
	- Takes extra time to copy the file.
	+ When the file has special attributes, is a (hard/symbolic) link or
	  has a resource fork, all this is preserved.
	- When the file is a link the backup will have the name of the link,
	  not of the real file.

	Renaming the file and writing a new one:
	+ It's fast.
	- Sometimes not all attributes of the file can be copied to the new
	  file.
	- When the file is a link the new file will not be a link.

	The "auto" value is the middle way: When Vim sees that renaming file
	is possible without side effects (the attributes can be passed on and
	and the file is not a link) that is used.  When problems are expected,
	a copy will be made.

	One situation where "no" and "auto" will cause problems: A program
	that opens a file, invokes Vim to edit that file, and then tests if
	the open file was changed (through the file descriptor) will check the
	backup file instead of the newly created file.  "crontab -e" is an
	example.

	When a copy is made, the original file is truncated and then filled
	with the new text.  This means that protection bits, owner and
	symbolic links of the original file are unmodified.  The backup file
	however, is a new file, owned by the user who edited the file.  The
	group of the backup is set to the group of the original file.  If this
	fails, the protection bits for the group are made the same as for
	others.

	When the file is renamed this is the other way around: The backup has
	the same attributes of the original file, and the newly written file
	is owned by the current user.  When the file was a (hard/symbolic)
	link, the new file will not!  That's why the "auto" value doesn't
	rename when the file is a link.  The owner and group of the newly
	written file will be set to the same ones as the original file, but
	the system may refuse to do this.  In that case the "auto" value will
	again not rename the file.

Comment 16 Paolo Maggi 2003-01-14 18:12:22 UTC
BTW, I think we should try to implement a simple solution (like the
one used bu nedit) in time for gnome 2.2 and then starting discussing
and implementing a more complex one (like the one used by VIM).
Comment 17 dsr 2003-01-16 11:53:40 UTC
Okay, I have created a revised version of gedit-document.c that
implements the nedit behavior. I haven't added an explicit warning
to the end user though, as I suspect that it is perhaps too late
for the translators. What do you think?

I now need to find out how to send the revised file, presumably
the gedit mailing list, no? I will check on #gedit
Comment 18 dsr 2003-01-16 11:57:16 UTC
Created attachment 13620 [details] [review]
revised to fix bug 92896 following behavior of nedit
Comment 19 dsr 2003-01-16 12:03:15 UTC
I have attached the patched version of gedit-document.c
The changes are to the function: gedit_document_save_as_real()

It would benefit from a user warning message at or around
line 1231, assuming we have time for this to be translated.

I would be happy to work on supporting the vim behavior as part
of the post 2.2 work.

Regards,
  Dave Raggett
Comment 20 Paolo Maggi 2003-01-16 14:59:09 UTC
dsr: Please, use "cvs diff -u -p" to send patches.
Comment 21 Paolo Maggi 2003-04-19 17:55:44 UTC
*** Bug 111100 has been marked as a duplicate of this bug. ***
Comment 22 Paolo Maggi 2003-04-19 17:58:23 UTC
See also bug #104432

dsr: are you still willing to work on this bug for gedit 2.4?
Comment 23 Eric Ritezel 2003-06-06 20:47:40 UTC
Created attachment 17256 [details] [review]
patch against CVS for nedit behavior
Comment 24 Travis Saling 2003-12-21 03:58:40 UTC
I know I was the reporter of this bug - about 15 months ago - but at
this point I have no interest in any reports regarding this bug.

There doesn't appear to be a way for me to remove my name via
bugzilla. Could someone please reassign the "reporter" to a different
address? 

Thank you.
Comment 25 Shreejith B L 2004-05-08 18:04:19 UTC
Created attachment 27485 [details] [review]
Works fine while saving changed file in a directory that doesnt have write permission, but belongs to the user

When we are trying to save a changed file in a directory that doesnt have write
permission, saving was not possible.  This is because each time a file is
changed, a new temporary file is created in the current directory.  As the
directory does not have write permission, an error indicating "cannot save
"filename" was thrown to the user. In order to overcome this problem, whenever
the directory doesnt have write permission, instead of creating a new file, the
old file is copied to the temporary directory /tmp and then copied back to the
file being edited.  This solves the problem
Comment 26 Paolo Maggi 2004-07-16 16:09:50 UTC
Thanks for the patch.
Note that I'm rewriting the "save" function in order to use gnome-vfs.
Comment 27 Marco Rodrigues 2004-07-20 22:12:44 UTC
*** Bug 148039 has been marked as a duplicate of this bug. ***
Comment 28 David A Knight 2004-11-13 04:11:46 UTC
Created attachment 33719 [details] [review]
gnome-vfs based saving using auto backup strategy

The error reporting needs working on.  I've been using the code in screem for
the past few days without problems, and its seems okay from quick tests in
gedit.
Comment 29 Paolo Borelli 2004-11-13 09:45:09 UTC
Hi David, thanks a lot for taking the time to port the screem code against
gedit, it's really appreciated. I know that Paolo Maggi has been working on the
saving code, so I'll leave to him commenting on the patch and integrating it
with his work.
Comment 30 Paolo Maggi 2004-11-13 09:49:20 UTC
David, thanks for the patch.
I will review it ASAP.
Comment 31 David A Knight 2004-11-16 01:27:45 UTC
Created attachment 33827 [details] [review]
fixed version of vfs save patch

This fixes a problem with the previous patch failing to save when backups are
disabled.
Comment 32 Paolo Maggi 2005-01-23 20:47:53 UTC
Comment on attachment 27485 [details] [review]
Works fine while saving changed file in a directory that doesnt have write permission, but belongs to the user

We are going to rewrite the   save function using gnome-vfs
Comment 33 Paolo Maggi 2005-01-23 20:54:27 UTC
Comment on attachment 33827 [details] [review]
fixed version of vfs save patch

Thanks for the patch, but we are completely rewriting the save_as_real function
in order to implement a vim -like behavior (see our prototyped patch on bug
#110191). We are trying to write the code in a gedit indepent way, so when
finished you should be able to adopt it for screem if you would like.
Comment 34 Nelson Benitez 2005-08-20 11:48:42 UTC
I've just hit this bug, commandline steps to reproduce:

nelson@gnelson ~ $ echo "testfile" > testfile.txt
nelson@gnelson ~ $ su
Password:
gnelson nelson # mkdir /usr/share/testdir
gnelson nelson # mv testfile.txt /usr/share/testdir/
gnelson nelson # exit
exit
nelson@gnelson ~ $ vi /usr/share/testdir/testfile.txt
(vi *can* save the file)
nelson@gnelson ~ $ gedit /usr/share/testdir/testfile.txt
(gedit *cannot* save the file)
Comment 35 Diego Escalante Urrelo (not reading bugmail) 2007-09-12 00:13:36 UTC
Nowadays it informs you of not being able to create a backup file, however it still allows you to save.
Comment 36 Pavel Šefránek 2008-04-27 08:35:52 UTC
Can confirm what diego in comment 35 says. So mabybe the original issue (gedit won't save file in some instances) has been resolved?
Comment 37 jessevdk@gmail.com 2009-11-22 11:44:53 UTC
Indeed, we have a fallback strategy now, which truncates the file. This is not as safe as writing the file to a temporary location, and then moving it over to the actual location, hence the warning you will see. I'm closing this bug as I consider the reported issue fixed.