Automatically detect whether colon can be used in a directory name.

This commit is contained in:
levlam 2021-06-23 02:03:22 +03:00
parent 08a92a2347
commit badeb9a7f0
3 changed files with 17 additions and 5 deletions

View File

@ -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 {

View File

@ -55,6 +55,7 @@ struct SharedData {
struct ClientParameters {
td::string working_directory_;
bool allow_colon_in_filenames_ = true;
bool local_mode_ = false;

View File

@ -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()) {