merged long-name truncation fix from RC_0_16
This commit is contained in:
parent
83f626c18e
commit
b943a9b057
|
@ -16,6 +16,7 @@
|
||||||
* fix uTP edge case where udp socket buffer fills up
|
* fix uTP edge case where udp socket buffer fills up
|
||||||
* fix nagle implementation in uTP
|
* fix nagle implementation in uTP
|
||||||
|
|
||||||
|
* fix long filename truncation on windows
|
||||||
* distinguish file open mode when checking files and downloading/seeding with bittorrent. updates storage interface
|
* distinguish file open mode when checking files and downloading/seeding with bittorrent. updates storage interface
|
||||||
* improve file_storage::map_file when dealing with invalid input
|
* improve file_storage::map_file when dealing with invalid input
|
||||||
* improve handling of invalid utf-8 sequences in strings in torrent files
|
* improve handling of invalid utf-8 sequences in strings in torrent files
|
||||||
|
|
|
@ -189,23 +189,48 @@ namespace libtorrent
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_EXTRA_EXPORT void trim_path_element(std::string& path_element)
|
TORRENT_EXTRA_EXPORT void trim_path_element(std::string& element)
|
||||||
{
|
{
|
||||||
const int max_path_len = TORRENT_MAX_PATH;
|
const int max_path_len = TORRENT_MAX_PATH;
|
||||||
if (int(path_element.size()) > max_path_len)
|
|
||||||
|
// on windows, the max path is expressed in
|
||||||
|
// unicode characters, not bytes
|
||||||
|
#if defined TORRENT_WINDOWS
|
||||||
|
std::wstring path_element;
|
||||||
|
utf8_wchar(element, path_element);
|
||||||
|
if (path_element.size() <= max_path_len) return;
|
||||||
|
|
||||||
|
// truncate filenames that are too long. But keep extensions!
|
||||||
|
std::wstring ext;
|
||||||
|
wchar_t const* ext1 = wcsrchr(path_element.c_str(), '.');
|
||||||
|
if (ext1 != NULL) ext = ext1;
|
||||||
|
|
||||||
|
if (ext.size() > 15)
|
||||||
{
|
{
|
||||||
// truncate filenames that are too long. But keep extensions!
|
path_element.resize(max_path_len);
|
||||||
std::string ext = extension(path_element);
|
|
||||||
if (ext.size() > 15)
|
|
||||||
{
|
|
||||||
path_element.resize(max_path_len);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
path_element.resize(max_path_len - ext.size());
|
|
||||||
path_element += ext;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
path_element.resize(max_path_len - ext.size());
|
||||||
|
path_element += ext;
|
||||||
|
}
|
||||||
|
wchar_utf8(path_element, element);
|
||||||
|
#else
|
||||||
|
std::string& path_element = element;
|
||||||
|
if (int(path_element.size()) <= max_path_len) return;
|
||||||
|
|
||||||
|
// truncate filenames that are too long. But keep extensions!
|
||||||
|
std::string ext = extension(path_element);
|
||||||
|
if (ext.size() > 15)
|
||||||
|
{
|
||||||
|
path_element.resize(max_path_len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
path_element.resize(max_path_len - ext.size());
|
||||||
|
path_element += ext;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_EXTRA_EXPORT std::string sanitize_path(std::string const& p)
|
TORRENT_EXTRA_EXPORT std::string sanitize_path(std::string const& p)
|
||||||
|
|
Loading…
Reference in New Issue