1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 12:27:34 +00:00

AK+Everywhere: Remove "null state" of LexicalPath

This removes the default constructor of LexicalPath, and subsequently
modifies all its users to accommodate the change.
This commit is contained in:
Max Wipfli 2021-06-29 20:12:53 +02:00 committed by Andreas Kling
parent 4c018909f7
commit d8be530397
10 changed files with 52 additions and 52 deletions

View file

@ -83,18 +83,19 @@ static Optional<FileWatcherEvent> get_event_from_fd(int fd, HashMap<unsigned, St
return result;
}
static String canonicalize_path(String path)
{
if (!path.is_empty() && path[0] == '/')
return LexicalPath::canonicalized_path(move(path));
char* cwd = getcwd(nullptr, 0);
VERIFY(cwd);
return LexicalPath::join(cwd, move(path)).string();
}
Result<bool, String> FileWatcherBase::add_watch(String path, FileWatcherEvent::Type event_mask)
{
LexicalPath lexical_path;
if (path.length() > 0 && path[0] == '/') {
lexical_path = LexicalPath { path };
} else {
char* buf = getcwd(nullptr, 0);
lexical_path = LexicalPath::join(String(buf), path);
free(buf);
}
String canonical_path = canonicalize_path(move(path));
auto const& canonical_path = lexical_path.string();
if (m_path_to_wd.find(canonical_path) != m_path_to_wd.end()) {
dbgln_if(FILE_WATCHER_DEBUG, "add_watch: path '{}' is already being watched", canonical_path);
return false;
@ -125,16 +126,8 @@ Result<bool, String> FileWatcherBase::add_watch(String path, FileWatcherEvent::T
Result<bool, String> FileWatcherBase::remove_watch(String path)
{
LexicalPath lexical_path;
if (path.length() > 0 && path[0] == '/') {
lexical_path = LexicalPath { path };
} else {
char* buf = getcwd(nullptr, 0);
lexical_path = LexicalPath::join(String(buf), path);
free(buf);
}
String canonical_path = canonicalize_path(move(path));
auto const& canonical_path = lexical_path.string();
auto it = m_path_to_wd.find(canonical_path);
if (it == m_path_to_wd.end()) {
dbgln_if(FILE_WATCHER_DEBUG, "remove_watch: path '{}' is not being watched", canonical_path);

View file

@ -189,14 +189,14 @@ ModelIndex FileSystemModel::index(String path, int column) const
FileSystemModel::Node const* FileSystemModel::node_for_path(String const& path) const
{
LexicalPath lexical_path;
if (path == m_root_path) {
lexical_path = LexicalPath { "/" };
} else if (!m_root_path.is_empty() && path.starts_with(m_root_path)) {
lexical_path = LexicalPath { LexicalPath::relative_path(path, m_root_path) };
} else {
lexical_path = LexicalPath { move(path) };
}
String resolved_path;
if (path == m_root_path)
resolved_path = "/";
else if (!m_root_path.is_empty() && path.starts_with(m_root_path))
resolved_path = LexicalPath::relative_path(path, m_root_path);
else
resolved_path = path;
LexicalPath lexical_path(resolved_path);
const Node* node = m_root->m_parent_of_root ? &m_root->children.first() : m_root;
if (lexical_path.string() == "/")