[*] Refactored FS resources to return AuOptional<const AuString &>

This commit is contained in:
Reece Wilson 2024-03-11 21:05:03 +00:00
parent 631fad8fd0
commit db1ff0cbf8
4 changed files with 75 additions and 66 deletions

View File

@ -12,12 +12,12 @@ namespace Aurora::IO::FS
/**
* @brief Provides an application specific storage path for sharing data amongst Aurora applications sharing the same branding info (defer to the init structure)
*/
AUKN_SYM bool GetSystemDomain(AuString &path);
AUKN_SYM AuOptional<const AuString &> GetSystemDomain();
/**
* @brief Provides an application specific storage path for user-local application data, isolated with respect to your Aurora application brand info (defer to the init structure)
*/
AUKN_SYM bool GetProfileDomain(AuString &path);
AUKN_SYM AuOptional<const AuString &> GetProfileDomain();
AUKN_SYM bool GetSystemResourcePath(const AuString &fileName, AuString &path);
@ -32,36 +32,36 @@ namespace Aurora::IO::FS
* @param path
* @return
*/
AUKN_SYM bool GetPackagePath(AuString &path);
AUKN_SYM AuOptional<const AuString &> GetPackagePath();
/**
* @brief Pulls the application directory as defined by the operating system standard file system hierarchy
* Otherwise, XDG_CONFIG_CONFIG or %appdata%.
* This directory might be sandboxed to the user or application by the operating system.
*/
AUKN_SYM bool GetAppData(AuString &path);
AUKN_SYM AuOptional<const AuString &> GetAppData();
/**
* @brief Pulls the users home directory, untouched
*/
AUKN_SYM bool GetUserHome(AuString &path);
AUKN_SYM AuOptional<const AuString &> GetUserHome();
/**
* @brief Global application data that requires no special permissions to access.
* This could be an SD-Card or user profile.
* This could be the root of the user managable aplication directory.
*/
AUKN_SYM bool GetWritableAppdata(AuString &path);
AUKN_SYM AuOptional<const AuString &> GetWritableAppdata();
/**
* @brief Global application data that requires special permissions to access, usually configured by a system account during installation
*/
AUKN_SYM bool GetRootAppdata(AuString &path);
AUKN_SYM AuOptional<const AuString &> GetRootAppdata();
/**
* @brief Get user installable application directory
*/
AUKN_SYM bool GetUserProgramsFolder(AuString &path);
AUKN_SYM AuOptional<const AuString &> GetUserProgramsFolder();
AUKN_SYM AuOptional<AuString> NewTempFile();

View File

@ -21,7 +21,18 @@ namespace Aurora::Console::ConsoleFIO
AuString path;
AuString procName;
if ((!gLogConfig.bWriteLogsToUserDir) || (!AuIOFS::GetProfileDomain(path)))
if (gLogConfig.bWriteLogsToUserDir)
{
if (auto optProfileDomain = AuIOFS::GetProfileDomain())
{
path = *optProfileDomain;
}
else
{
path = ".";
}
}
else
{
path = ".";
}

View File

@ -70,7 +70,11 @@ namespace Aurora::IO::FS
// Local Aurora profile
else if (path[iOffset] == '~')
{
if (!FS::GetProfileDomain(buffer))
if (auto optPath = GetProfileDomain())
{
buffer = *optPath;
}
else
{
result.clear();
return;
@ -79,7 +83,11 @@ namespace Aurora::IO::FS
// Global Aurora profile
else if (path[iOffset] == '!')
{
if (!FS::GetSystemDomain(buffer))
if (auto optPath = GetSystemDomain())
{
buffer = *optPath;
}
else
{
result.clear();
return;
@ -246,13 +254,19 @@ namespace Aurora::IO::FS
if (str[0] == '~')
{
AuFS::GetProfileDomain(str);
if (auto optPath = FS::GetProfileDomain())
{
str = *optPath;
}
return;
}
if (str[0] == '!')
{
AuFS::GetSystemDomain(str);
if (auto optPath = FS::GetSystemDomain())
{
str = *optPath;
}
return;
}
}

View File

@ -38,23 +38,28 @@ namespace Aurora::IO::FS
static AuOptional<AuString> gUserLibPath2;
static AuString gTempDir;
// Should the following be /opt? Probably, if it were a direct replacement for Windows' appdata on Linux for global software packages outside of our ecosystem, sure; however, this is strictly a fallback for when there is no home
// We don't support initially-undefined global application configurations across users on Unix targets. We can therefore conclue the application running is a service whose user is without a home, and should be subject to the same rules as an application deployed by a real package manager
// We don't support initially-undefined global application configurations across users on Unix targets. We can therefore conclude the application running is a service whose user is without a home, and should be subject to the same rules as daemon deployed by a real package manager
// For internal packages, in our own ecosystem of tools, I think this follows the UNIX spec, not that I care what arcahic C-with-vendor-packages-as-an-OS specification says.
// The only way you can break this assumption is if you argue for users who will be outside of our deployment pipeline, wanting global configs, and don't have write permission on a relevant global directory.
// They can shove it. Superuser should install software for all users.
// XDG (falling back to home) for non-root installs; for root installs, installing a service package, use /var; for root installs of an application whose system configs should be shared amongst all users, unsupported, idc, it's sandboxed per user
// We should use:
// 2> XDG envvars (with a fallback to a home relative path) for non-root installs; for special installs via package manager, use /var;
// 2> for root installs of an application whose system configs should be shared amongst all users, unsupported, idc, it's sandboxed per user.
// we don't have any good examples of home family computer-esc posix machines
static const char * kUnixAppData {"/var"};
AUKN_SYM bool GetSystemDomain(AuString &path)
AUKN_SYM AuOptional<const AuString &> GetSystemDomain()
{
path = gApplicationData;
return path.size();
return gApplicationData.size() ?
gApplicationData :
AuOptional<const AuString &> {};
}
AUKN_SYM bool GetProfileDomain(AuString &path)
AUKN_SYM AuOptional<const AuString &> GetProfileDomain()
{
path = gHomeDirectory;
return path.size();
return gHomeDirectory.size() ?
gHomeDirectory :
AuOptional<const AuString &> {};
}
AUKN_SYM bool GetSystemResourcePath(const AuString &fileName, AuString &path)
@ -453,71 +458,50 @@ namespace Aurora::IO::FS
gApplicationData.clear();
}
AUKN_SYM bool GetAppData(AuString &path)
AUKN_SYM AuOptional<const AuString &> GetAppData()
{
path.clear();
if (gUserWritableAppData.empty())
{
return false;
}
path = gUserWritableAppData;
return path.size();
return gUserWritableAppData.size() ?
gUserWritableAppData :
AuOptional<const AuString &> {};
}
AUKN_SYM bool GetUserHome(AuString &path)
AUKN_SYM AuOptional<const AuString &> GetUserHome()
{
path.clear();
if (gUserHomeDirectory.empty())
{
return false;
}
path = gUserHomeDirectory;
return path.size();
return gUserHomeDirectory.size() ?
gUserHomeDirectory :
AuOptional<const AuString &> {};
}
AUKN_SYM bool GetPackagePath(AuString &path)
AUKN_SYM AuOptional<const AuString &> GetPackagePath()
{
// TODO: iOS/mac OS -> CFBundleCopyResourcesDirectoryURL
if (auto pProcessDirectory = Process::GetProcessDirectory())
if (auto optProcessDirectory = Process::GetProcessDirectory())
{
path = *pProcessDirectory;
return true;
return optProcessDirectory;
}
return false;
return AuOptional<const AuString &>{};
}
AUKN_SYM bool GetWritableAppdata(AuString &path)
AUKN_SYM AuOptional<const AuString &> GetWritableAppdata()
{
path.clear();
if (gGlobalWritableAppDirectory.empty())
{
return GetSystemDomain(path);
}
path = gGlobalWritableAppDirectory;
return path.size();
return gGlobalWritableAppDirectory.size() ?
gGlobalWritableAppDirectory :
AuOptional<const AuString &> {};
}
AUKN_SYM bool GetRootAppdata(AuString &path)
AUKN_SYM AuOptional<const AuString &> GetRootAppdata()
{
path.clear();
if (gAdminWritableAppDirectory.empty())
{
return false;
}
path = gAdminWritableAppDirectory;
return path.size();
return gAdminWritableAppDirectory.size() ?
gAdminWritableAppDirectory :
AuOptional<const AuString &> {};
}
AUKN_SYM bool GetUserProgramsFolder(AuString &path)
AUKN_SYM AuOptional<const AuString &> GetUserProgramsFolder()
{
path.clear();
if (gProgramsFolder.empty())
{
return false;
}
path = gProgramsFolder;
return path.size();
return gProgramsFolder.size() ?
gProgramsFolder :
AuOptional<const AuString &> {};
}
AUKN_SYM AuOptional<AuString> NewTempFile()