Skip to content

Commit 393a665

Browse files
authored
fix: fix uuid.h to work on macOS (#271)
1 parent dd92530 commit 393a665

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

src/paimon/common/utils/uuid.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,36 @@
3131
#include <fstream>
3232
#include <string>
3333

34+
#if defined(__APPLE__)
35+
#include <uuid/uuid.h>
36+
37+
#include <array>
38+
#endif
39+
3440
namespace paimon {
3541

3642
class UUID {
3743
public:
3844
static bool Generate(std::string* output) {
45+
#if defined(__APPLE__)
3946
output->clear();
40-
std::ifstream f("/proc/sys/kernel/random/uuid");
41-
std::getline(f, /*&*/ *output);
47+
std::array<char, 37> buffer{};
48+
uuid_t uuid;
49+
uuid_generate_random(uuid);
50+
uuid_unparse_lower(uuid, buffer.data());
51+
*output = buffer.data();
4252
if (output->size() == 36) {
4353
return true;
44-
} else {
45-
output->clear();
46-
return false;
4754
}
55+
#else
56+
output->clear();
57+
std::ifstream f("/proc/sys/kernel/random/uuid");
58+
if (std::getline(f, /*&*/ *output) && output->size() == 36) {
59+
return true;
60+
}
61+
#endif
62+
output->clear();
63+
return false;
4864
}
4965
};
5066

0 commit comments

Comments
 (0)