diff options
author | Andreas Kling <kling@serenityos.org> | 2021-04-21 22:16:32 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-21 23:49:01 +0200 |
commit | 2a6a54dea5d5711288de67f0081da312488039d9 (patch) | |
tree | d39b8d0c3b146d7494c68ae5712bd3fa5a667939 | |
parent | b41b6dd279154a0873ce4c6a171fdd42fb827698 (diff) | |
download | serenity-2a6a54dea5d5711288de67f0081da312488039d9.zip |
Userland: Use Core::DirIterator::next_full_path()
Simplify some code by using this instead of concatenating the full path
ourselves at the call site.
-rw-r--r-- | Userland/Applications/SystemMonitor/DevicesModel.cpp | 3 | ||||
-rw-r--r-- | Userland/Demos/WidgetGallery/GalleryModels.h | 23 | ||||
-rw-r--r-- | Userland/DevTools/HackStudio/Editor.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/FileWatcher.cpp | 6 | ||||
-rw-r--r-- | Userland/Utilities/test-js.cpp | 2 | ||||
-rw-r--r-- | Userland/Utilities/test-web.cpp | 2 |
6 files changed, 14 insertions, 24 deletions
diff --git a/Userland/Applications/SystemMonitor/DevicesModel.cpp b/Userland/Applications/SystemMonitor/DevicesModel.cpp index 44a05fb550..f04e2c298e 100644 --- a/Userland/Applications/SystemMonitor/DevicesModel.cpp +++ b/Userland/Applications/SystemMonitor/DevicesModel.cpp @@ -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(); diff --git a/Userland/Demos/WidgetGallery/GalleryModels.h b/Userland/Demos/WidgetGallery/GalleryModels.h index 07d4791428..d25c3dea00 100644 --- a/Userland/Demos/WidgetGallery/GalleryModels.h +++ b/Userland/Demos/WidgetGallery/GalleryModels.h @@ -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++) { diff --git a/Userland/DevTools/HackStudio/Editor.cpp b/Userland/DevTools/HackStudio/Editor.cpp index 58ed61207f..474336a046 100644 --- a/Userland/DevTools/HackStudio/Editor.cpp +++ b/Userland/DevTools/HackStudio/Editor.cpp @@ -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); } diff --git a/Userland/Libraries/LibCore/FileWatcher.cpp b/Userland/Libraries/LibCore/FileWatcher.cpp index 46db6686d6..3c990e8c9a 100644 --- a/Userland/Libraries/LibCore/FileWatcher.cpp +++ b/Userland/Libraries/LibCore/FileWatcher.cpp @@ -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 {}; } diff --git a/Userland/Utilities/test-js.cpp b/Userland/Utilities/test-js.cpp index 8b312ab77d..dafddcc8c2 100644 --- a/Userland/Utilities/test-js.cpp +++ b/Userland/Utilities/test-js.cpp @@ -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 { diff --git a/Userland/Utilities/test-web.cpp b/Userland/Utilities/test-web.cpp index a05f0ae60b..e0b9596a94 100644 --- a/Userland/Utilities/test-web.cpp +++ b/Userland/Utilities/test-web.cpp @@ -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 { |