ReplaceFile.patch

Axel Waggershauser, 27 Aug 2014 08:06

Download (2.6 KB)

View differences:

src/basicio.cpp 2014-08-27 15:01:22.364840200 +0200
710 710
            // MSVCRT rename that does not overwrite existing files
711 711
#ifdef EXV_UNICODE_PATH
712 712
            if (p_->wpMode_ == Impl::wpUnicode) {
713
#if defined WIN32 && !defined __CYGWIN__
714
                // Windows implementation that deals with the fact that ::rename fails
715
                // if the target filename still exists, which regularly happens when
716
                // that file has been opened with FILE_SHARE_DELETE by another process,
717
                // like a virus scanner or disk indexer
718
                // (see also http://stackoverflow.com/a/11023068)
719
                if (ReplaceFileW(wpf, fileIo->wpath().c_str(), NULL, REPLACEFILE_IGNORE_MERGE_ERRORS, NULL, NULL) == 0) {
720
                    throw WError(17, fileIo->wpath(), wpf, strError().c_str());
721
                }
722
#else
713 723
                if (fileExists(wpf) && ::_wremove(wpf) != 0) {
714 724
                    throw WError(2, wpf, strError().c_str(), "::_wremove");
715 725
                }
......
717 727
                    throw WError(17, fileIo->wpath(), wpf, strError().c_str());
718 728
                }
719 729
                ::_wremove(fileIo->wpath().c_str());
730
#endif
720 731
                // Check permissions of new file
721 732
                struct _stat buf2;
722 733
                if (statOk && ::_wstat(wpf, &buf2) == -1) {
......
737 748
            else
738 749
#endif // EXV_UNICODE_PATH
739 750
            {
751
#if defined WIN32 && !defined __CYGWIN__
752
                // Windows implementation that deals with the fact that ::rename fails
753
                // if the target filename still exists, which regularly happens when
754
                // that file has been opened with FILE_SHARE_DELETE by another process,
755
                // like a virus scanner or disk indexer
756
                // (see also http://stackoverflow.com/a/11023068)
757
                if (ReplaceFile(pf, fileIo->path().c_str(), NULL, REPLACEFILE_IGNORE_MERGE_ERRORS, NULL, NULL) == 0) {
758
                    throw Error(17, fileIo->path(), pf, strError());
759
                }
760
#else
740 761
                if (fileExists(pf) && ::remove(pf) != 0) {
741 762
                    throw Error(2, pf, strError(), "::remove");
742 763
                }
......
744 765
                    throw Error(17, fileIo->path(), pf, strError());
745 766
                }
746 767
                ::remove(fileIo->path().c_str());
768
#endif
747 769
                // Check permissions of new file
748 770
                struct stat buf2;
749 771
                if (statOk && ::stat(pf, &buf2) == -1) {
Redmine Appliance - Powered by TurnKey Linux