Skip to content

Commit

Permalink
Improve handling of file name conflicts when sending files
Browse files Browse the repository at this point in the history
Use random characters after a few attempts.
  • Loading branch information
reupen committed Oct 1, 2017
1 parent 7a60f2d commit 3b46e65
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Fixed corruption of smart playlists with nested rules
* Fixed various clipped labels in preferences and other dialog boxes
* Reorganised conversion preferences and clarified some setting labels
* Improved handling of file name conflicts when adding files to a device
* Disabled support for iOS device sync pause/cancel requests due to instability caused
* Compiled with Visual Studio 2017 15.3
* Compiled with latest foobar2000 SDK (foobar2000 1.3+ now required)
Expand Down
20 changes: 15 additions & 5 deletions foo_dop/file_adder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ void ipod_add_files::run (ipod_device_ptr_ref_t p_ipod, const pfc::list_base_con
pfc::list_t<file_info_impl> p_hint_info;
pfc::list_t<t_filestats> p_hint_stats;
pfc::ptr_list_t<const file_info> p_hint_info_ptrs;
mmh::GenRand gen_rand;

t_size j, counter=0, count_added=0, progress_index=0;
try
Expand Down Expand Up @@ -459,13 +460,22 @@ void ipod_add_files::run (ipod_device_ptr_ref_t p_ipod, const pfc::list_base_con
if (filesystem::g_exists(dsttemp, p_abort))
{
t_uint32 index = 0;
filename.truncate(/*31 - 1 - ext.length()*/ p_mappings.extra_filename_characters + 4 + 4 - 1 - ext.length() - 3 - mobile_extra);
const auto file_name_len = p_mappings.extra_filename_characters + 4 + 4 - 1 - ext.length() - mobile_extra;
filename.truncate(file_name_len - 3);
do {
if (index == 10)
filename.truncate(/*31 - 1 - ext.length()*/ p_mappings.extra_filename_characters + 4 + 4 - 1 - ext.length() - 4 - mobile_extra);
if (index==100) throw pfc::exception("Gave up looking for suitable filename");
dsttemp.reset();
dsttemp << dst.get_ptr() << p_ipod->get_path_separator_ptr() << filename.get_ptr() << "(" << index << ")" <<"." << ext;
dsttemp << dst.get_ptr() << p_ipod->get_path_separator_ptr();
if (index < 5) {
dsttemp << filename.get_ptr() << "(" << index << ")";
} else if (index < 10) {
const auto num_rand_bytes = file_name_len / 2;
pfc::array_staticsize_t<uint8_t> rand_bytes(num_rand_bytes);
gen_rand.run(rand_bytes.get_ptr(), num_rand_bytes);
dsttemp << pfc::format_hexdump_ex(rand_bytes.get_ptr(), num_rand_bytes, "");
} else {
throw pfc::exception("Gave up looking for suitable filename");
}
dsttemp << "." << ext;
index++;
}
while (filesystem::g_exists(dsttemp, p_abort));
Expand Down

0 comments on commit 3b46e65

Please sign in to comment.