fix: avoid creating client_id file for empty DIR_CRASH_DUMPS (#25296)
This commit is contained in:
parent
733d56e908
commit
03e60cce8b
1 changed files with 13 additions and 7 deletions
|
@ -86,18 +86,22 @@ const std::map<std::string, std::string>& GetGlobalCrashKeys() {
|
||||||
return GetGlobalCrashKeysMutable();
|
return GetGlobalCrashKeysMutable();
|
||||||
}
|
}
|
||||||
|
|
||||||
base::FilePath GetClientIdPath() {
|
bool GetClientIdPath(base::FilePath* path) {
|
||||||
base::FilePath path;
|
if (base::PathService::Get(electron::DIR_CRASH_DUMPS, path)) {
|
||||||
base::PathService::Get(electron::DIR_CRASH_DUMPS, &path);
|
*path = path->Append("client_id");
|
||||||
return path.Append("client_id");
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ReadClientId() {
|
std::string ReadClientId() {
|
||||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||||
std::string client_id;
|
std::string client_id;
|
||||||
// "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".length == 36
|
// "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".length == 36
|
||||||
if (!base::ReadFileToStringWithMaxSize(GetClientIdPath(), &client_id, 36) ||
|
base::FilePath client_id_path;
|
||||||
client_id.size() != 36)
|
if (GetClientIdPath(&client_id_path) &&
|
||||||
|
(!base::ReadFileToStringWithMaxSize(client_id_path, &client_id, 36) ||
|
||||||
|
client_id.size() != 36))
|
||||||
return std::string();
|
return std::string();
|
||||||
return client_id;
|
return client_id;
|
||||||
}
|
}
|
||||||
|
@ -105,7 +109,9 @@ std::string ReadClientId() {
|
||||||
void WriteClientId(const std::string& client_id) {
|
void WriteClientId(const std::string& client_id) {
|
||||||
DCHECK_EQ(client_id.size(), 36u);
|
DCHECK_EQ(client_id.size(), 36u);
|
||||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||||
base::WriteFile(GetClientIdPath(), client_id);
|
base::FilePath client_id_path;
|
||||||
|
if (GetClientIdPath(&client_id_path))
|
||||||
|
base::WriteFile(client_id_path, client_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetClientId() {
|
std::string GetClientId() {
|
||||||
|
|
Loading…
Reference in a new issue