diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index a653445..7c7f8a4 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -3456,13 +3456,13 @@ void Client::start_up() { set_tag(bot_token_id_); auto suff = bot_token_with_dc_ + TD_DIR_SLASH; -#if TD_PORT_WINDOWS - for (auto &c : suff) { - if (c == ':') { - c = '~'; + if (!parameters_->allow_colon_in_filenames_) { + for (auto &c : suff) { + if (c == ':') { + c = '~'; + } } } -#endif dir_ = parameters_->working_directory_ + suff; class TdCallback : public td::TdCallback { diff --git a/telegram-bot-api/ClientParameters.h b/telegram-bot-api/ClientParameters.h index e686887..a0f2333 100644 --- a/telegram-bot-api/ClientParameters.h +++ b/telegram-bot-api/ClientParameters.h @@ -55,6 +55,7 @@ struct SharedData { struct ClientParameters { td::string working_directory_; + bool allow_colon_in_filenames_ = true; bool local_mode_ = false; diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index 6454651..c43ad34 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -382,6 +382,17 @@ int main(int argc, char *argv[]) { } r_temp_file.ok_ref().first.close(); td::unlink(r_temp_file.ok().second).ensure(); + + auto r_temp_dir = td::mkdtemp(working_directory, "1:a"); + if (r_temp_dir.is_error()) { + parameters->allow_colon_in_filenames_ = false; + r_temp_dir = td::mkdtemp(working_directory, "1~a"); + if (r_temp_dir.is_error()) { + return td::Status::Error(PSLICE() << "Can't create directories in the directory \"" << working_directory + << "\". Use --dir option to specify a writable working directory"); + } + } + td::rmdir(r_temp_dir.ok()).ensure(); } if (!temporary_directory.empty()) {