diff options
| author | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
| commit | 5a4fb2325f60d292b47330f540b26a3279341c90 (patch) | |
| tree | d2aa7967be25450b83e625025366c618101ae49f /src/io/sys.cpp | |
| parent | The Polar Arrange Tab of the Arrange Dialog now hides the parametric (diff) | |
| parent | Remove Snap menu item and improve grid menu item text (diff) | |
| download | inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.tar.gz inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.zip | |
Commit a merge to trunk, with probabal errors
(bzr r11073.1.36)
Diffstat (limited to 'src/io/sys.cpp')
| -rw-r--r-- | src/io/sys.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/io/sys.cpp b/src/io/sys.cpp index 5f19ee5db..94175176a 100644 --- a/src/io/sys.cpp +++ b/src/io/sys.cpp @@ -15,6 +15,7 @@ # include "config.h" #endif +#include <fstream> #include <glib.h> #include <glib/gstdio.h> #include <glibmm/fileutils.h> @@ -226,8 +227,10 @@ bool Inkscape::IO::file_is_writable( char const *utf8name) } if ( filename ) { struct stat st; - if(g_lstat (filename, &st) == 0) { - success = ((st.st_mode & S_IWRITE) != 0); + if (g_file_test (filename, G_FILE_TEST_EXISTS)){ + if (g_lstat (filename, &st) == 0) { + success = ((st.st_mode & S_IWRITE) != 0); + } } g_free(filename); filename = NULL; @@ -239,6 +242,40 @@ bool Inkscape::IO::file_is_writable( char const *utf8name) return success; } +/**Checks if directory of file exists, useful + * because inkscape doesn't create directories.*/ +bool Inkscape::IO::file_directory_exists( char const *utf8name ){ + bool exists = true; + + if ( utf8name) { + gchar *filename = NULL; + if (utf8name && !g_utf8_validate(utf8name, -1, NULL)) { + /* FIXME: Trying to guess whether or not a filename is already in utf8 is unreliable. + If any callers pass non-utf8 data (e.g. using g_get_home_dir), then change caller to + use simple g_file_test. Then add g_return_val_if_fail(g_utf_validate(...), false) + to beginning of this function. */ + filename = g_strdup(utf8name); + // Looks like g_get_home_dir isn't safe. + //g_warning("invalid UTF-8 detected internally. HUNT IT DOWN AND KILL IT!!!"); + } else { + filename = g_filename_from_utf8 ( utf8name, -1, NULL, NULL, NULL ); + } + if ( filename ) { + gchar *dirname = g_path_get_dirname(filename); + exists = Inkscape::IO::file_test( dirname, G_FILE_TEST_EXISTS); + g_free(filename); + g_free(dirname); + filename = NULL; + dirname = NULL; + } else { + g_warning( "Unable to convert filename in IO:file_test" ); + } + } + + return exists; + +} + /** Wrapper around g_dir_open, but taking a utf8name as first argument. */ GDir * Inkscape::IO::dir_open(gchar const *const utf8name, guint const flags, GError **const error) |
