AuroraRuntime/Source/IO/FS/FileAttrs.Unix.cpp
Reece Wilson f43251c8fc [+] AuNet::ISocketChannelEventListener
[+] AuFS::UpdateTimes
[+] AuFS::UpdateFileTimes
[+] AuFS::CompressEx
[*] AuFS::Compress now rejects files that look to be already compressed
[+] AuFS::DecompressEx
[+] AuFS::Create
[+] AuFS::WriteNewFile
[+] AuFS::WriteNewString
[+] AuFs::FileAttrsList
[+] AuFs::FileAttrsGet
[+] AuFs::FileAttrsSet
[+] DirectoryLogger::uMaxLogsOrZeroBeforeCompress
[+] ISocketChannel.AddEventListener
[+] ISocketChannel.AddEventListener
[+] DirectoryLogger.uMaxLogsOrZeroBeforeCompress
[*] Fix UNIX regression
[*] Fix up stream socket channel realloc IPC
[*] Fix shutdown regression in pretty much everything thanks to 8ff81df1's dumbass fix
    (fixes fence regression on shutdown)
[*] Fix DirDeleterEx formatting of reported failed paths
[*] Fix up file not truncated if already exists bugs. Extended and alternative apis added.
[*] Fix ICompressionStream::ReadEx returning the wrong read value
[+] Legacy compression API can now self-correct once newer stream processor objects are added
2023-02-04 19:43:01 +00:00

123 lines
3.0 KiB
C++

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: FileAttrs.Unix.cpp
Date: 2023-2-4
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "FS.hpp"
#include "FileAttrs.Unix.hpp"
#include <sys/types.h>
#include <sys/xattr.h>
namespace Aurora::IO::FS
{
AUKN_SYM AuList<AuString> FileAttrsList(const AuString &path)
{
static const auto kLength = 10 * 1024;
AuString buffer;
auto srcPath = NormalizePathRet(path);
if (pathex.empty())
{
return {};
}
if (!AuTryResize(buffer, kLength))
{
SysPushErrorMemory();
return {};
}
auto length = ::listxattr(srcPath.c_str(), attr.c_str(), buffer.data(), buffer.size(), 0 /*no follow symlinks*/);
if (length < 0)
{
SysPushErrorIO("Error listing attributes");
return {};
}
if (!AuTryResize(buffer, length))
{
SysPushErrorMemory();
return {};
}
return AuSplitString(buffer, "\00");
}
AUKN_SYM AuResult<AuByteBuffer> FileAttrsGet(const AuString &path, const AuString &attr)
{
AuByteBuffer buffer;
auto srcPath = NormalizePathRet(path);
if (pathex.empty())
{
return {};
}
auto length = ::getxattr(srcPath.c_str(), attr.c_str(), nullptr, 0, 0 /*no follow symlinks*/);
if (length < 0)
{
SysPushErrorIO("Error reading attribute");
return {};
}
if (!length)
{
return AuMove(buffer);
}
if (!AuTryResize(buffer, length))
{
SysPushErrorMemory();
return {};
}
length = ::getxattr(srcPath.c_str(), attr.c_str(), buffer.base, length, 0 /*no follow symlinks*/);
if (length < 0)
{
SysPushErrorIO("Error reading attribute");
return {};
}
buffer.writePtr += length;
return AuMove(buffer);
}
AUKN_SYM bool FileAttrsSet(const AuString &path, const AuString &attr, const Memory::MemoryViewRead &view)
{
auto srcPath = NormalizePathRet(path);
if (pathex.empty())
{
return false;
}
if (::setxattr(srcPath.c_str(), attr.c_str(), view.ptr, view.length, XATTR_CREATE) == -1)
{
if (errno == EEXIST)
{
if (::setxattr(srcPath.c_str(), attr.c_str(), view.ptr, view.length, XATTR_REPLACE) == -1)
{
SysPushErrorIO();
return false;
}
}
}
return true;
}
AUKN_SYM bool FileAttrsDel(const AuString &path, const AuString &attr)
{
auto srcPath = NormalizePathRet(path);
if (pathex.empty())
{
return false;
}
return (::removexattr(srcPath.c_str(), attr.c_str()) == 0) ||
(errno == ENODATA);
}
}