diff options
| author | Kris De Gussem <kris.degussem@gmail.com> | 2013-04-03 20:47:48 +0000 |
|---|---|---|
| committer | Kris <Kris.De.Gussem@hotmail.com> | 2013-04-03 20:47:48 +0000 |
| commit | 3c213cec8c2aab1a53d0d5cb9d87659b584ac876 (patch) | |
| tree | c999ceaf1d985a8a3eee1f6dce37ebc7930ca9e0 /src | |
| parent | Translations. Latvian translation update by Jānis Eisaks. (diff) | |
| download | inkscape-3c213cec8c2aab1a53d0d5cb9d87659b584ac876.tar.gz inkscape-3c213cec8c2aab1a53d0d5cb9d87659b584ac876.zip | |
Checking file presence before calling lstat (should fix Bug #785701 Inkscape freezes at opening)
(bzr r12263)
Diffstat (limited to 'src')
| -rw-r--r-- | src/inkscape.cpp | 16 | ||||
| -rw-r--r-- | src/io/sys.cpp | 6 | ||||
| -rw-r--r-- | src/sp-image.cpp | 19 | ||||
| -rw-r--r-- | src/ui/dialog/filedialogimpl-gtkmm.cpp | 2 | ||||
| -rw-r--r-- | src/ui/widget/imageicon.cpp | 2 |
5 files changed, 28 insertions, 17 deletions
diff --git a/src/inkscape.cpp b/src/inkscape.cpp index ac419784f..eca19c4b9 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -364,15 +364,17 @@ static gint inkscape_autosave(gpointer) while( (filename = g_dir_read_name(autosave_dir_ptr)) != NULL ){ if ( strncmp(filename, baseName, strlen(baseName)) == 0 ){ gchar* full_path = g_build_filename( autosave_dir.c_str(), filename, NULL ); - if ( g_stat(full_path, &sb) != -1 ) { - if ( difftime(sb.st_ctime, min_time) < 0 || min_time == 0 ){ - min_time = sb.st_ctime; - if ( oldest_autosave ) { - g_free(oldest_autosave); + if (g_file_test (full_path, G_FILE_TEST_EXISTS)){ + if ( g_stat(full_path, &sb) != -1 ) { + if ( difftime(sb.st_ctime, min_time) < 0 || min_time == 0 ){ + min_time = sb.st_ctime; + if ( oldest_autosave ) { + g_free(oldest_autosave); + } + oldest_autosave = g_strdup(full_path); } - oldest_autosave = g_strdup(full_path); + count ++; } - count ++; } g_free(full_path); } diff --git a/src/io/sys.cpp b/src/io/sys.cpp index 60e850c96..94175176a 100644 --- a/src/io/sys.cpp +++ b/src/io/sys.cpp @@ -227,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; diff --git a/src/sp-image.cpp b/src/sp-image.cpp index ce8879f70..dacea3417 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -417,8 +417,12 @@ GdkPixbuf* pixbuf_new_from_file( const char *filename, time_t &modTime, gchar*& pixPath = NULL; } + //test correctness of filename + if (!g_file_test (filename, G_FILE_TEST_EXISTS)){ + return NULL; + } struct stat stdir; - g_stat(filename, &stdir); + int val = g_stat(filename, &stdir); if (stdir.st_mode & S_IFDIR){ //filename is not correct: it is a directory name and hence further code can not return valid results return NULL; @@ -429,11 +433,11 @@ GdkPixbuf* pixbuf_new_from_file( const char *filename, time_t &modTime, gchar*& if ( fp ) { { - struct stat st; - memset(&st, 0, sizeof(st)); - int val = g_stat(filename, &st); + // struct stat st; + // memset(&st, 0, sizeof(st)); + // int val = g_stat(filename, &st); if ( !val ) { - modTime = st.st_mtime; + modTime = stdir.st_mtime;//st.st_mtime; pixPath = g_strdup(filename); } } @@ -1495,7 +1499,10 @@ void sp_image_refresh_if_outdated( SPImage* image ) struct stat st; memset(&st, 0, sizeof(st)); - int val = g_stat(image->pixPath, &st); + int val = 0; + if (g_file_test (image->pixPath, G_FILE_TEST_EXISTS)){ + val = g_stat(image->pixPath, &st); + } if ( !val ) { // stat call worked. Check time now if ( st.st_mtime != image->lastMod ) { diff --git a/src/ui/dialog/filedialogimpl-gtkmm.cpp b/src/ui/dialog/filedialogimpl-gtkmm.cpp index 5808d7d21..fdc9cecc3 100644 --- a/src/ui/dialog/filedialogimpl-gtkmm.cpp +++ b/src/ui/dialog/filedialogimpl-gtkmm.cpp @@ -529,7 +529,7 @@ bool SVGPreview::set(Glib::ustring &fileName, int dialogType) Glib::ustring fileNameUtf8 = Glib::filename_to_utf8(fileName); gchar *fName = const_cast<gchar *>(fileNameUtf8.c_str()); struct stat info; - if (g_stat(fName, &info)) + if (g_file_test (fName, G_FILE_TEST_EXISTS) && g_stat(fName, &info)) { g_warning("SVGPreview::set() : %s : %s", fName, strerror(errno)); diff --git a/src/ui/widget/imageicon.cpp b/src/ui/widget/imageicon.cpp index 1c36dc36e..cf41a16a4 100644 --- a/src/ui/widget/imageicon.cpp +++ b/src/ui/widget/imageicon.cpp @@ -382,7 +382,7 @@ bool ImageIcon::show(const Glib::ustring &fileName) if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) { struct stat info; - if (stat(fName, &info)) + if (g_file_test (fName, G_FILE_TEST_EXISTS) && stat(fName, &info)) { Glib::ustring err = "cannot get file info"; showBrokenImage(err); |
