Ticket #8094: file_preallocation_for_windows.patch
File file_preallocation_for_windows.patch, 2.6 KB (added by , 10 years ago) |
---|
-
src/engine/ftpcontrolsocket.cpp
2633 2633 2634 2634 if (pData->resume) 2635 2635 { 2636 if (!pFile->Open(pData->localFile, wxFile::write_append)) 2636 // Open the file in read_write mode since we don't want to truncate the file 2637 // nor to always write at the end of the file due to possible preallocation 2638 if (!pFile->Open(pData->localFile, wxFile::read_write)) 2637 2639 { 2638 2640 delete pFile; 2639 2641 LogMessage(MessageType::Error, _("Failed to open \"%s\" for appending/writing"), pData->localFile); … … 2692 2694 pData->resumeOffset = 0; 2693 2695 2694 2696 InitTransferStatus(pData->remoteFileSize, startOffset, false); 2697 2698 #ifdef __WXMSW__ 2699 // Try to preallocate the file on Windows in order to reduce fragmentation 2700 wxFileOffset sizeToPreallocate = pData->remoteFileSize - startOffset; 2701 if (sizeToPreallocate > 0) 2702 { 2703 LogMessage(MessageType::Debug_Info, _T("Preallocating %") wxFileOffsetFmtSpec _T("d bytes for the file \"%s\""), sizeToPreallocate, pData->localFile); 2704 wxFileOffset oldPos = pFile->Tell(); 2705 if (pFile->SeekEnd(sizeToPreallocate) == pData->remoteFileSize) 2706 { 2707 if (!SetEndOfFile((HANDLE)_get_osfhandle(pFile->fd()))) 2708 LogMessage(MessageType::Debug_Warning, _T("Impossible to preallocate the file")); 2709 } 2710 pFile->Seek(oldPos); 2711 } 2712 #endif 2695 2713 } 2696 2714 else 2697 2715 { -
src/engine/iothread.cpp
41 41 42 42 CIOThread::~CIOThread() 43 43 { 44 delete m_pFile; 44 if (m_pFile) 45 { 46 #ifdef __WXMSW__ 47 // The file might have been preallocated and the transfer stopped before being completed 48 // so always truncate the file to the actually written size before closing it. 49 if (!m_read) 50 SetEndOfFile((HANDLE)_get_osfhandle(m_pFile->fd())); 51 #endif 52 delete m_pFile; 53 } 45 54 46 55 for (unsigned int i = 0; i < BUFFERCOUNT; i++) 47 56 delete [] m_buffers[i]; … … 52 61 bool CIOThread::Create(wxFile* pFile, bool read, bool binary) 53 62 { 54 63 wxASSERT(pFile); 55 delete m_pFile; 64 65 if (m_pFile) 66 { 67 #ifdef __WXMSW__ 68 // The file might have been preallocated and the transfer stopped before being completed 69 // so always truncate the file to the actually written size before closing it. 70 if (!m_read) 71 SetEndOfFile((HANDLE)_get_osfhandle(m_pFile->fd())); 72 #endif 73 delete m_pFile; 74 } 75 56 76 m_pFile = pFile; 57 77 m_read = read; 58 78 m_binary = binary;