2

I use Geany to edit files in a web app that resides in /var/www. The owner and group of /var/www and all sub directories and files are www-data:www-data. My user account is a member of that group and I edit the files as my user. Sometimes it seems Geany changes the owner and group of the edited file to my user and my group.

How can I make sure the user:group is never changed when I edit a file with Geany?


I found this clue in the Geany help:

use_atomic_file_saving

Defines the mode how Geany saves files to disk. If disabled, Geany directly writes the content of the document to disk. This might cause loss of data when there is no more free space on disk to save the file. When set to true, Geany first saves the contents into a temporary file and if this succeeded, the temporary file is moved to the real file to save. This gives better error checking in case of no more free disk space. But it also destroys hard links of the original file and its permissions (e.g. executable flags are reset). Use this with care as it can break things seriously. The better approach would be to ensure your disk won't run out of free space.

As of now it's disabled, meaning that the file is written directly, which I thought would prevent my problem from happening.

This questions contains some relevant info: How do I edit a file and preserve its access control list / SELinux security context?

  • 1
    I thought it was a bad idea to have your www files owned by www-data, because if your server is compromised, you don't want the user gaining access to change the files. – P Daddy Mar 30 '16 at 15:56
1

Looking at Geany's wiki, it looks like you might also need to disable this option:

use_gio_unsafe_file_saving

This is on by the default, and is provided by the GIO library.

This option attempts to deal with as many of the issues associated with the other methods as it can:

  • It attempts to use the atomic rename saving method described above, but tries to address as many issues as it can:
    • it checks metadata of the temporary file and tries to copy the metadata from the existing file,
    • if the metadata is correct, it writes to the temporary and renames as above,
    • if the metadata is not correct, it uses a non-atomic but safe method of:
      • copying the existing file to a temporary file
      • truncating and overwriting the existing file, if this fails the temporary file should be copied back or available, but see disadvantages below.
  • It attempts to determine if rename is available on the underlying file system, and uses the non-atomic method if rename fails.

Advantages:

  • Deals with the most different conditions, so works the most correctly on the most file systems. That is why it is the default.

Disadvantages:

  • There is a long standing bug or design fault in the GIO library that deletes the temporary file from the non-atomic save if writing the data file fails. This means it is no more safe than the simple overwrite method since the previous data is not restored, or even left available for the user to restore.
  • The non-atomic save copies data over the network three times (read and write to make the temporary file, write the output file) which can be slow on remote networks.
  • Uses twice the disk space.
  • Is quite complex.
  • Uses library code so Geany can't modify its behaviour

What a strange method of file saving. It appears that it can result in the same "atomic" save as the use_atomic_file_saving option.

  • Looks very likely that this was the catch! :) I will try this for a couple of days of work, and come back with feedback when tested. – PetaspeedBeaver Mar 30 '16 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.