#1272 Submitting modified version of Ben's patch.
This commit is contained in:
parent
dd4faaf831
commit
9f06ff2971
@ -551,7 +551,11 @@ namespace Exiv2 {
|
||||
/*!
|
||||
@brief Returns the path to a temporary data storage location.
|
||||
*/
|
||||
static std::string temporaryPath();
|
||||
#ifdef EXV_UNICODE_PATH
|
||||
static std::wstring temporaryPath();
|
||||
#else
|
||||
static std::string temporaryPath();
|
||||
#endif
|
||||
|
||||
private:
|
||||
// NOT IMPLEMENTED
|
||||
|
||||
@ -165,6 +165,9 @@ typedef int pid_t;
|
||||
# ifdef EXV_HAVE_REGEX
|
||||
# undef EXV_HAVE_REGEX
|
||||
# endif
|
||||
#ifdef EXV_UNICODE_PATH
|
||||
#error EXV_UNICODE_PATH is not supported for MinGW builds
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef __CYGWIN__
|
||||
|
||||
@ -51,7 +51,7 @@
|
||||
#endif /* !EXV_COMMERCIAL_VERSION */
|
||||
|
||||
/* Define Windows unicode path support. */
|
||||
/* #undef EXV_UNICODE_PATH */
|
||||
/* #define EXV_UNICODE_PATH */
|
||||
|
||||
|
||||
/* Define to `const' or to empty, depending on the second argument of `iconv'. */
|
||||
|
||||
@ -363,7 +363,6 @@ namespace Exiv2 {
|
||||
EXIV2API std::wstring s2ws(const std::string& s);
|
||||
//! Convert a unicode std::wstring s to an std::string.
|
||||
EXIV2API std::string ws2s(const std::wstring& s);
|
||||
|
||||
#endif
|
||||
/*!
|
||||
@brief Return a \em long set to the value represented by \em s.
|
||||
|
||||
@ -2071,7 +2071,11 @@ namespace {
|
||||
Action::Modify::applyCommands(sourceImage.get());
|
||||
|
||||
// Open or create the target file
|
||||
std::string target = bStdout ? Exiv2::FileIo::temporaryPath() : tgt;
|
||||
#ifdef EXV_UNICODE_PATH
|
||||
std::string target = bStdout ? Exiv2::ws2s(Exiv2::FileIo::temporaryPath()) : tgt;
|
||||
#else
|
||||
std::string target = bStdout ? Exiv2::FileIo::temporaryPath() : tgt;
|
||||
#endif
|
||||
|
||||
Exiv2::Image::AutoPtr targetImage;
|
||||
if (Exiv2::fileExists(target)) {
|
||||
|
||||
@ -577,46 +577,56 @@ namespace Exiv2 {
|
||||
#else
|
||||
nlink_t nlink = buf.st_nlink;
|
||||
#endif
|
||||
|
||||
#ifdef EXV_UNICODE_PATH
|
||||
std::wstring tmpname;
|
||||
#else
|
||||
std::string tmpname;
|
||||
#endif
|
||||
// If file is > 1MB and doesn't have hard links then use a file, otherwise
|
||||
// use a memory buffer. I.e., files with hard links always use a memory
|
||||
// buffer, which is a workaround to ensure that the links don't get broken.
|
||||
if (ret != 0 || (buf.st_size > 1048576 && nlink == 1)) {
|
||||
if (ret != 0 || (buf.st_size > 1048576 && nlink == 1))
|
||||
{
|
||||
pid_t pid = ::getpid();
|
||||
std::auto_ptr<FileIo> fileIo;
|
||||
#ifdef EXV_UNICODE_PATH
|
||||
if (p_->wpMode_ == Impl::wpUnicode) {
|
||||
std::wstring tmpname = wpath() + s2ws(toString(pid));
|
||||
fileIo = std::auto_ptr<FileIo>(new FileIo(tmpname));
|
||||
}
|
||||
else
|
||||
tmpname = temporaryPath() + s2ws(toString(pid));
|
||||
fileIo = std::auto_ptr<FileIo>(new FileIo(tmpname));
|
||||
#else
|
||||
tmpname = temporaryPath() + toString(pid);
|
||||
fileIo = std::auto_ptr<FileIo>(new FileIo(tmpname));
|
||||
#endif
|
||||
{
|
||||
std::string tmpname = path() + toString(pid);
|
||||
fileIo = std::auto_ptr<FileIo>(new FileIo(tmpname));
|
||||
}
|
||||
if (fileIo->open("w+b") != 0) {
|
||||
#ifdef EXV_UNICODE_PATH
|
||||
if (p_->wpMode_ == Impl::wpUnicode) {
|
||||
throw WError(10, wpath(), "w+b", strError().c_str());
|
||||
#if defined(_MSC_VER)
|
||||
if( !DeleteFileW( tmpname.c_str()) )
|
||||
{
|
||||
perror("Error deleting file");
|
||||
throw WError(10, ws2s(tmpname).c_str(), "w+b", strError().c_str());
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#else
|
||||
#if defined(_MSC_VER) || defined(__MINGW__)
|
||||
if( !DeleteFile( tmpname.c_str() ) )
|
||||
#else
|
||||
if( remove( tmpname.c_str() ) != 0 )
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
throw Error(10, path(), "w+b", strError());
|
||||
perror("Error deleting file");
|
||||
}
|
||||
throw Error(10, tmpname.c_str(), "w+b", strError());
|
||||
}
|
||||
fileIo->p_->copyXattrFrom(*this);
|
||||
basicIo = fileIo;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
basicIo.reset(new MemIo);
|
||||
}
|
||||
|
||||
return basicIo;
|
||||
}
|
||||
|
||||
std::string FileIo::temporaryPath()
|
||||
static std::string tempPath()
|
||||
{
|
||||
static int count = 0 ;
|
||||
char sCount[12];
|
||||
@ -638,6 +648,18 @@ namespace Exiv2 {
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef EXV_UNICODE_PATH
|
||||
std::wstring FileIo::temporaryPath()
|
||||
{
|
||||
return s2ws(tempPath());
|
||||
}
|
||||
#else
|
||||
std::string FileIo::temporaryPath()
|
||||
{
|
||||
return tempPath();
|
||||
}
|
||||
#endif
|
||||
|
||||
long FileIo::write(const byte* data, long wcount)
|
||||
{
|
||||
assert(p_->fp_ != 0);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user