From b2484ead1075450040ce8b6897f6b573c110ed7d Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 20 Mar 2010 08:18:49 +0000 Subject: [PATCH] only allocate a file if it's not already allocated (windows) --- src/file.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/file.cpp b/src/file.cpp index ef6432f75..38421385c 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1478,15 +1478,21 @@ namespace libtorrent return false; } } -#if _WIN32_WINNT >= 0x501 - // TODO: again, only allocate the space if the file - // is not fully allocated +#if _WIN32_WINNT >= 0x501 if ((m_open_mode & sparse) == 0) { - // if the user has permissions, avoid filling - // the file with zeroes, but just fill it with - // garbage instead - SetFileValidData(m_file_handle, offs.QuadPart); + // only allocate the space if the file + // is not fully allocated + offs.LowPart = GetCompressedFileSize(m_path.c_str(), &offs.HighPart); + ec.assign(GetLastError(), get_system_category()); + if (ec) return false; + if (offs.QuadPart != s) + { + // if the user has permissions, avoid filling + // the file with zeroes, but just fill it with + // garbage instead + SetFileValidData(m_file_handle, offs.QuadPart); + } } #endif #else