[*] Harden POSIX FS Remove

This commit is contained in:
Reece Wilson 2023-09-20 20:17:27 +01:00
parent 259572724c
commit 4fa053ce97

View File

@ -346,6 +346,8 @@ namespace Aurora::IO::FS
AUKN_SYM bool Remove(const AuString &path)
{
struct stat s;
if (path.empty())
{
SysPushErrorArg("Cannot open an IO handle to the provided empty path");
@ -359,7 +361,38 @@ namespace Aurora::IO::FS
return false;
}
return remove(pathExpanded.c_str()) != -1;
if (::stat(pathExpanded.c_str(), &s) == -1)
{
if (errno == ENOENT)
{
return true;
}
}
else
{
if (S_ISDIR(s.st_mode))
{
if (::rmdir(pathExpanded.c_str()) == 0)
{
return true;
}
}
if (S_ISREG(s.st_mode))
{
if (::unlink(pathExpanded.c_str()) == 0)
{
return true;
}
}
}
if (::remove(pathExpanded.c_str()) == 0)
{
return true;
}
return false;
}
AUKN_SYM bool Relink(const AuString &src, const AuString &dest)