From having a look at where this function is used, by Geany it's used only to store configuration files in the .config directory and some auxiliary functions like writing the export file by the exporter plugin. In the geany-plugins project this function is used only for saving configuration files.
Before this patch, the fwrite() method was used by default for saving configuration files (because g_file_replace_contents() normally used by Geany wasn't used in this function) which wasn't very safe and could lead to configuration file loss under some extreme conditions.
The documentation of this function was changed to reflect the situation better than now - the previous comment made the impression that file permissions were always preserved with this method but it wasn't the case and depended on the exact configuration.
Replaces #3947. You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany/pull/3950
-- Commit Summary --
* Modify utils_write_file() to always use g_file_replace_contents()
-- File Changes --
M src/utils.c (69)
-- Patch Links --
https://github.com/geany/geany/pull/3950.patch https://github.com/geany/geany/pull/3950.diff
LGBI
@elextr approved this pull request.
LGBI
For completeness, I went through other uses of `fwrite()` and `g_file_set_contents()`: - `fwrite()` is used in tag manager to write some auxiliary file when generating tag files - pretty much OK since this is just a temporary file (TM doesn't have access to the rest of Geany ATM so it cannot use `utils_write_file()`) - `fwrite()` is used to write to the socket which has to be done this way - `g_file_set_contents()` is used to write the temporary `geany_run_script_XXXXXX.sh` script - could probably be converted to use `utils_write_file()` but right now it needs the `GError` for error messages which `utils_write_file()` does not return. Probably not worth the work since it's just a temporary file (and the possible wrong permissions will only be within the `/tmp` directory and won't prevent creation of other `geany_run_script_XXXXXX.sh` since the suffix is random)
So no extra work needed IMO.
Unless there are any objections, I'll merge this in about a week.
Merged #3950 into master.
github-comments@lists.geany.org