1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-29 17:25:10 +00:00

Shell: Improve readability of cache_path()

I prefer String::format over StringBuilder here.
Also simplified a weird continue statement.
This commit is contained in:
William McPherson 2019-12-10 18:02:43 +11:00 committed by Andreas Kling
parent c0696ad3aa
commit bb311b970f
2 changed files with 4 additions and 11 deletions

View file

@ -51,16 +51,10 @@ void LineEditor::cache_path()
CDirIterator programs(directory.characters(), CDirIterator::SkipDots);
while (programs.has_next()) {
auto program = programs.next_path();
StringBuilder program_path;
program_path.append(directory.characters());
program_path.append('/');
program_path.append(program.characters());
String program_path = String::format("%s/%s", directory.characters(), program.characters());
struct stat program_status;
int stat_error = stat(program_path.to_string().characters(), &program_status);
if (stat_error || !(program_status.st_mode & S_IXUSR))
continue;
int stat_error = stat(program_path.characters(), &program_status);
if (!stat_error && (program_status.st_mode & S_IXUSR))
m_path.append(program.characters());
}
}

View file

@ -3,7 +3,6 @@
#include <AK/BinarySearch.h>
#include <AK/QuickSort.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/Vector.h>
#include <LibCore/CDirIterator.h>
#include <sys/stat.h>