pitrou commented on a change in pull request #9265:
URL: https://github.com/apache/arrow/pull/9265#discussion_r561910697
##########
File path: cpp/src/arrow/util/io_util.cc
##########
@@ -1482,31 +1482,51 @@ std::string MakeRandomName(int num_chars) {
} // namespace
Result<std::unique_ptr<TemporaryDir>> TemporaryDir::Make(const std::string&
prefix) {
- std::string suffix = MakeRandomName(8);
+ const int kNumChars = 8;
+
NativePathString base_name;
- ARROW_ASSIGN_OR_RAISE(base_name, StringToNative(prefix + suffix));
+
+ auto MakeBaseName = [&]() {
+ std::string suffix = MakeRandomName(kNumChars);
+ return StringToNative(prefix + suffix);
+ };
+
+ auto TryCreatingDirectory =
+ [&](const NativePathString& base_dir) ->
Result<std::unique_ptr<TemporaryDir>> {
+ Status st;
+ for (int attempt = 0; attempt < 3; ++attempt) {
+ PlatformFilename fn(base_dir + kNativeSep + base_name + kNativeSep);
+ auto result = CreateDir(fn);
+ if (!result.ok()) {
+ // Probably a permissions error or a non-existing base_dir
+ return nullptr;
+ }
+ if (*result) {
+ return std::unique_ptr<TemporaryDir>(new TemporaryDir(std::move(fn)));
+ }
+ // The random name already exists in base_dir, try with another name
+ st = Status::IOError("Path already exists: '", fn.ToString(), "'");
+ ARROW_ASSIGN_OR_RAISE(base_name, MakeBaseName());
+ }
+ return st;
+ };
+
+ ARROW_ASSIGN_OR_RAISE(base_name, MakeBaseName());
auto base_dirs = GetPlatformTemporaryDirs();
DCHECK_NE(base_dirs.size(), 0);
- auto st = Status::OK();
- for (const auto& p : base_dirs) {
- PlatformFilename fn(p + kNativeSep + base_name + kNativeSep);
- auto result = CreateDir(fn);
- if (!result.ok()) {
- st = result.status();
- continue;
- }
- if (!*result) {
- // XXX Should we retry with another random name?
- return Status::IOError("Path already exists: '", fn.ToString(), "'");
- } else {
- return std::unique_ptr<TemporaryDir>(new TemporaryDir(std::move(fn)));
+ for (const auto& base_dir : base_dirs) {
+ ARROW_ASSIGN_OR_RAISE(auto ptr, TryCreatingDirectory(base_dir));
+ if (ptr) {
+ return std::move(ptr);
Review comment:
Because some old gcc fails compiling without it:
https://github.com/apache/arrow/runs/1728457990#step:9:552
https://github.com/apache/arrow/runs/1728457638#step:7:992
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]