Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c491e4d

Browse filesBrowse files
joyeecheungtargos
authored andcommitted
src: fall back to env->exec_path() for default profile directory
When the current working directory is deleted, fall back to exec_path as the default profile directory. PR-URL: #28252 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 040b9db commit c491e4d
Copy full SHA for c491e4d

File tree

Expand file treeCollapse file tree

1 file changed

+13
-10
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-10
lines changed
Open diff view settings
Collapse file

‎src/inspector_profiler.cc‎

Copy file name to clipboardExpand all lines: src/inspector_profiler.cc
+13-10Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,20 @@ void EndStartedProfilers(Environment* env) {
320320
}
321321
}
322322

323-
std::string GetCwd() {
323+
std::string GetCwd(Environment* env) {
324324
char cwd[PATH_MAX_BYTES];
325325
size_t size = PATH_MAX_BYTES;
326326
int err = uv_cwd(cwd, &size);
327-
// This can fail if the cwd is deleted.
328-
// TODO(joyeecheung): store this in the Environment during Environment
329-
// creation and fallback to exec_path and argv0, then we no longer need
330-
// SetCoverageDirectory().
331-
CHECK_EQ(err, 0);
332-
CHECK_GT(size, 0);
333-
return cwd;
327+
328+
if (err == 0) {
329+
CHECK_GT(size, 0);
330+
return cwd;
331+
}
332+
333+
// This can fail if the cwd is deleted. In that case, fall back to
334+
// exec_path.
335+
const std::string& exec_path = env->exec_path();
336+
return exec_path.substr(0, exec_path.find_last_of(kPathSeparator));
334337
}
335338

336339
void StartProfilers(Environment* env) {
@@ -345,7 +348,7 @@ void StartProfilers(Environment* env) {
345348
if (env->options()->cpu_prof) {
346349
const std::string& dir = env->options()->cpu_prof_dir;
347350
env->set_cpu_prof_interval(env->options()->cpu_prof_interval);
348-
env->set_cpu_prof_dir(dir.empty() ? GetCwd() : dir);
351+
env->set_cpu_prof_dir(dir.empty() ? GetCwd(env) : dir);
349352
if (env->options()->cpu_prof_name.empty()) {
350353
DiagnosticFilename filename(env, "CPU", "cpuprofile");
351354
env->set_cpu_prof_name(*filename);
@@ -360,7 +363,7 @@ void StartProfilers(Environment* env) {
360363
if (env->options()->heap_prof) {
361364
const std::string& dir = env->options()->heap_prof_dir;
362365
env->set_heap_prof_interval(env->options()->heap_prof_interval);
363-
env->set_heap_prof_dir(dir.empty() ? GetCwd() : dir);
366+
env->set_heap_prof_dir(dir.empty() ? GetCwd(env) : dir);
364367
if (env->options()->heap_prof_name.empty()) {
365368
DiagnosticFilename filename(env, "Heap", "heapprofile");
366369
env->set_heap_prof_name(*filename);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.