Overhaul cmake configuration, add console api, fix http code that caused issues with cgi-bin

This commit is contained in:
2026-05-27 03:02:16 -05:00
parent 266ef5f830
commit 8413c67ec6
177 changed files with 20088 additions and 17948 deletions

View File

@@ -1,33 +1,68 @@
/*
TessesFramework a library to make C++ easier for me, used in CrossLang:
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "TempFS.hpp"
#include "VFSFix.hpp"
namespace Tesses::Framework::Filesystem::Helpers
{
void ReadAllText(std::shared_ptr<VFS> vfs, VFSPath path, std::string& text);
void ReadAllLines(std::shared_ptr<VFS> vfs, VFSPath path, std::vector<std::string>& lines);
void ReadAllBytes(std::shared_ptr<VFS> vfs, VFSPath path, std::vector<uint8_t>& array);
std::string ReadAllText(std::shared_ptr<VFS> vfs, VFSPath path);
std::vector<std::string> ReadAllLines(std::shared_ptr<VFS> vfs, VFSPath path);
std::vector<uint8_t> ReadAllBytes(std::shared_ptr<VFS> vfs, VFSPath path);
void WriteAllText(std::shared_ptr<VFS> vfs, VFSPath path, const std::string& text);
void WriteAllLines(std::shared_ptr<VFS> vfs, VFSPath path, const std::vector<std::string>& parts);
void WriteAllBytes(std::shared_ptr<VFS> vfs, VFSPath path, const std::vector<uint8_t>& bytes);
namespace Tesses::Framework::Filesystem::Helpers {
void ReadAllText(std::shared_ptr<VFS> vfs, VFSPath path, std::string &text);
void ReadAllLines(std::shared_ptr<VFS> vfs, VFSPath path,
std::vector<std::string> &lines);
void ReadAllBytes(std::shared_ptr<VFS> vfs, VFSPath path,
std::vector<uint8_t> &array);
std::string ReadAllText(std::shared_ptr<VFS> vfs, VFSPath path);
std::vector<std::string> ReadAllLines(std::shared_ptr<VFS> vfs, VFSPath path);
std::vector<uint8_t> ReadAllBytes(std::shared_ptr<VFS> vfs, VFSPath path);
void WriteAllText(std::shared_ptr<VFS> vfs, VFSPath path,
const std::string &text);
void WriteAllLines(std::shared_ptr<VFS> vfs, VFSPath path,
const std::vector<std::string> &parts);
void WriteAllBytes(std::shared_ptr<VFS> vfs, VFSPath path,
const std::vector<uint8_t> &bytes);
void CopyStreamProgress(std::shared_ptr<Streams::Stream> src,std::shared_ptr<Streams::Stream> dest, std::function<void(int64_t offset, int64_t length)> progress);
void CopyStreamProgress(
std::shared_ptr<Streams::Stream> src, std::shared_ptr<Streams::Stream> dest,
std::function<void(int64_t offset, int64_t length)> progress);
void CopyFile(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc, std::shared_ptr<VFS> vfsDest, VFSPath pathDest, bool overwrite=true);
void CopyFile(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc, std::shared_ptr<VFS> vfsDest, VFSPath pathDest, std::function<void(int64_t offset, int64_t length)> progress, bool overwrite=true);
void CopyDirectory(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc, std::shared_ptr<VFS> vfsDest, VFSPath pathDest, bool overwrite=true);
void CopyDirectory(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc, std::shared_ptr<VFS> vfsDest, VFSPath pathDest, std::function<void(int64_t offset, int64_t length, VFSPath currentFile)> progress, bool overwrite=true);
void CopyFile(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc,
std::shared_ptr<VFS> vfsDest, VFSPath pathDest,
bool overwrite = true);
void CopyFile(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc,
std::shared_ptr<VFS> vfsDest, VFSPath pathDest,
std::function<void(int64_t offset, int64_t length)> progress,
bool overwrite = true);
void CopyDirectory(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc,
std::shared_ptr<VFS> vfsDest, VFSPath pathDest,
bool overwrite = true);
void CopyDirectory(
std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc, std::shared_ptr<VFS> vfsDest,
VFSPath pathDest,
std::function<void(int64_t offset, int64_t length, VFSPath currentFile)>
progress,
bool overwrite = true);
inline std::shared_ptr<TempFS> CreateTempFS(bool deleteOnDestroy=true)
{
return std::make_shared<TempFS>(deleteOnDestroy);
}
inline std::shared_ptr<TempFS> CreateTempFS(std::shared_ptr<VFS> vfs,bool deleteOnDestroy=true)
{
return std::make_shared<TempFS>(vfs,deleteOnDestroy);
}
inline std::shared_ptr<TempFS> CreateTempFS(bool deleteOnDestroy = true) {
return std::make_shared<TempFS>(deleteOnDestroy);
}
inline std::shared_ptr<TempFS> CreateTempFS(std::shared_ptr<VFS> vfs,
bool deleteOnDestroy = true) {
return std::make_shared<TempFS>(vfs, deleteOnDestroy);
}
}
} // namespace Tesses::Framework::Filesystem::Helpers

View File

@@ -1,46 +1,62 @@
/*
TessesFramework a library to make C++ easier for me, used in CrossLang:
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "VFS.hpp"
#include "VFSFix.hpp"
namespace Tesses::Framework::Filesystem
{
class LocalFilesystem : public VFS
{
public:
namespace Tesses::Framework::Filesystem {
class LocalFilesystem : public VFS {
public:
std::shared_ptr<Tesses::Framework::Streams::Stream>
OpenFile(VFSPath path, std::string mode);
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
void CreateDirectory(VFSPath path);
void DeleteDirectory(VFSPath path);
void CreateDirectory(VFSPath path);
void DeleteDirectory(VFSPath path);
void DeleteFile(VFSPath path);
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
VFSPathEnumerator EnumeratePaths(VFSPath path);
void CreateHardlink(VFSPath existingFile, VFSPath newName);
void MoveFile(VFSPath src, VFSPath dest);
void DeleteFile(VFSPath path);
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
VFSPathEnumerator EnumeratePaths(VFSPath path);
void CreateHardlink(VFSPath existingFile, VFSPath newName);
void MoveDirectory(VFSPath src, VFSPath dest);
VFSPath ReadLink(VFSPath path);
std::string VFSPathToSystem(VFSPath path);
VFSPath SystemToVFSPath(std::string path);
void MoveFile(VFSPath src, VFSPath dest);
void SetDate(VFSPath path, Date::DateTime lastWrite,
Date::DateTime lastAccess);
bool Stat(VFSPath path, StatData &stat);
bool StatVFS(VFSPath path, StatVFSData &vfsData);
void MoveDirectory(VFSPath src, VFSPath dest);
VFSPath ReadLink(VFSPath path);
std::string VFSPathToSystem(VFSPath path);
VFSPath SystemToVFSPath(std::string path);
void Chmod(VFSPath path, uint32_t mode);
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
bool Stat(VFSPath path, StatData& stat);
bool StatVFS(VFSPath path, StatVFSData& vfsData);
void Lock(VFSPath path);
void Unlock(VFSPath path);
void Chmod(VFSPath path, uint32_t mode);
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mod);
void Lock(VFSPath path);
void Unlock(VFSPath path);
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mod);
protected:
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs, VFSPath path);
};
extern std::shared_ptr<LocalFilesystem> LocalFS;
}
protected:
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs,
VFSPath path);
};
extern std::shared_ptr<LocalFilesystem> LocalFS;
} // namespace Tesses::Framework::Filesystem

View File

@@ -1,59 +1,75 @@
/*
TessesFramework a library to make C++ easier for me, used in CrossLang:
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "VFS.hpp"
#include "VFSFix.hpp"
namespace Tesses::Framework::Filesystem
{
class MountableDirectory {
public:
std::string name;
std::shared_ptr<VFS> vfs;
bool owns;
std::vector<MountableDirectory*> dirs;
void GetFS(VFSPath srcPath, VFSPath curDir, VFSPath& destRoot, VFSPath& destPath, std::shared_ptr<VFS>& vfs);
~MountableDirectory();
};
namespace Tesses::Framework::Filesystem {
class MountableDirectory {
public:
std::string name;
std::shared_ptr<VFS> vfs;
bool owns;
std::vector<MountableDirectory *> dirs;
void GetFS(VFSPath srcPath, VFSPath curDir, VFSPath &destRoot,
VFSPath &destPath, std::shared_ptr<VFS> &vfs);
~MountableDirectory();
};
class MountableFilesystem : public VFS
{
std::shared_ptr<VFS> root;
class MountableFilesystem : public VFS {
std::shared_ptr<VFS> root;
std::vector<MountableDirectory*> directories;
std::vector<MountableDirectory *> directories;
void GetFS(VFSPath srcPath, VFSPath& destRoot, VFSPath& destPath, std::shared_ptr<VFS>& vfs);
void GetFS(VFSPath srcPath, VFSPath &destRoot, VFSPath &destPath,
std::shared_ptr<VFS> &vfs);
public:
MountableFilesystem();
MountableFilesystem(std::shared_ptr<VFS> root);
void Mount(VFSPath path, std::shared_ptr<VFS> vfs);
void Unmount(VFSPath path);
std::shared_ptr<Tesses::Framework::Streams::Stream>
OpenFile(VFSPath path, std::string mode);
void CreateDirectory(VFSPath path);
void DeleteDirectory(VFSPath path);
bool Stat(VFSPath path, StatData &data);
void DeleteFile(VFSPath path);
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
VFSPathEnumerator EnumeratePaths(VFSPath path);
void CreateHardlink(VFSPath existingFile, VFSPath newName);
void MoveFile(VFSPath src, VFSPath dest);
void MoveDirectory(VFSPath src, VFSPath dest);
VFSPath ReadLink(VFSPath path);
std::string VFSPathToSystem(VFSPath path);
VFSPath SystemToVFSPath(std::string path);
~MountableFilesystem();
void SetDate(VFSPath path, Date::DateTime lastWrite,
Date::DateTime lastAccess);
public:
MountableFilesystem();
MountableFilesystem(std::shared_ptr<VFS> root);
void Mount(VFSPath path, std::shared_ptr<VFS> vfs);
void Unmount(VFSPath path);
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
void CreateDirectory(VFSPath path);
void DeleteDirectory(VFSPath path);
bool Stat(VFSPath path, StatData& data);
void DeleteFile(VFSPath path);
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
VFSPathEnumerator EnumeratePaths(VFSPath path);
void CreateHardlink(VFSPath existingFile, VFSPath newName);
void MoveFile(VFSPath src, VFSPath dest);
void MoveDirectory(VFSPath src, VFSPath dest);
VFSPath ReadLink(VFSPath path);
std::string VFSPathToSystem(VFSPath path);
VFSPath SystemToVFSPath(std::string path);
~MountableFilesystem();
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
bool StatVFS(VFSPath path, StatVFSData &vfsData);
bool StatVFS(VFSPath path, StatVFSData& vfsData);
void Chmod(VFSPath path, uint32_t mode);
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
void Chmod(VFSPath path, uint32_t mode);
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
void Lock(VFSPath path);
void Unlock(VFSPath path);
};
}
void Lock(VFSPath path);
void Unlock(VFSPath path);
};
} // namespace Tesses::Framework::Filesystem

View File

@@ -1,16 +1,33 @@
/*
TessesFramework a library to make C++ easier for me, used in CrossLang:
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "VFS.hpp"
#include "VFSFix.hpp"
namespace Tesses::Framework::Filesystem
{
class NullFilesystem : public VFS
{
public:
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
VFSPathEnumerator EnumeratePaths(VFSPath path);
bool Stat(VFSPath path, StatData& data);
std::string VFSPathToSystem(VFSPath path);
VFSPath SystemToVFSPath(std::string path);
};
}
namespace Tesses::Framework::Filesystem {
class NullFilesystem : public VFS {
public:
std::shared_ptr<Tesses::Framework::Streams::Stream>
OpenFile(VFSPath path, std::string mode);
VFSPathEnumerator EnumeratePaths(VFSPath path);
bool Stat(VFSPath path, StatData &data);
std::string VFSPathToSystem(VFSPath path);
VFSPath SystemToVFSPath(std::string path);
};
} // namespace Tesses::Framework::Filesystem

View File

@@ -1,54 +1,78 @@
/*
TessesFramework a library to make C++ easier for me, used in CrossLang:
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "VFS.hpp"
#include "VFSFix.hpp"
namespace Tesses::Framework::Filesystem
{
class RelativeFilesystem : public VFS {
Tesses::Framework::Threading::Mutex mtx;
VFSPath working;
std::shared_ptr<VFS> vfs;
private:
VFSPath ToParent(VFSPath path);
public:
RelativeFilesystem(std::shared_ptr<VFS> vfs, VFSPath working);
VFSPath GetWorking();
void SetWorking(VFSPath path);
std::shared_ptr<VFS> GetVFS();
namespace Tesses::Framework::Filesystem {
class RelativeFilesystem : public VFS {
Tesses::Framework::Threading::Mutex mtx;
VFSPath working;
std::shared_ptr<VFS> vfs;
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
void CreateDirectory(VFSPath path);
void DeleteDirectory(VFSPath path);
void DeleteFile(VFSPath path);
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
VFSPathEnumerator EnumeratePaths(VFSPath path);
void CreateHardlink(VFSPath existingFile, VFSPath newName);
void MoveFile(VFSPath src, VFSPath dest);
void MoveDirectory(VFSPath src, VFSPath dest);
void DeleteDirectoryRecurse(VFSPath path);
VFSPath ReadLink(VFSPath path);
std::string VFSPathToSystem(VFSPath path);
VFSPath SystemToVFSPath(std::string path);
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
bool StatVFS(VFSPath path, StatVFSData& vfsData);
bool Stat(VFSPath path, StatData& data);
private:
VFSPath ToParent(VFSPath path);
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
void Chmod(VFSPath path, uint32_t mode);
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
void Lock(VFSPath path);
void Unlock(VFSPath path);
protected:
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs, VFSPath path);
public:
RelativeFilesystem(std::shared_ptr<VFS> vfs, VFSPath working);
VFSPath GetWorking();
void SetWorking(VFSPath path);
std::shared_ptr<VFS> GetVFS();
std::shared_ptr<Tesses::Framework::Streams::Stream>
OpenFile(VFSPath path, std::string mode);
void CreateDirectory(VFSPath path);
void DeleteDirectory(VFSPath path);
void DeleteFile(VFSPath path);
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
VFSPathEnumerator EnumeratePaths(VFSPath path);
void CreateHardlink(VFSPath existingFile, VFSPath newName);
void MoveFile(VFSPath src, VFSPath dest);
void MoveDirectory(VFSPath src, VFSPath dest);
void DeleteDirectoryRecurse(VFSPath path);
VFSPath ReadLink(VFSPath path);
std::string VFSPathToSystem(VFSPath path);
VFSPath SystemToVFSPath(std::string path);
void SetDate(VFSPath path, Date::DateTime lastWrite,
Date::DateTime lastAccess);
bool StatVFS(VFSPath path, StatVFSData &vfsData);
bool Stat(VFSPath path, StatData &data);
class Watcher : public FSWatcher {
std::shared_ptr<FSWatcher> watcher;
protected:
void SetEnabledImpl(bool enabled);
public:
Watcher(std::shared_ptr<RelativeFilesystem> vfs, VFSPath path);
~Watcher();
};
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
void Chmod(VFSPath path, uint32_t mode);
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
void Lock(VFSPath path);
void Unlock(VFSPath path);
protected:
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs,
VFSPath path);
class Watcher : public FSWatcher {
std::shared_ptr<FSWatcher> watcher;
protected:
void SetEnabledImpl(bool enabled);
public:
Watcher(std::shared_ptr<RelativeFilesystem> vfs, VFSPath path);
~Watcher();
};
}
};
} // namespace Tesses::Framework::Filesystem

View File

@@ -1,53 +1,73 @@
/*
TessesFramework a library to make C++ easier for me, used in CrossLang:
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "VFS.hpp"
#include "VFSFix.hpp"
namespace Tesses::Framework::Filesystem
{
class SubdirFilesystem : public VFS
{
std::shared_ptr<VFS> parent;
VFSPath path;
VFSPath ToParent(VFSPath path);
VFSPath FromParent(VFSPath path);
public:
SubdirFilesystem(std::shared_ptr<VFS> parent, VFSPath path);
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
void CreateDirectory(VFSPath path);
void DeleteDirectory(VFSPath path);
void DeleteFile(VFSPath path);
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
VFSPathEnumerator EnumeratePaths(VFSPath path);
void CreateHardlink(VFSPath existingFile, VFSPath newName);
void MoveFile(VFSPath src, VFSPath dest);
void MoveDirectory(VFSPath src, VFSPath dest);
void DeleteDirectoryRecurse(VFSPath path);
VFSPath ReadLink(VFSPath path);
std::string VFSPathToSystem(VFSPath path);
VFSPath SystemToVFSPath(std::string path);
~SubdirFilesystem();
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
bool StatVFS(VFSPath path, StatVFSData& vfsData);
bool Stat(VFSPath path, StatData& data);
namespace Tesses::Framework::Filesystem {
class SubdirFilesystem : public VFS {
std::shared_ptr<VFS> parent;
VFSPath path;
VFSPath ToParent(VFSPath path);
VFSPath FromParent(VFSPath path);
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
void Chmod(VFSPath path, uint32_t mode);
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
void Lock(VFSPath path);
void Unlock(VFSPath path);
public:
SubdirFilesystem(std::shared_ptr<VFS> parent, VFSPath path);
std::shared_ptr<Tesses::Framework::Streams::Stream>
OpenFile(VFSPath path, std::string mode);
void CreateDirectory(VFSPath path);
void DeleteDirectory(VFSPath path);
void DeleteFile(VFSPath path);
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
VFSPathEnumerator EnumeratePaths(VFSPath path);
void CreateHardlink(VFSPath existingFile, VFSPath newName);
void MoveFile(VFSPath src, VFSPath dest);
void MoveDirectory(VFSPath src, VFSPath dest);
void DeleteDirectoryRecurse(VFSPath path);
VFSPath ReadLink(VFSPath path);
std::string VFSPathToSystem(VFSPath path);
VFSPath SystemToVFSPath(std::string path);
~SubdirFilesystem();
void SetDate(VFSPath path, Date::DateTime lastWrite,
Date::DateTime lastAccess);
bool StatVFS(VFSPath path, StatVFSData &vfsData);
bool Stat(VFSPath path, StatData &data);
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
void Chmod(VFSPath path, uint32_t mode);
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
void Lock(VFSPath path);
void Unlock(VFSPath path);
protected:
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs, VFSPath path);
protected:
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs,
VFSPath path);
class Watcher : public FSWatcher {
std::shared_ptr<FSWatcher> watcher;
class Watcher : public FSWatcher {
std::shared_ptr<FSWatcher> watcher;
protected:
void SetEnabledImpl(bool enabled);
public:
Watcher(std::shared_ptr<SubdirFilesystem> vfs, VFSPath path);
~Watcher();
};
protected:
void SetEnabledImpl(bool enabled);
public:
Watcher(std::shared_ptr<SubdirFilesystem> vfs, VFSPath path);
~Watcher();
};
}
};
} // namespace Tesses::Framework::Filesystem

View File

@@ -1,52 +1,71 @@
/*
TessesFramework a library to make C++ easier for me, used in CrossLang:
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "../Common.hpp"
#include "VFS.hpp"
#include "VFSFix.hpp"
namespace Tesses::Framework::Filesystem
{
void UniqueString(std::string& text);
namespace Tesses::Framework::Filesystem {
void UniqueString(std::string &text);
class TempFS : public VFS
{
std::shared_ptr<VFS> vfs;
bool deleteOnDestroy;
std::shared_ptr<VFS> parent;
std::string tmp_str;
public:
std::string TempDirectoryName();
TempFS(bool deleteOnDestroy=true);
TempFS(std::shared_ptr<VFS> vfs,bool deleteOnDestroy=true);
class TempFS : public VFS {
std::shared_ptr<VFS> vfs;
bool deleteOnDestroy;
std::shared_ptr<VFS> parent;
std::string tmp_str;
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
void CreateDirectory(VFSPath path);
void DeleteDirectory(VFSPath path);
void DeleteFile(VFSPath path);
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
VFSPathEnumerator EnumeratePaths(VFSPath path);
void CreateHardlink(VFSPath existingFile, VFSPath newName);
void MoveFile(VFSPath src, VFSPath dest);
void MoveDirectory(VFSPath src, VFSPath dest);
void DeleteDirectoryRecurse(VFSPath path);
VFSPath ReadLink(VFSPath path);
std::string VFSPathToSystem(VFSPath path);
VFSPath SystemToVFSPath(std::string path);
public:
std::string TempDirectoryName();
TempFS(bool deleteOnDestroy = true);
TempFS(std::shared_ptr<VFS> vfs, bool deleteOnDestroy = true);
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
bool StatVFS(VFSPath path, StatVFSData& vfsData);
bool Stat(VFSPath path, StatData& data);
std::shared_ptr<Tesses::Framework::Streams::Stream>
OpenFile(VFSPath path, std::string mode);
void CreateDirectory(VFSPath path);
void DeleteDirectory(VFSPath path);
void DeleteFile(VFSPath path);
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
VFSPathEnumerator EnumeratePaths(VFSPath path);
void CreateHardlink(VFSPath existingFile, VFSPath newName);
void MoveFile(VFSPath src, VFSPath dest);
void MoveDirectory(VFSPath src, VFSPath dest);
void DeleteDirectoryRecurse(VFSPath path);
VFSPath ReadLink(VFSPath path);
std::string VFSPathToSystem(VFSPath path);
VFSPath SystemToVFSPath(std::string path);
void Chmod(VFSPath path, uint32_t mode);
void SetDate(VFSPath path, Date::DateTime lastWrite,
Date::DateTime lastAccess);
bool StatVFS(VFSPath path, StatVFSData &vfsData);
bool Stat(VFSPath path, StatData &data);
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
void Close();
void Chmod(VFSPath path, uint32_t mode);
void Lock(VFSPath path);
void Unlock(VFSPath path);
~TempFS();
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
void Close();
protected:
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs, VFSPath path);
void Lock(VFSPath path);
void Unlock(VFSPath path);
~TempFS();
};
}
protected:
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs,
VFSPath path);
};
} // namespace Tesses::Framework::Filesystem

View File

@@ -1,343 +1,336 @@
/*
TessesFramework a library to make C++ easier for me, used in CrossLang:
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "../Common.hpp"
#include "../Date/Date.hpp"
#include "../Streams/Stream.hpp"
#include "VFSFix.hpp"
#include <TessesFramework/Common.hpp>
#include <TessesFramework/Date/Date.hpp>
#include <functional>
#include <memory>
#include "../Date/Date.hpp"
#include "VFSFix.hpp"
namespace Tesses::Framework::Filesystem
{
namespace Tesses::Framework::Filesystem {
struct StatVFSData {
struct StatVFSData {
uint64_t BlockSize;
uint64_t FragmentSize;
uint64_t Blocks;
uint64_t BlocksFree;
uint64_t BlocksAvailable;
uint64_t TotalInodes;
uint64_t FreeInodes;
uint64_t AvailableInodes;
uint64_t Id;
uint64_t Flags;
uint64_t MaxNameLength;
};
uint64_t BlockSize;
uint64_t FragmentSize;
uint64_t Blocks;
uint64_t BlocksFree;
uint64_t BlocksAvailable;
uint64_t TotalInodes;
uint64_t FreeInodes;
uint64_t AvailableInodes;
uint64_t Id;
uint64_t Flags;
uint64_t MaxNameLength;
};
constexpr uint32_t MODE_USER_READ = 0400;
constexpr uint32_t MODE_USER_WRITE = 0200;
constexpr uint32_t MODE_USER_EXEC = 0100;
constexpr uint32_t MODE_USER_READ = 0400;
constexpr uint32_t MODE_USER_WRITE = 0200;
constexpr uint32_t MODE_USER_EXEC = 0100;
constexpr uint32_t MODE_GROUP_READ = (MODE_USER_READ >> 3);
constexpr uint32_t MODE_GROUP_WRITE = (MODE_USER_WRITE >> 3);
constexpr uint32_t MODE_GROUP_EXEC = (MODE_USER_EXEC >> 3);
constexpr uint32_t MODE_GROUP_READ = (MODE_USER_READ >> 3);
constexpr uint32_t MODE_GROUP_WRITE = (MODE_USER_WRITE >> 3);
constexpr uint32_t MODE_GROUP_EXEC = (MODE_USER_EXEC >> 3);
constexpr uint32_t MODE_OTHER_READ = (MODE_GROUP_READ >> 3);
constexpr uint32_t MODE_OTHER_WRITE = (MODE_GROUP_WRITE >> 3);
constexpr uint32_t MODE_OTHER_EXEC = (MODE_GROUP_EXEC >> 3);
constexpr uint32_t MODE_OTHER_READ = (MODE_GROUP_READ >> 3);
constexpr uint32_t MODE_OTHER_WRITE = (MODE_GROUP_WRITE >> 3);
constexpr uint32_t MODE_OTHER_EXEC = (MODE_GROUP_EXEC >> 3);
constexpr uint32_t MODE_REGULAR = 0100000;
constexpr uint32_t MODE_DIRECTORY = 0040000;
constexpr uint32_t MODE_CHAR_DEVICE = 0020000;
constexpr uint32_t MODE_BLOCK_DEVICE = 0060000;
constexpr uint32_t MODE_SOCKET = 0140000;
constexpr uint32_t MODE_FIFO = 0010000;
constexpr uint32_t MODE_SYMLINK = 0120000;
constexpr uint32_t MODE_REGULAR = 0100000;
constexpr uint32_t MODE_DIRECTORY = 0040000;
constexpr uint32_t MODE_CHAR_DEVICE = 0020000;
constexpr uint32_t MODE_BLOCK_DEVICE = 0060000;
constexpr uint32_t MODE_SOCKET = 0140000;
constexpr uint32_t MODE_FIFO = 0010000;
constexpr uint32_t MODE_SYMLINK = 0120000;
struct StatData {
uint64_t Device;
uint64_t Inode;
uint32_t Mode;
uint64_t HardLinks;
uint32_t UserId;
uint32_t GroupId;
uint64_t DeviceId;
uint64_t Size;
uint64_t BlockSize;
uint64_t BlockCount;
Date::DateTime LastAccess;
Date::DateTime LastModified;
Date::DateTime LastStatus;
struct StatData {
uint64_t Device;
uint64_t Inode;
uint32_t Mode;
uint64_t HardLinks;
uint32_t UserId;
uint32_t GroupId;
uint64_t DeviceId;
uint64_t Size;
uint64_t BlockSize;
uint64_t BlockCount;
Date::DateTime LastAccess;
Date::DateTime LastModified;
Date::DateTime LastStatus;
bool IsRegularFile() { return (Mode & MODE_REGULAR) > 0; }
bool IsDirectory() { return (Mode & MODE_DIRECTORY) > 0; }
bool IsRegularFile()
{
return (Mode & MODE_REGULAR) > 0;
}
bool IsDirectory()
{
return (Mode & MODE_DIRECTORY) > 0;
}
bool IsCharDevice() { return (Mode & MODE_CHAR_DEVICE) > 0; }
bool IsCharDevice()
{
return (Mode & MODE_CHAR_DEVICE) > 0;
}
bool IsBlockDevice() { return (Mode & MODE_BLOCK_DEVICE) > 0; }
bool IsBlockDevice()
{
return (Mode & MODE_BLOCK_DEVICE) > 0;
}
bool IsSocket() { return (Mode & MODE_SOCKET) > 0; }
bool IsFIFO() { return (Mode & MODE_FIFO) > 0; }
bool IsSocket()
{
return (Mode & MODE_SOCKET) > 0;
}
bool IsFIFO()
{
return (Mode & MODE_FIFO) > 0;
}
bool IsSymlink() { return (Mode & MODE_SYMLINK) > 0; }
bool IsSymlink()
{
return (Mode & MODE_SYMLINK) > 0;
}
bool IsSpecial()
{
if(IsRegularFile()) return false;
if(IsDirectory()) return false;
return true;
}
std::string ToSizeString(bool usesBin=true)
{
return TF_FileSize(this->Size, usesBin);
}
};
class VFSPath {
public:
static VFSPath CurrentDirectoryAsRelative();
bool relative;
static std::vector<std::string> SplitPath(std::string path);
std::vector<std::string> path;
VFSPath();
explicit VFSPath(const char* path) : VFSPath(std::string(path))
{}
VFSPath(std::vector<std::string> path);
VFSPath(std::string path);
VFSPath(VFSPath p, std::string subent);
VFSPath(VFSPath p, VFSPath p2);
//does not check for ?
static VFSPath ParseUriPath(std::string path);
VFSPath GetParent() const;
VFSPath CollapseRelativeParents() const;
std::string GetFileName() const;
bool HasExtension() const;
std::string GetExtension() const;
void ChangeExtension(std::string ext);
void RemoveExtension();
std::string ToString() const;
static VFSPath GetAbsoluteCurrentDirectory();
static void SetAbsoluteCurrentDirectory(VFSPath path);
VFSPath MakeAbsolute() const;
VFSPath MakeAbsolute(VFSPath curDir) const;
VFSPath MakeRelative() const;
VFSPath MakeRelative(VFSPath toMakeRelativeTo) const;
};
VFSPath operator/(VFSPath p, VFSPath p2);
VFSPath operator/(VFSPath p, std::string p2);
VFSPath operator/(std::string p, VFSPath p2);
VFSPath operator+(VFSPath p, VFSPath p2);
VFSPath operator+(VFSPath p, std::string p2);
VFSPath operator+(std::string p, VFSPath p2);
bool operator==(VFSPath p,VFSPath p2);
bool operator!=(VFSPath p,VFSPath p2);
bool operator==(std::string p,VFSPath p2);
bool operator!=(std::string p,VFSPath p2);
bool operator==(VFSPath p,std::string p2);
bool operator!=(VFSPath p,std::string p2);
class VFSPathEnumeratorData {
public:
VFSPathEnumeratorData(std::function<bool(VFSPath&)> moveNext, std::function<void()> destroy)
{
this->eof=false;
this->moveNext=moveNext;
this->destroy=destroy;
}
bool eof;
std::function<bool(VFSPath&)> moveNext;
std::function<void()> destroy;
~VFSPathEnumeratorData()
{
this->destroy();
}
};
class VFSPathEnumerator;
class VFSPathEnumeratorItterator
{
VFSPath e;
VFSPathEnumerator* enumerator;
public:
VFSPathEnumeratorItterator();
VFSPathEnumeratorItterator(VFSPathEnumerator* enumerator);
VFSPathEnumeratorItterator& operator++();
VFSPathEnumeratorItterator& operator++(int);
VFSPath& operator*();
VFSPath* operator->();
bool operator!=(VFSPathEnumeratorItterator right);
bool operator==(VFSPathEnumeratorItterator right);
};
class VFSPathEnumerator {
std::shared_ptr<VFSPathEnumeratorData> data;
public:
VFSPathEnumerator();
VFSPathEnumerator* MakePointer();
VFSPathEnumerator(std::function<bool(VFSPath&)> moveNext, std::function<void()> destroy);
VFSPath Current;
bool MoveNext();
bool IsDone();
VFSPathEnumeratorItterator begin();
VFSPathEnumeratorItterator end();
};
enum class FSWatcherEventType {
None = 0,
//IN_ACCESS
Accessed=1,
//IN_ATTRIB
AttributeChanged =2,
//IN_CLOSE_WRITE
Writen = 4,
//IN_CLOSE_NOWRITE
Read = 8,
//IN_CREATE
Created = 16,
//IN_DELETE
Deleted = 32,
//IN_DELETE_SELF
WatchEntryDeleted = 64,
//IN_MODIFY
Modified = 128,
//IN_MOVE_SELF
WatchEntryMoved = 256,
//IN_MOVED_FROM
MoveOld = 512,
//IN_MOVED_TO
MoveNew = 1024,
//IN_OPEN
Opened = 2048,
//IN_CLOSE
Closed = Writen | Read,
//IN_MOVE
Moved = MoveOld | MoveNew,
//IN_ALL_EVENTS
All = Accessed | AttributeChanged | Created | Deleted | WatchEntryDeleted | Modified | WatchEntryMoved | Opened | Closed | Moved
};
struct FSWatcherEvent {
//the file or source on move
VFSPath src;
//the dest when moving
VFSPath dest;
FSWatcherEventType type;
bool isDir;
bool IsEvent(FSWatcherEventType e);
std::string ToString();
};
class VFS;
class FSWatcher {
private:
std::shared_ptr<VFS> vfs;
VFSPath path;
protected:
std::atomic<bool> enabled=false;
virtual void SetEnabledImpl(bool enabled);
public:
FSWatcher(std::shared_ptr<VFS> vfs, VFSPath path);
std::function<void(FSWatcherEvent&)> event;
FSWatcherEventType events = FSWatcherEventType::All;
bool GetEnabled();
void SetEnabled(bool val);
std::shared_ptr<VFS> GetFilesystem();
const VFSPath& GetPath();
virtual ~FSWatcher() = default;
static std::shared_ptr<FSWatcher> Create(std::shared_ptr<VFS> vfs, VFSPath path);
};
enum class FIFOCreationResult {
Success=0,
Exists = 1,
ReadOnlyFS = 2,
Denied = 3,
OutOfInodes = 4,
UnknownError = 5,
Unsupported = 255
};
class VFS {
public:
virtual std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode)=0;
virtual void CreateDirectory(VFSPath path);
virtual void DeleteDirectory(VFSPath path);
bool DirectoryExists(VFSPath path);
bool RegularFileExists(VFSPath path);
bool SymlinkExists(VFSPath path);
bool CharacterDeviceExists(VFSPath path);
bool BlockDeviceExists(VFSPath path);
bool SocketFileExists(VFSPath path);
bool FIFOFileExists(VFSPath path);
bool FileExists(VFSPath path);
bool SpecialFileExists(VFSPath path);
virtual void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
virtual void CreateHardlink(VFSPath existingFile, VFSPath newName);
virtual void DeleteFile(VFSPath path);
virtual void DeleteDirectoryRecurse(VFSPath path);
virtual VFSPathEnumerator EnumeratePaths(VFSPath path) = 0;
virtual void MoveFile(VFSPath src, VFSPath dest);
virtual void MoveDirectory(VFSPath src, VFSPath dest);
virtual VFSPath ReadLink(VFSPath path);
virtual std::string VFSPathToSystem(VFSPath path)=0;
virtual VFSPath SystemToVFSPath(std::string path)=0;
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
virtual void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
virtual bool Stat(VFSPath path, StatData& data) = 0;
virtual bool StatVFS(VFSPath path, StatVFSData& data);
virtual void Chmod(VFSPath path, uint32_t mode);
virtual void Chown(VFSPath path, uint32_t userId, uint32_t groupId);
virtual void Lock(VFSPath path);
virtual void Unlock(VFSPath path);
virtual FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
virtual ~VFS();
virtual void Close();
protected:
virtual std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs, VFSPath path);
friend class FSWatcher;
};
namespace Literals
{
inline VFSPath operator""_tpath(const char* path)
{
return VFSPath(path);
}
bool IsSpecial() {
if (IsRegularFile())
return false;
if (IsDirectory())
return false;
return true;
}
}
std::string ToSizeString(bool usesBin = true) {
return TF_FileSize(this->Size, usesBin);
}
};
class VFSPath {
public:
static VFSPath CurrentDirectoryAsRelative();
bool relative;
static std::vector<std::string> SplitPath(std::string path);
std::vector<std::string> path;
VFSPath();
explicit VFSPath(const char *path) : VFSPath(std::string(path)) {}
VFSPath(std::vector<std::string> path);
VFSPath(std::string path);
VFSPath(VFSPath p, std::string subent);
VFSPath(VFSPath p, VFSPath p2);
// does not check for ?
static VFSPath ParseUriPath(std::string path);
VFSPath GetParent() const;
VFSPath CollapseRelativeParents() const;
std::string GetFileName() const;
bool HasExtension() const;
std::string GetExtension() const;
void ChangeExtension(std::string ext);
void RemoveExtension();
std::string ToString() const;
static VFSPath GetAbsoluteCurrentDirectory();
static void SetAbsoluteCurrentDirectory(VFSPath path);
VFSPath MakeAbsolute() const;
VFSPath MakeAbsolute(VFSPath curDir) const;
VFSPath MakeRelative() const;
VFSPath MakeRelative(VFSPath toMakeRelativeTo) const;
};
VFSPath operator/(VFSPath p, VFSPath p2);
VFSPath operator/(VFSPath p, std::string p2);
VFSPath operator/(std::string p, VFSPath p2);
VFSPath operator+(VFSPath p, VFSPath p2);
VFSPath operator+(VFSPath p, std::string p2);
VFSPath operator+(std::string p, VFSPath p2);
bool operator==(VFSPath p, VFSPath p2);
bool operator!=(VFSPath p, VFSPath p2);
bool operator==(std::string p, VFSPath p2);
bool operator!=(std::string p, VFSPath p2);
bool operator==(VFSPath p, std::string p2);
bool operator!=(VFSPath p, std::string p2);
class VFSPathEnumeratorData {
public:
VFSPathEnumeratorData(std::function<bool(VFSPath &)> moveNext,
std::function<void()> destroy) {
this->eof = false;
this->moveNext = moveNext;
this->destroy = destroy;
}
bool eof;
std::function<bool(VFSPath &)> moveNext;
std::function<void()> destroy;
~VFSPathEnumeratorData() { this->destroy(); }
};
class VFSPathEnumerator;
class VFSPathEnumeratorItterator {
VFSPath e;
VFSPathEnumerator *enumerator;
public:
VFSPathEnumeratorItterator();
VFSPathEnumeratorItterator(VFSPathEnumerator *enumerator);
VFSPathEnumeratorItterator &operator++();
VFSPathEnumeratorItterator &operator++(int);
VFSPath &operator*();
VFSPath *operator->();
bool operator!=(VFSPathEnumeratorItterator right);
bool operator==(VFSPathEnumeratorItterator right);
};
class VFSPathEnumerator {
std::shared_ptr<VFSPathEnumeratorData> data;
public:
VFSPathEnumerator();
VFSPathEnumerator *MakePointer();
VFSPathEnumerator(std::function<bool(VFSPath &)> moveNext,
std::function<void()> destroy);
VFSPath Current;
bool MoveNext();
bool IsDone();
VFSPathEnumeratorItterator begin();
VFSPathEnumeratorItterator end();
};
enum class FSWatcherEventType {
None = 0,
// IN_ACCESS
Accessed = 1,
// IN_ATTRIB
AttributeChanged = 2,
// IN_CLOSE_WRITE
Writen = 4,
// IN_CLOSE_NOWRITE
Read = 8,
// IN_CREATE
Created = 16,
// IN_DELETE
Deleted = 32,
// IN_DELETE_SELF
WatchEntryDeleted = 64,
// IN_MODIFY
Modified = 128,
// IN_MOVE_SELF
WatchEntryMoved = 256,
// IN_MOVED_FROM
MoveOld = 512,
// IN_MOVED_TO
MoveNew = 1024,
// IN_OPEN
Opened = 2048,
// IN_CLOSE
Closed = Writen | Read,
// IN_MOVE
Moved = MoveOld | MoveNew,
// IN_ALL_EVENTS
All = Accessed | AttributeChanged | Created | Deleted | WatchEntryDeleted |
Modified | WatchEntryMoved | Opened | Closed | Moved
};
struct FSWatcherEvent {
// the file or source on move
VFSPath src;
// the dest when moving
VFSPath dest;
FSWatcherEventType type;
bool isDir;
bool IsEvent(FSWatcherEventType e);
std::string ToString();
};
class VFS;
class FSWatcher {
private:
std::shared_ptr<VFS> vfs;
VFSPath path;
protected:
std::atomic<bool> enabled = false;
virtual void SetEnabledImpl(bool enabled);
public:
FSWatcher(std::shared_ptr<VFS> vfs, VFSPath path);
std::function<void(FSWatcherEvent &)> event;
FSWatcherEventType events = FSWatcherEventType::All;
bool GetEnabled();
void SetEnabled(bool val);
std::shared_ptr<VFS> GetFilesystem();
const VFSPath &GetPath();
virtual ~FSWatcher() = default;
static std::shared_ptr<FSWatcher> Create(std::shared_ptr<VFS> vfs,
VFSPath path);
};
enum class FIFOCreationResult {
Success = 0,
Exists = 1,
ReadOnlyFS = 2,
Denied = 3,
OutOfInodes = 4,
UnknownError = 5,
Unsupported = 255
};
class VFS {
public:
virtual std::shared_ptr<Tesses::Framework::Streams::Stream>
OpenFile(VFSPath path, std::string mode) = 0;
virtual void CreateDirectory(VFSPath path);
virtual void DeleteDirectory(VFSPath path);
bool DirectoryExists(VFSPath path);
bool RegularFileExists(VFSPath path);
bool SymlinkExists(VFSPath path);
bool CharacterDeviceExists(VFSPath path);
bool BlockDeviceExists(VFSPath path);
bool SocketFileExists(VFSPath path);
bool FIFOFileExists(VFSPath path);
bool FileExists(VFSPath path);
bool SpecialFileExists(VFSPath path);
virtual void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
virtual void CreateHardlink(VFSPath existingFile, VFSPath newName);
virtual void DeleteFile(VFSPath path);
virtual void DeleteDirectoryRecurse(VFSPath path);
virtual VFSPathEnumerator EnumeratePaths(VFSPath path) = 0;
virtual void MoveFile(VFSPath src, VFSPath dest);
virtual void MoveDirectory(VFSPath src, VFSPath dest);
virtual VFSPath ReadLink(VFSPath path);
virtual std::string VFSPathToSystem(VFSPath path) = 0;
virtual VFSPath SystemToVFSPath(std::string path) = 0;
void GetDate(VFSPath path, Date::DateTime &lastWrite,
Date::DateTime &lastAccess);
virtual void SetDate(VFSPath path, Date::DateTime lastWrite,
Date::DateTime lastAccess);
virtual bool Stat(VFSPath path, StatData &data) = 0;
virtual bool StatVFS(VFSPath path, StatVFSData &data);
virtual void Chmod(VFSPath path, uint32_t mode);
virtual void Chown(VFSPath path, uint32_t userId, uint32_t groupId);
virtual void Lock(VFSPath path);
virtual void Unlock(VFSPath path);
virtual FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
virtual ~VFS();
virtual void Close();
protected:
virtual std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs,
VFSPath path);
friend class FSWatcher;
};
namespace Literals {
inline VFSPath operator""_tpath(const char *path) { return VFSPath(path); }
} // namespace Literals
} // namespace Tesses::Framework::Filesystem

View File

@@ -1,3 +1,21 @@
/*
TessesFramework a library to make C++ easier for me, used in CrossLang:
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#undef CreateDirectory
#undef DeleteDirectory
#undef DeleteFile