Changed FileIo::transfer to only write a warning if changing file permissions fails and fixed the use of strerror_r. Fixes digiKam bug 178103.

v0.27.3
Andreas Huggel 17 years ago
parent fa1777dee8
commit 105a4e417d

@ -44,6 +44,7 @@ EXIV2_RCSID("@(#) $Id$")
// + standard includes
#include <string>
#include <memory>
#include <iostream>
#include <cstring>
#include <cassert>
#include <cstdio> // 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 {

@ -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

@ -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

Loading…
Cancel
Save