diff options
| author | Eduard Braun <eduard.braun2@gmx.de> | 2017-09-27 17:54:14 +0000 |
|---|---|---|
| committer | Eduard Braun <eduard.braun2@gmx.de> | 2017-09-27 17:54:14 +0000 |
| commit | 980bacf4fd6e28e7b2087bbb46504b186dd53f4c (patch) | |
| tree | 6be423b0622301e34478961c39a99d58c8106b94 /src/io/sys.cpp | |
| parent | Merge branch 'jali/inkscape-ustring_refactor' (diff) | |
| parent | Create parent directories when opening a file for writing (diff) | |
| download | inkscape-980bacf4fd6e28e7b2087bbb46504b186dd53f4c.tar.gz inkscape-980bacf4fd6e28e7b2087bbb46504b186dd53f4c.zip | |
Merge branch 'fix_saving' into 'master'
Create parent directories when opening a file for writing
See merge request inkscape/inkscape!83
Diffstat (limited to 'src/io/sys.cpp')
| -rw-r--r-- | src/io/sys.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
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); |
