Skip to content

Commit dd9f3c9

Browse files
AtkinsSJawesomekling
authored andcommitted
HackStudio: Absolutize project paths before opening them
Relative paths cause issues in a couple of ways: - `open_project()` sets the working directory to that path, and then opens a project at that same path. This means opening `./foo` goes to `./foo`, and then tries to open `./foo/foo`. - Even with that rearranged, we would then have issues with trying to open files, because again we would try to open `./foo/foo/file` instead of `./foo/file`. - The relative path would get saved in "Recent Projects" which is wrong. Absolutizing the path before using it means we avoid these issues, and without having to rearchitect everything. :^)
1 parent 6db4d3b commit dd9f3c9

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Userland/DevTools/HackStudio/HackStudioWidget.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,23 @@ void HackStudioWidget::open_project(ByteString const& root_path)
239239
{
240240
if (warn_unsaved_changes("There are unsaved changes, do you want to save before closing current project?") == ContinueDecision::No)
241241
return;
242-
if (auto result = Core::System::chdir(root_path); result.is_error()) {
242+
auto absolute_root_path = FileSystem::absolute_path(root_path).release_value_but_fixme_should_propagate_errors();
243+
if (auto result = Core::System::chdir(absolute_root_path); result.is_error()) {
243244
warnln("Failed to open project: {}", result.release_error());
244245
exit(1);
245246
}
246247
if (m_project) {
247248
close_current_project();
248249
}
249-
m_project = Project::open_with_root_path(root_path);
250+
m_project = Project::open_with_root_path(absolute_root_path);
250251
VERIFY(m_project);
251252
m_project_builder = make<ProjectBuilder>(*m_terminal_wrapper, *m_project);
252253
if (m_project_tree_view) {
253254
m_project_tree_view->set_model(m_project->model());
254255
m_project_tree_view->update();
255256
}
256257
if (m_git_widget->initialized()) {
257-
m_git_widget->change_repo(root_path);
258+
m_git_widget->change_repo(absolute_root_path);
258259
m_git_widget->refresh();
259260
}
260261
if (Debugger::is_initialized()) {
@@ -275,8 +276,8 @@ void HackStudioWidget::open_project(ByteString const& root_path)
275276
};
276277

277278
auto recent_projects = read_recent_projects();
278-
recent_projects.remove_all_matching([&](auto& p) { return p == root_path; });
279-
recent_projects.insert(0, root_path);
279+
recent_projects.remove_all_matching([&](auto& p) { return p == absolute_root_path; });
280+
recent_projects.insert(0, absolute_root_path);
280281
if (recent_projects.size() > recent_projects_history_size)
281282
recent_projects.shrink(recent_projects_history_size);
282283

Userland/DevTools/HackStudio/Project.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Project::Project(ByteString const& root_path)
1818

1919
OwnPtr<Project> Project::open_with_root_path(ByteString const& root_path)
2020
{
21+
VERIFY(LexicalPath(root_path).is_absolute());
2122
if (!FileSystem::is_directory(root_path))
2223
return {};
2324
return adopt_own(*new Project(root_path));

0 commit comments

Comments
 (0)