AuroraRuntime/Source/IO/FS/FS.hpp
J Reece Wilson fd0c5b51b2 Further Linux support
[+] Begin work on IO futexes for io release on process/thread exit
[+] Linux ::readdir iteration
[+] AuConsole buffering API
[*] Fix sleep as to not get interrupted by signals
[*] Switch the type of FS lock used under Linux
[*] Linux: Use new IPCHandle encoding scheme
[*] Fix undefined behaviour: unintialized timeout values (AuLoop/Linux)
[*] Fix undefined behaviour: ConsoleTTY clear line was called of a color of a random value on stack
[-] Remainings of std dir iterator
[*] Fix pthread_kill (aka send signal to pthread handle) always kills process. This is what you expect bc signal handler inheritance.
[*] Reformat the build Aurora.json file
[+] Added clang warning ignores to the build file
[*] Fix: UNIX need to use STDOUT_FILENO. Was using CRT handle in place of fd by mistake.
[+] Linux implementation for IO yield (AuIO::IOYield() - UNIX::LinuxOverlappedYield())
[*] Fix: Linux async end of stream processing. res 0 = zero bytes consumed. <= was detecting this as an error of code 0. Should succeed with zero bytes.
[+] Linux LoopQueue missing epilogue hook for the IO processor
[*] Various refactors and minor bug fixes
[*] Linux fix: Handle pipe EOS as zero
[*] Linux fix: thread termination via a user signal of 77. Need a force terminate.
[*] IPC handle: fix improper int to bool cast in the header setup within ToString
[*] Linux fix: HWInfo CPU topology regression
[-] Linux fix: remove SIGABRT handler
[*] Missing override in compression, exit, and consoletty headers.
[+] Unix Syslog logger backend
2022-08-02 05:52:57 +01:00

122 lines
3.0 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: FS.hpp
Date: 2021-6-16
Author: Reece
***/
#pragma once
#if !defined(NO_FSTREAM) && (!defined(__has_include) || __has_include(<fstream>))
#include <fstream>
#if !defined(HAS_FSTREAM)
#define HAS_FSTREAM
#endif
#endif
#if !defined(NO_STD_FS) && (!defined(__has_include) || __has_include(<filesystem>))
#include <filesystem>
#define HAS_STD_FS
#if !defined(_HAS_CXX17) && defined(AURORA_COMPILER_MSVC)
// map experimental::filesystem to filesystem::
// as in newer compilers it is not experimental anymore
namespace std
{
namespace filesystem = experimental::filesystem;
}
#endif
#endif
namespace Aurora::IO::FS
{
#if defined(VENDOR_GENERIC_MICROSOFT) || defined(VENDOR_CONSOLE_MICROSOFT)
static const unsigned char kPathSplitter = '\\';
static const AuString kDoublePathSplitter = "\\\\";
#else
static const unsigned char kPathSplitter = '/';
static const AuString kDoublePathSplitter = "//";
#endif
void _NormalizePath(AuString &str);
static void NormalizePath(AuString &str)
{
try
{
_NormalizePath(str);
}
catch (...)
{
str = {};
}
}
static auline AuString NormalizePathRet(const AuString &str)
{
try
{
AuString ret = str;
_NormalizePath(ret);
return ret;
}
catch (...)
{
return {};
}
}
bool _MkDir(const AuString &str);
static bool CreateDirectories(const AuString &cpath, bool isFile)
{
try
{
// This gives us a significant performance boost
AuString path;
if (isFile && GetDirectoryFromPath(path, cpath))
{
if (DirExists(path))
{
return true;
}
}
for (int i = 0; i < cpath.size(); i++)
{
bool end = i == cpath.size() - 1;
if ((cpath[i] == kPathSplitter) ||
((!isFile) && (end)))
{
auto subpath = end ? cpath : AuString(cpath.begin(), cpath.begin() + i);
if (subpath.empty())
{
continue;
}
if (DirExists(subpath))
{
continue;
}
if (!_MkDir(subpath))
{
if (!DirExists(subpath)) // copium. im worried :(
{
return false; // ...aw shit
}
}
}
}
return true;
}
catch (...)
{
return false;
}
}
void InitResources();
}