577 |
577 |
#else
|
578 |
578 |
nlink_t nlink = buf.st_nlink;
|
579 |
579 |
#endif
|
|
580 |
#ifdef EXV_UNICODE_PATH
|
|
581 |
std::wstring wtmpname;
|
|
582 |
#endif
|
|
583 |
std::string tmpname;
|
580 |
584 |
|
581 |
585 |
// If file is > 1MB and doesn't have hard links then use a file, otherwise
|
582 |
586 |
// use a memory buffer. I.e., files with hard links always use a memory
|
583 |
587 |
// buffer, which is a workaround to ensure that the links don't get broken.
|
584 |
|
if (ret != 0 || (buf.st_size > 1048576 && nlink == 1)) {
|
|
588 |
if (ret != 0 || (buf.st_size > 1048576 && nlink == 1))
|
|
589 |
{
|
585 |
590 |
pid_t pid = ::getpid();
|
586 |
591 |
std::auto_ptr<FileIo> fileIo;
|
587 |
592 |
#ifdef EXV_UNICODE_PATH
|
588 |
593 |
if (p_->wpMode_ == Impl::wpUnicode) {
|
589 |
|
std::wstring tmpname = wpath() + s2ws(toString(pid));
|
590 |
|
fileIo = std::auto_ptr<FileIo>(new FileIo(tmpname));
|
|
594 |
wtmpname = temporaryWPath() + s2ws(toString(pid));
|
|
595 |
fileIo = std::auto_ptr<FileIo>(new FileIo(wtmpname));
|
591 |
596 |
}
|
592 |
597 |
else
|
593 |
598 |
#endif
|
594 |
599 |
{
|
595 |
|
std::string tmpname = path() + toString(pid);
|
|
600 |
tmpname = temporaryPath() + toString(pid);
|
596 |
601 |
fileIo = std::auto_ptr<FileIo>(new FileIo(tmpname));
|
597 |
602 |
}
|
598 |
603 |
if (fileIo->open("w+b") != 0) {
|
599 |
604 |
#ifdef EXV_UNICODE_PATH
|
600 |
605 |
if (p_->wpMode_ == Impl::wpUnicode) {
|
601 |
|
throw WError(10, wpath(), "w+b", strError().c_str());
|
|
606 |
#if defined(_MSC_VER) || defined(__MINGW__)
|
|
607 |
if( !DeleteFileW( wtmpname.c_str() ) )
|
|
608 |
#else
|
|
609 |
if( remove( wtmpname.c_str() ) != 0 )
|
|
610 |
#endif
|
|
611 |
{
|
|
612 |
perror("Error deleting file");
|
|
613 |
}
|
|
614 |
throw WError(10, temporaryWPath(), "w+b", strError().c_str());
|
602 |
615 |
}
|
603 |
616 |
else
|
604 |
617 |
#endif
|
605 |
618 |
{
|
606 |
|
throw Error(10, path(), "w+b", strError());
|
|
619 |
#if defined(_MSC_VER) || defined(__MINGW__)
|
|
620 |
if( !DeleteFile( tmpname.c_str() ) )
|
|
621 |
#else
|
|
622 |
if( remove( tmpname.c_str() ) != 0 )
|
|
623 |
#endif
|
|
624 |
{
|
|
625 |
perror("Error deleting file");
|
|
626 |
}
|
|
627 |
throw Error(10, temporaryPath(), "w+b", strError());
|
607 |
628 |
}
|
608 |
629 |
}
|
609 |
630 |
fileIo->p_->copyXattrFrom(*this);
|
... | ... | |
638 |
659 |
return result;
|
639 |
660 |
}
|
640 |
661 |
|
|
662 |
#ifdef EXV_UNICODE_PATH
|
|
663 |
std::wstring FileIo::temporaryWPath()
|
|
664 |
{
|
|
665 |
std::wstring result = s2ws(temporaryPath());
|
|
666 |
return result;
|
|
667 |
}
|
|
668 |
#endif
|
|
669 |
|
641 |
670 |
long FileIo::write(const byte* data, long wcount)
|
642 |
671 |
{
|
643 |
672 |
assert(p_->fp_ != 0);
|