mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
Userland: Use Core::DirIterator::next_full_path()
Simplify some code by using this instead of concatenating the full path ourselves at the call site.
This commit is contained in:
parent
b41b6dd279
commit
2a6a54dea5
6 changed files with 14 additions and 24 deletions
|
@ -171,8 +171,7 @@ void DevicesModel::update()
|
|||
auto fill_in_paths_from_dir = [this](const String& dir) {
|
||||
Core::DirIterator dir_iter { dir, Core::DirIterator::Flags::SkipDots };
|
||||
while (dir_iter.has_next()) {
|
||||
auto name = dir_iter.next_path();
|
||||
auto path = String::formatted("{}/{}", dir, name);
|
||||
auto path = dir_iter.next_full_path();
|
||||
struct stat statbuf;
|
||||
if (lstat(path.characters(), &statbuf) != 0) {
|
||||
VERIFY_NOT_REACHED();
|
||||
|
|
|
@ -78,16 +78,13 @@ public:
|
|||
Core::DirIterator iterator("/res/cursors", Core::DirIterator::Flags::SkipDots);
|
||||
|
||||
while (iterator.has_next()) {
|
||||
auto path = iterator.next_path();
|
||||
auto path = iterator.next_full_path();
|
||||
if (path.contains("2x"))
|
||||
continue;
|
||||
Cursor cursor;
|
||||
StringBuilder full_path;
|
||||
full_path.append("/res/cursors/");
|
||||
full_path.append(path);
|
||||
cursor.path = full_path.to_string();
|
||||
cursor.path = move(path);
|
||||
cursor.bitmap = Gfx::Bitmap::load_from_file(cursor.path);
|
||||
auto filename_split = path.split('.');
|
||||
auto filename_split = cursor.path.split('.');
|
||||
cursor.name = filename_split[0];
|
||||
m_cursors.append(move(cursor));
|
||||
}
|
||||
|
@ -161,14 +158,11 @@ public:
|
|||
Core::DirIterator big_iterator("/res/icons/32x32", Core::DirIterator::Flags::SkipDots);
|
||||
|
||||
while (big_iterator.has_next()) {
|
||||
auto path = big_iterator.next_path();
|
||||
auto path = big_iterator.next_full_path();
|
||||
if (!path.contains("filetype-") && !path.contains("app-"))
|
||||
continue;
|
||||
IconSet icon_set;
|
||||
StringBuilder full_path;
|
||||
full_path.append("/res/icons/32x32/");
|
||||
full_path.append(path);
|
||||
icon_set.big_icon = Gfx::Bitmap::load_from_file(full_path.to_string());
|
||||
icon_set.big_icon = Gfx::Bitmap::load_from_file(path);
|
||||
auto filename_split = path.split('.');
|
||||
icon_set.name = filename_split[0];
|
||||
m_icon_sets.append(move(icon_set));
|
||||
|
@ -179,14 +173,11 @@ public:
|
|||
Core::DirIterator little_iterator("/res/icons/16x16", Core::DirIterator::Flags::SkipDots);
|
||||
|
||||
while (little_iterator.has_next()) {
|
||||
auto path = little_iterator.next_path();
|
||||
auto path = little_iterator.next_full_path();
|
||||
if (!path.contains("filetype-") && !path.contains("app-"))
|
||||
continue;
|
||||
IconSet icon_set;
|
||||
StringBuilder full_path;
|
||||
full_path.append("/res/icons/16x16/");
|
||||
full_path.append(path);
|
||||
icon_set.little_icon = Gfx::Bitmap::load_from_file(full_path.to_string());
|
||||
icon_set.little_icon = Gfx::Bitmap::load_from_file(path);
|
||||
auto filename_split = path.split('.');
|
||||
icon_set.name = filename_split[0];
|
||||
for (size_t i = 0; i < big_icons_found; i++) {
|
||||
|
|
|
@ -142,7 +142,7 @@ static HashMap<String, String>& man_paths()
|
|||
// FIXME: This should also search man3, possibly other places..
|
||||
Core::DirIterator it("/usr/share/man/man2", Core::DirIterator::Flags::SkipDots);
|
||||
while (it.has_next()) {
|
||||
auto path = String::formatted("/usr/share/man/man2/{}", it.next_path());
|
||||
auto path = it.next_full_path();
|
||||
auto title = LexicalPath(path).title();
|
||||
paths.set(title, path);
|
||||
}
|
||||
|
|
|
@ -55,10 +55,10 @@ static String get_child_path_from_inode_index(const String& path, unsigned child
|
|||
}
|
||||
|
||||
while (iterator.has_next()) {
|
||||
auto child_full_path = String::formatted("{}/{}", path, iterator.next_path());
|
||||
struct stat st;
|
||||
auto child_full_path = iterator.next_full_path();
|
||||
|
||||
if (lstat(child_full_path.characters(), &st)) {
|
||||
struct stat st = {};
|
||||
if (lstat(child_full_path.characters(), &st) < 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ static void iterate_directory_recursively(const String& directory_path, Callback
|
|||
Core::DirIterator directory_iterator(directory_path, Core::DirIterator::Flags::SkipDots);
|
||||
|
||||
while (directory_iterator.has_next()) {
|
||||
auto file_path = String::formatted("{}/{}", directory_path, directory_iterator.next_path());
|
||||
auto file_path = directory_iterator.next_full_path();
|
||||
if (Core::File::is_directory(file_path)) {
|
||||
iterate_directory_recursively(file_path, callback);
|
||||
} else {
|
||||
|
|
|
@ -168,7 +168,7 @@ void iterate_directory_recursively(const String& directory_path, Callback callba
|
|||
Core::DirIterator directory_iterator(directory_path, Core::DirIterator::Flags::SkipDots);
|
||||
|
||||
while (directory_iterator.has_next()) {
|
||||
auto file_path = String::format("%s/%s", directory_path.characters(), directory_iterator.next_path().characters());
|
||||
auto file_path = directory_iterator.next_full_path();
|
||||
if (Core::File::is_directory(file_path)) {
|
||||
iterate_directory_recursively(file_path, callback);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue