Skip to content

Commit cd0dda0

Browse files
authored
fix: allow blocking IO for setAppLogsPath to avoid DCHECK (electron#23111)
* fix: let setAppLogsPath write to disk on UI thread Otherwise, the DCHECK in thread_restrictions will fire. * scope the io allowance more tightly * oops, scope it tightly in the mac version too
1 parent 07654c4 commit cd0dda0

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

shell/browser/api/electron_api_app.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,13 +851,19 @@ void App::SetAppLogsPath(gin_helper::ErrorThrower thrower,
851851
thrower.ThrowError("Path must be absolute");
852852
return;
853853
}
854-
base::PathService::Override(DIR_APP_LOGS, custom_path.value());
854+
{
855+
base::ThreadRestrictions::ScopedAllowIO allow_io;
856+
base::PathService::Override(DIR_APP_LOGS, custom_path.value());
857+
}
855858
} else {
856859
base::FilePath path;
857860
if (base::PathService::Get(DIR_USER_DATA, &path)) {
858861
path = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName()));
859862
path = path.Append(base::FilePath::FromUTF8Unsafe("logs"));
860-
base::PathService::Override(DIR_APP_LOGS, path);
863+
{
864+
base::ThreadRestrictions::ScopedAllowIO allow_io;
865+
base::PathService::Override(DIR_APP_LOGS, path);
866+
}
861867
}
862868
}
863869
}
@@ -874,7 +880,6 @@ base::FilePath App::GetPath(gin_helper::ErrorThrower thrower,
874880
// If users try to get the logs path before setting a logs path,
875881
// set the path to a sensible default and then try to get it again
876882
if (!succeed && name == "logs") {
877-
base::ThreadRestrictions::ScopedAllowIO allow_io;
878883
SetAppLogsPath(thrower, base::Optional<base::FilePath>());
879884
succeed = base::PathService::Get(key, &path);
880885
}

shell/browser/api/electron_api_app_mac.mm

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,22 @@
2121
thrower.ThrowError("Path must be absolute");
2222
return;
2323
}
24-
base::PathService::Override(DIR_APP_LOGS, custom_path.value());
24+
{
25+
base::ThreadRestrictions::ScopedAllowIO allow_io;
26+
base::PathService::Override(DIR_APP_LOGS, custom_path.value());
27+
}
2528
} else {
2629
NSString* bundle_name =
2730
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
2831
NSString* logs_path =
2932
[NSString stringWithFormat:@"Library/Logs/%@", bundle_name];
3033
NSString* library_path =
3134
[NSHomeDirectory() stringByAppendingPathComponent:logs_path];
32-
base::PathService::Override(DIR_APP_LOGS,
33-
base::FilePath([library_path UTF8String]));
35+
{
36+
base::ThreadRestrictions::ScopedAllowIO allow_io;
37+
base::PathService::Override(DIR_APP_LOGS,
38+
base::FilePath([library_path UTF8String]));
39+
}
3440
}
3541
}
3642

0 commit comments

Comments
 (0)