From 105a4e417deff3e9bbd3f819c03013511f47d2b6 Mon Sep 17 00:00:00 2001 From: Andreas Huggel Date: Tue, 30 Dec 2008 15:54:46 +0000 Subject: [PATCH] Changed FileIo::transfer to only write a warning if changing file permissions fails and fixed the use of strerror_r. Fixes digiKam bug 178103. --- src/basicio.cpp | 29 +++++++++++++++++++++++------ src/error.cpp | 2 +- src/futils.cpp | 5 +++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/basicio.cpp b/src/basicio.cpp index 20797fca..10d7ae2d 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -44,6 +44,7 @@ EXIV2_RCSID("@(#) $Id$") // + standard includes #include #include +#include #include #include #include // for remove, rename @@ -230,9 +231,13 @@ namespace Exiv2 { throw Error(10, path_, "w+b", strError()); } close(); - struct stat buf; - if (::stat(path_.c_str(), &buf) == -1) { - throw Error(2, path_, strError(), "stat"); + bool statOk = true; + struct stat buf1; + if (::stat(path_.c_str(), &buf1) == -1) { + statOk = false; +#ifndef SUPPRESS_WARNINGS + std::cerr << "Warning: " << Error(2, path_, strError(), "stat") << "\n"; +#endif } // MSVCRT rename that does not overwrite existing files if (fileExists(path_) && std::remove(path_.c_str()) != 0) { @@ -242,9 +247,21 @@ namespace Exiv2 { throw Error(17, fileIo->path_, path_, strError()); } std::remove(fileIo->path_.c_str()); - // Set original file permissions - if (::chmod(path_.c_str(), buf.st_mode) == -1) { - throw Error(2, fileIo->path_, strError(), "chmod"); + // Check permissions of new file + struct stat buf2; + if (statOk && ::stat(path_.c_str(), &buf2) == -1) { + statOk = false; +#ifndef SUPPRESS_WARNINGS + std::cerr << "Warning: " << Error(2, path_, strError(), "stat") << "\n"; +#endif + } + if (statOk && buf1.st_mode != buf2.st_mode) { + // Set original file permissions + if (::chmod(path_.c_str(), buf1.st_mode) == -1) { +#ifndef SUPPRESS_WARNINGS + std::cerr << "Warning: " << Error(2, path_, strError(), "chmod") << "\n"; +#endif + } } } else { diff --git a/src/error.cpp b/src/error.cpp index f0a3ae0e..4d5b1f12 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -49,7 +49,7 @@ namespace { { -1, N_("Error %0: arg1=%1, arg2=%2, arg3=%3.") }, { 0, N_("Success") }, { 1, "%1" }, // %1=error message - { 2, "%1: %2 (%3)" }, // %1=path, %2=strerror, %3=function that failed + { 2, "%1: Call to `%3' failed: %2" }, // %1=path, %2=strerror, %3=function that failed { 3, N_("This does not look like a %1 image") }, // %1=Image type { 4, N_("Invalid dataset name `%1'") }, // %1=dataset name { 5, N_("Invalid record name `%1'") }, // %1=record name diff --git a/src/futils.cpp b/src/futils.cpp index 10c495a4..acc76bc2 100644 --- a/src/futils.cpp +++ b/src/futils.cpp @@ -81,7 +81,8 @@ namespace Exiv2 { std::ostringstream os; #ifdef EXV_HAVE_STRERROR_R const size_t n = 1024; -# ifdef EXV_STRERROR_R_CHAR_P +// _GNU_SOURCE: See Debian bug #485135 +# if defined EXV_STRERROR_R_CHAR_P || defined _GNU_SOURCE char *buf = 0; char buf2[n]; std::memset(buf2, 0x0, n); @@ -95,7 +96,7 @@ namespace Exiv2 { #else os << std::strerror(error); #endif - os << " (" << error << ")"; + os << " (errno = " << error << ")"; return os.str(); } // strError