Ticket #8094: file_preallocation_v3.patch
File file_preallocation_v3.patch, 6.5 KB (added by , 10 years ago) |
---|
-
src/engine/file.cpp
79 79 return ret; 80 80 } 81 81 82 bool CFile::Truncate() 83 { 84 return !!SetEndOfFile(hFile_); 85 } 86 82 87 ssize_t CFile::Read(void *buf, size_t count) 83 88 { 84 89 ssize_t ret = -1; … … 171 176 return ret; 172 177 } 173 178 179 bool CFile::Truncate() 180 { 181 bool ret = false; 182 183 auto length = lseek(fd_, 0, SEEK_CUR); 184 if (length != static_cast<off_t>(-1)) { 185 do { 186 ret = !ftruncate(fd_, length); 187 } while (!ret && (errno == EAGAIN || errno == EINTR)); 188 } 189 190 return ret; 191 } 192 174 193 ssize_t CFile::Read(void *buf, size_t count) 175 194 { 176 195 ssize_t ret; -
src/engine/file.h
48 48 // On failure, the new position in the file is undefined. 49 49 wxFileOffset Seek(wxFileOffset offset, seekMode m); 50 50 51 // Truncate the file to the current position of the file pointer. 52 bool Truncate(); 53 51 54 // Returns number of bytes read or -1 on error 52 55 ssize_t Read(void *buf, size_t count); 53 56 -
src/engine/ftpcontrolsocket.cpp
2601 2601 pData->resumeOffset = 0; 2602 2602 2603 2603 InitTransferStatus(pData->remoteFileSize, startOffset, false); 2604 2605 if (m_pEngine->GetOptions().GetOptionVal(OPTION_PREALLOCATE_SPACE)) 2606 { 2607 // Try to preallocate the file in order to reduce fragmentation 2608 wxFileOffset sizeToPreallocate = pData->remoteFileSize - startOffset; 2609 if (sizeToPreallocate > 0) 2610 { 2611 LogMessage(MessageType::Debug_Info, _T("Preallocating %") wxFileOffsetFmtSpec _T("d bytes for the file \"%s\""), sizeToPreallocate, pData->localFile); 2612 wxFileOffset oldPos = pFile->Seek(0, CFile::current); 2613 if (pFile->Seek(sizeToPreallocate, CFile::end) == pData->remoteFileSize) 2614 { 2615 if (!pFile->Truncate()) 2616 LogMessage(MessageType::Debug_Warning, _T("Impossible to preallocate the file")); 2617 } 2618 pFile->Seek(oldPos, CFile::begin); 2619 } 2620 } 2604 2621 } 2605 2622 else { 2606 2623 if (!pFile->Open(pData->localFile, CFile::read)) { -
src/engine/iothread.cpp
29 29 30 30 CIOThread::~CIOThread() 31 31 { 32 delete m_pFile; 32 if (m_pFile) 33 { 34 // The file might have been preallocated and the transfer stopped before being completed 35 // so always truncate the file to the actually written size before closing it. 36 if (!m_read) 37 m_pFile->Truncate(); 33 38 39 delete m_pFile; 40 } 41 34 42 for (unsigned int i = 0; i < BUFFERCOUNT; i++) 35 43 delete [] m_buffers[i]; 36 44 … … 40 48 bool CIOThread::Create(CFile* pFile, bool read, bool binary) 41 49 { 42 50 wxASSERT(pFile); 43 delete m_pFile; 51 52 if (m_pFile) 53 { 54 // The file might have been preallocated and the transfer stopped before being completed 55 // so always truncate the file to the actually written size before closing it. 56 if (!m_read) 57 m_pFile->Truncate(); 58 59 delete m_pFile; 60 } 61 44 62 m_pFile = pFile; 45 63 m_read = read; 46 64 m_binary = binary; -
src/include/optionsbase.h
41 41 OPTION_SPEEDLIMIT_OUTBOUND, 42 42 OPTION_SPEEDLIMIT_BURSTTOLERANCE, 43 43 44 OPTION_PREALLOCATE_SPACE, 45 44 46 OPTION_VIEW_HIDDEN_FILES, 45 47 46 48 OPTION_PRESERVE_TIMESTAMPS, -
src/interface/Options.cpp
77 77 { "Speedlimit inbound", number, _T("100"), normal }, 78 78 { "Speedlimit outbound", number, _T("20"), normal }, 79 79 { "Speedlimit burst tolerance", number, _T("0"), normal }, 80 { "Preallocate space", number, _T("1"), normal }, 80 81 { "View hidden files", number, _T("0"), normal }, 81 82 { "Preserve timestamps", number, _T("0"), normal }, 82 83 { "Socket recv buffer size (v2)", number, _T("4194304"), normal }, // Make it large enough by default -
src/interface/resources/xrc/settings.xrc
946 946 </content> 947 947 </object> 948 948 </object> 949 <object class="sizeritem">950 <object class="wxStaticText">951 </object>952 </object>953 949 <cols>2</cols> 954 950 <vgap>5</vgap> 955 951 <hgap>5</hgap> … … 1007 1003 </object> 1008 1004 <flag>wxGROW</flag> 1009 1005 </object> 1006 <object class="sizeritem"> 1007 <object class="wxStaticBoxSizer"> 1008 <label>Preallocation</label> 1009 <orient>wxVERTICAL</orient> 1010 <object class="sizeritem"> 1011 <object class="wxCheckBox" name="ID_ENABLE_PREALLOCATION"> 1012 <label>&Preallocate space before downloading</label> 1013 </object> 1014 <flag>wxLEFT|wxRIGHT|wxTOP</flag> 1015 <border>4</border> 1016 </object> 1017 </object> 1018 <flag>wxGROW</flag> 1019 </object> 1020 <object class="sizeritem"> 1021 <object class="wxStaticText"> 1022 </object> 1023 </object> 1010 1024 </object> 1011 1025 </object> 1012 1026 <object class="wxPanel" name="ID_SETTINGS_FILETYPE"> -
src/interface/settings/optionspage_transfer.cpp
70 70 #endif 71 71 XRCCTRL(*this, "ID_REPLACED", wxStaticText)->SetLabel(filtered); 72 72 73 bool enable_preallocation = m_pOptions->GetOptionVal(OPTION_PREALLOCATE_SPACE) != 0; 74 SetCheck(XRCID("ID_ENABLE_PREALLOCATION"), enable_preallocation, failure); 75 73 76 return !failure; 74 77 } 75 78 … … 87 90 SetOptionFromText(XRCID("ID_REPLACE"), OPTION_INVALID_CHAR_REPLACE); 88 91 SetOptionFromCheck(XRCID("ID_ENABLE_REPLACE"), OPTION_INVALID_CHAR_REPLACE_ENABLE); 89 92 93 SetOptionFromCheck(XRCID("ID_ENABLE_PREALLOCATION"), OPTION_PREALLOCATE_SPACE); 94 90 95 return true; 91 96 } 92 97