From fde4b17b3614d7b51e220e02053b97f66ddd0652 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Tue, 26 Sep 2017 20:55:36 +0200 Subject: Create parent directories when opening a file for writing - this affects callers of Inkscape::IO::fopen_utf8name - fixes at least two issues: - creating custom shortcuts failed when "/inkscape/keys" was missing in the configuration directory, see https://bugs.launchpad.net/inkscape/+bug/1719629 - autosaving probably failed if a non-existent directory was specified --- src/io/sys.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/io/sys.cpp') diff --git a/src/io/sys.cpp b/src/io/sys.cpp index b06b550dd..833dee437 100644 --- a/src/io/sys.cpp +++ b/src/io/sys.cpp @@ -71,10 +71,20 @@ FILE *Inkscape::IO::fopen_utf8name( char const *utf8name, char const *mode ) gchar *filename = g_filename_from_utf8( utf8name, -1, NULL, NULL, NULL ); if ( filename ) { + // ensure we open the file in binary mode (not needed in POSIX but doesn't hurt either) Glib::ustring how( mode ); if ( how.find("b") == Glib::ustring::npos ) { - how.append("b"); // not needed in POSIX but doesn't hurt either + how.append("b"); + } + // when opening a file for writing: create parent directories if they don't exist already + if ( how.find("w") != Glib::ustring::npos ) + { + gchar *dirname = g_path_get_dirname(utf8name); + if (g_mkdir_with_parents(dirname, 0777)) { + g_warning("Could not create directory '%s'", dirname); + } + g_free(dirname); } fp = g_fopen(filename, how.c_str()); g_free(filename); -- cgit v1.2.3 From c419daf4e13efc020401b3bcbbe8b6116bb3cdd7 Mon Sep 17 00:00:00 2001 From: Stefano Facchini Date: Wed, 18 Oct 2017 22:08:15 +0200 Subject: Drop obsolete wrapper around Glib::file_open_tmp --- src/io/sys.cpp | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'src/io/sys.cpp') diff --git a/src/io/sys.cpp b/src/io/sys.cpp index 833dee437..2ff17cdc9 100644 --- a/src/io/sys.cpp +++ b/src/io/sys.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include @@ -107,26 +106,6 @@ int Inkscape::IO::mkdir_utf8name( char const *utf8name ) return retval; } -/* - * Wrapper around Glib::file_open_tmp(). - * Returns a handle to the temp file. - * name_used contains the actual name used (a raw filename, not necessarily utf8). - * - * Returns: - * A file handle (as from open()) to the file opened for reading and writing. - * The file is opened in binary mode on platforms where there is a difference. - * The file handle should be closed with close(). - * - * Note: - * On Windows Vista Glib::file_open_tmp fails with the current version of glibmm - * A special case is implemented for WIN32. This can be removed if the issue is fixed - * in future versions of glibmm - * */ -int Inkscape::IO::file_open_tmp(std::string& name_used, const std::string& prefix) -{ - return Glib::file_open_tmp(name_used, prefix); -} - bool Inkscape::IO::file_test( char const *utf8name, GFileTest test ) { bool exists = false; -- cgit v1.2.3