1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 11:37:44 +00:00

LibCore+Userland: Remove File::ensure_parent_directories

We have a much safer and more powerful alternative now, so let's move
the few users over.
This commit is contained in:
kleines Filmröllchen 2022-04-10 20:51:01 +02:00 committed by Andreas Kling
parent 0fd09b2381
commit 5319e3a03f
7 changed files with 14 additions and 48 deletions

View file

@ -181,42 +181,6 @@ String File::real_path_for(String const& filename)
return real_path;
}
bool File::ensure_parent_directories(String const& path)
{
char* parent_buffer = strdup(path.characters());
ScopeGuard free_buffer = [parent_buffer] { free(parent_buffer); };
char const* parent = dirname(parent_buffer);
return ensure_directories(parent);
}
bool File::ensure_directories(String const& path)
{
VERIFY(path.starts_with("/"));
int saved_errno = 0;
ScopeGuard restore_errno = [&saved_errno] { errno = saved_errno; };
int rc = mkdir(path.characters(), 0755);
saved_errno = errno;
if (rc == 0 || errno == EEXIST)
return true;
if (errno != ENOENT)
return false;
bool ok = ensure_parent_directories(path);
saved_errno = errno;
if (!ok)
return false;
rc = mkdir(path.characters(), 0755);
saved_errno = errno;
return rc == 0;
}
String File::current_working_directory()
{
char* cwd = getcwd(nullptr, 0);