From: albinsunnanbo Date: Thu, 13 Mar 2008 14:24:00 +0000 (+0000) Subject: BUG 168896, fix BUG_168896_refactor_tempfile.patch problems with Vista tempfiles... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5f2c606c00ae95f21324b0e16ff024529843192b;p=inkscape.git BUG 168896, fix BUG_168896_refactor_tempfile.patch problems with Vista tempfiles breaks some extensions (including Save as XAML) --- diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index 381b02b08..da60c8821 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -472,7 +472,7 @@ ScriptDocCache::ScriptDocCache (Inkscape::UI::View::View * view) : _tempfd(0) { try { - _tempfd = Glib::file_open_tmp(_filename, "ink_ext_XXXXXX.svg"); + _tempfd = Inkscape::IO::file_open_tmp(_filename, "ink_ext_XXXXXX.svg"); } catch (...) { /// \todo Popup dialog here return; @@ -593,7 +593,7 @@ Script::open(Inkscape::Extension::Input *module, std::string tempfilename_out; int tempfd_out = 0; try { - tempfd_out = Glib::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX"); + tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX"); } catch (...) { /// \todo Popup dialog here return NULL; @@ -667,7 +667,7 @@ Script::save(Inkscape::Extension::Output *module, std::string tempfilename_in; int tempfd_in = 0; try { - tempfd_in = Glib::file_open_tmp(tempfilename_in, "ink_ext_XXXXXX"); + tempfd_in = Inkscape::IO::file_open_tmp(tempfilename_in, "ink_ext_XXXXXX"); } catch (...) { /// \todo Popup dialog here return; @@ -764,7 +764,7 @@ Script::effect(Inkscape::Extension::Effect *module, std::string tempfilename_out; int tempfd_out = 0; try { - tempfd_out = Glib::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX.svg"); + tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX.svg"); } catch (...) { /// \todo Popup dialog here return; diff --git a/src/extension/implementation/xslt.cpp b/src/extension/implementation/xslt.cpp index fb7d6a6f9..8b0ba97a8 100644 --- a/src/extension/implementation/xslt.cpp +++ b/src/extension/implementation/xslt.cpp @@ -195,7 +195,7 @@ XSLT::save(Inkscape::Extension::Output */*module*/, SPDocument *doc, gchar const std::string tempfilename_out; int tempfd_out = 0; try { - tempfd_out = Glib::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX"); + tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX"); } catch (...) { /// \todo Popup dialog here return; diff --git a/src/io/sys.cpp b/src/io/sys.cpp index a1e693a24..b184988fd 100644 --- a/src/io/sys.cpp +++ b/src/io/sys.cpp @@ -166,6 +166,51 @@ 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 + * + * 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) +{ +#ifndef WIN32 + return Glib::file_open_tmp(name_used, prefix); +#else + /* Special case for WIN32 due to a bug in glibmm + * (only needed for Windows Vista, but since there is only one windows build all builds get the workaround) + * The workaround can be removed if the bug is fixed in glibmm + * + * The code is mostly identical to the implementation in glibmm + * http://svn.gnome.org/svn/glibmm/branches/glibmm-2-12/glib/src/fileutils.ccg + * */ + + std::string basename_template (prefix); + basename_template += "XXXXXX"; // this sillyness shouldn't be in the interface + + GError* error = 0; + gchar *buf_name_used; + + gint fileno = g_file_open_tmp(basename_template.c_str(), &buf_name_used, &error); + + if(error) + Glib::Error::throw_exception(error); + + name_used = g_strdup(buf_name_used); + g_free(buf_name_used); + return fileno; +#endif +} + bool Inkscape::IO::file_test( char const *utf8name, GFileTest test ) { bool exists = false; diff --git a/src/io/sys.h b/src/io/sys.h index fd39c630b..b31602d91 100644 --- a/src/io/sys.h +++ b/src/io/sys.h @@ -18,6 +18,7 @@ #include #include #include +#include /*##################### ## U T I L I T Y @@ -32,6 +33,8 @@ FILE *fopen_utf8name( char const *utf8name, char const *mode ); int mkdir_utf8name( char const *utf8name ); +int file_open_tmp( std::string& name_used, const std::string& prefix ); + bool file_test( char const *utf8name, GFileTest test ); GDir *dir_open(gchar const *utf8name, guint flags, GError **error); diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index e9ef63443..19b739061 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -24,6 +24,7 @@ #include "interface.h" #include "gc-core.h" #include +#include "io/sys.h" namespace Inkscape { @@ -285,7 +286,7 @@ void FileListViewText::on_cursor_changed() // create file path const std::string tmptemplate = "ocal-"; std::string tmpname; - int fd = Glib::file_open_tmp(tmpname, tmptemplate); + int fd = Inkscape::IO::file_open_tmp(tmpname, tmptemplate); if (fd<0) { g_warning("Error creating temp file"); return; diff --git a/src/ui/dialog/print.cpp b/src/ui/dialog/print.cpp index 3deb4204a..52ff07ee6 100644 --- a/src/ui/dialog/print.cpp +++ b/src/ui/dialog/print.cpp @@ -26,6 +26,7 @@ #include "unit-constants.h" #include "helper/png-write.h" #include "svg/svg-color.h" +#include "io/sys.h" static void @@ -46,7 +47,7 @@ draw_page (GtkPrintOperation */*operation*/, std::string tmp_base = "inkscape-print-png-XXXXXX"; int tmp_fd; - if ( (tmp_fd = Glib::file_open_tmp (tmp_png, tmp_base)) >= 0) { + if ( (tmp_fd = Inkscape::IO::file_open_tmp (tmp_png, tmp_base)) >= 0) { close(tmp_fd); guint32 bgcolor = 0x00000000;