Project

General

Profile

Patch #1272 » temp_file-1.diff

This patch supersedes the previous one. Adds a widestring version of temporaryPath. - Ben Touchette, 20 Jan 2017 15:45

View differences:

exiv2-0.26.delete/include/exiv2/basicio.hpp 2017-01-20 08:55:37.000000000 -0500
552 552
          @brief Returns the path to a temporary data storage location.
553 553
         */
554 554
        static std::string temporaryPath();
555
#ifdef EXV_UNICODE_PATH
556
        /*!
557
          @brief Returns the unicode path to a temporary data storage location.
558
         */
559
        static std::wstring temporaryWPath();
560
#endif
555 561

  
556 562
    protected:
557 563
        // Pimpl idiom
exiv2-0.26.delete/include/exiv2/exv_conf.h 2017-01-20 08:42:26.621121801 -0500
28 28
#define EXV_HAVE_LIBINTL_H 1
29 29

  
30 30
/* Define to 1 if you require video support. */
31
#define EXV_ENABLE_VIDEO 1
31
/* #undef EXV_ENABLE_VIDEO */
32 32

  
33 33
/* Define to 1 if you require webready support. */
34 34
/* #undef EXV_ENABLE_WEBREADY */
......
40 40

  
41 41
/* Define to 1 if translation of program messages to the user's
42 42
   native language is requested. */
43
/* #undef EXV_ENABLE_NLS */
43
#define EXV_ENABLE_NLS 1
44 44

  
45 45
/* Define to 1 if you have the `iconv' function. */
46 46
#define EXV_HAVE_ICONV 1
exiv2-0.26.delete/src/basicio.cpp 2017-01-20 10:24:02.000000000 -0500
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);
(2-2/2)