Using PathView to pass paths to APIs #2
@@ -64,8 +64,8 @@ public:
|
||||
|
||||
GetStatResult getStat(AbsPathView path) const override;
|
||||
|
||||
cppcoro::generator<EnumerateEntry> enumerate(AbsPathView path) const override;
|
||||
cppcoro::generator<EnumerateEntry> enumerateRecursively(AbsPathView path) const override;
|
||||
cppcoro::generator<EnumerateEntry> enumerate(AbsPath path) const override;
|
||||
cppcoro::generator<EnumerateEntry> enumerateRecursively(AbsPath path) const override;
|
||||
|
||||
private:
|
||||
struct PackData
|
||||
|
||||
@@ -25,8 +25,8 @@ public:
|
||||
|
||||
GetStatResult getStat(AbsPathView path) const override;
|
||||
|
||||
cppcoro::generator<EnumerateEntry> enumerate(AbsPathView path) const override;
|
||||
cppcoro::generator<EnumerateEntry> enumerateRecursively(AbsPathView path) const override;
|
||||
cppcoro::generator<EnumerateEntry> enumerate(AbsPath path) const override;
|
||||
cppcoro::generator<EnumerateEntry> enumerateRecursively(AbsPath path) const override;
|
||||
|
||||
ConvertToNativePathResult convertToNativePath(AbsPathView path) const override;
|
||||
|
||||
|
||||
@@ -117,8 +117,12 @@ public:
|
||||
|
||||
virtual SetWriteTimeResult setWriteTime(AbsPathView path, time_t time) = 0;
|
||||
|
||||
virtual cppcoro::generator<EnumerateEntry> enumerate(AbsPathView path) const = 0;
|
||||
virtual cppcoro::generator<EnumerateEntry> enumerateRecursively(AbsPathView path) const = 0;
|
||||
//The AbsPath is a copy, because there are lifetime subtleties when using coroutines.
|
||||
//In particular, without pass-by-value, this would crash because nobody is storing the rvalue:
|
||||
// for (auto e: fs.enumerate(path + "other folder"))
|
||||
// {}
|
||||
virtual cppcoro::generator<EnumerateEntry> enumerate(AbsPath path) const = 0;
|
||||
virtual cppcoro::generator<EnumerateEntry> enumerateRecursively(AbsPath path) const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -33,8 +33,8 @@ public:
|
||||
|
||||
virtual GetStatResult getStat(AbsPathView i_path) const = 0;
|
||||
|
||||
virtual cppcoro::generator<EnumerateEntry> enumerate(AbsPathView i_path) const = 0;
|
||||
virtual cppcoro::generator<EnumerateEntry> enumerateRecursively(AbsPathView i_path) const = 0;
|
||||
virtual cppcoro::generator<EnumerateEntry> enumerate(AbsPath i_path) const = 0;
|
||||
virtual cppcoro::generator<EnumerateEntry> enumerateRecursively(AbsPath i_path) const = 0;
|
||||
|
||||
virtual ConvertToNativePathResult convertToNativePath(AbsPathView i_path) const = 0;
|
||||
|
||||
|
||||
@@ -50,8 +50,8 @@ public:
|
||||
|
||||
GetStatResult getStat(AbsPathView path) const override;
|
||||
|
||||
cppcoro::generator<EnumerateEntry> enumerate(AbsPathView path) const override;
|
||||
cppcoro::generator<EnumerateEntry> enumerateRecursively(AbsPathView path) const override;
|
||||
cppcoro::generator<EnumerateEntry> enumerate(AbsPath path) const override;
|
||||
cppcoro::generator<EnumerateEntry> enumerateRecursively(AbsPath path) const override;
|
||||
|
||||
AbsPath getCurrentFolder() const;
|
||||
tl::result<Error> setCurrentFolder(AbsPathView path);
|
||||
|
||||
@@ -37,8 +37,8 @@ public:
|
||||
|
||||
GetStatResult getStat(AbsPathView path) const override;
|
||||
|
||||
cppcoro::generator<EnumerateEntry> enumerate(AbsPathView path) const override;
|
||||
cppcoro::generator<EnumerateEntry> enumerateRecursively(AbsPathView path) const override;
|
||||
cppcoro::generator<EnumerateEntry> enumerate(AbsPath path) const override;
|
||||
cppcoro::generator<EnumerateEntry> enumerateRecursively(AbsPath path) const override;
|
||||
|
||||
tl::result<AbsPath, Error> convertToNativePath(AbsPathView path) const override;
|
||||
|
||||
|
||||
@@ -499,7 +499,7 @@ GetStatResult CustomFilesystem::getStat(AbsPathView path) const
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cppcoro::generator<EnumerateEntry> CustomFilesystem::enumerate(AbsPathView path) const
|
||||
cppcoro::generator<EnumerateEntry> CustomFilesystem::enumerate(AbsPath path) const
|
||||
{
|
||||
AbsPath basePackPath;
|
||||
for (const auto& pd : m_packsData)
|
||||
@@ -521,19 +521,16 @@ cppcoro::generator<EnumerateEntry> CustomFilesystem::enumerate(AbsPathView path)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cppcoro::generator<EnumerateEntry> CustomFilesystem::enumerateRecursively(AbsPathView path) const
|
||||
cppcoro::generator<EnumerateEntry> CustomFilesystem::enumerateRecursively(AbsPath path) const
|
||||
{
|
||||
tl::unordered_set<RelPath> checkedFiles;
|
||||
|
||||
const AbsPath rootPath(path);
|
||||
//Note, the path might not survive after the first co_yield, if it came from a rvalue, in some conditions, so use the rootPath
|
||||
|
||||
AbsPath basePackPath;
|
||||
for (const auto& pd : m_packsData)
|
||||
{
|
||||
if (pd.mountPoint.is_prefix_of(rootPath))
|
||||
if (pd.mountPoint.is_prefix_of(path))
|
||||
{
|
||||
convertToPackPath(basePackPath, rootPath, pd.mountPoint);
|
||||
convertToPackPath(basePackPath, path, pd.mountPoint);
|
||||
|
||||
if (!basePackPath.empty())
|
||||
{
|
||||
@@ -548,9 +545,9 @@ cppcoro::generator<EnumerateEntry> CustomFilesystem::enumerateRecursively(AbsPat
|
||||
co_yield std::move(ee);
|
||||
}
|
||||
}
|
||||
else if (rootPath.is_prefix_of(pd.mountPoint))
|
||||
else if (path.is_prefix_of(pd.mountPoint))
|
||||
{
|
||||
const RelPathView parentPath = rootPath.path_to(pd.mountPoint);
|
||||
const RelPathView parentPath = path.path_to(pd.mountPoint);
|
||||
|
||||
RelPath p = parentPath;
|
||||
for (EnumerateEntry ee : pd.pack->enumerateRecursively(AbsPath(PosixRootTag::value())))
|
||||
|
||||
+2
-2
@@ -78,7 +78,7 @@ GetStatResult FolderPack::getStat(AbsPathView path) const
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cppcoro::generator<EnumerateEntry> FolderPack::enumerate(AbsPathView path) const
|
||||
cppcoro::generator<EnumerateEntry> FolderPack::enumerate(AbsPath path) const
|
||||
{
|
||||
const AbsPath localPath = convertToUnderlyingPath(path);
|
||||
for (EnumerateEntry ee : m_filesystem->enumerate(localPath))
|
||||
@@ -87,7 +87,7 @@ cppcoro::generator<EnumerateEntry> FolderPack::enumerate(AbsPathView path) const
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cppcoro::generator<EnumerateEntry> FolderPack::enumerateRecursively(AbsPathView path) const
|
||||
cppcoro::generator<EnumerateEntry> FolderPack::enumerateRecursively(AbsPath path) const
|
||||
{
|
||||
const AbsPath localPath = convertToUnderlyingPath(path);
|
||||
for (EnumerateEntry ee : m_filesystem->enumerateRecursively(localPath))
|
||||
|
||||
@@ -522,7 +522,7 @@ GetStatResult NativeFilesystem::getStat(AbsPathView path) const
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cppcoro::generator<EnumerateEntry> NativeFilesystem::enumerate(AbsPathView path) const
|
||||
cppcoro::generator<EnumerateEntry> NativeFilesystem::enumerate(AbsPath path) const
|
||||
{
|
||||
TL_ASSERT(path.is_valid());
|
||||
|
||||
@@ -536,8 +536,6 @@ cppcoro::generator<EnumerateEntry> NativeFilesystem::enumerate(AbsPathView path)
|
||||
co_return;
|
||||
}
|
||||
|
||||
//Note, the path might not survive after the first co_yield, if it came from a rvalue, in some conditions, so if you need it below, make a copy in a AbsPath
|
||||
|
||||
for (auto const& entry : std::filesystem::directory_iterator{ toStdPath(path) })
|
||||
{
|
||||
const auto status = entry.status();
|
||||
@@ -557,7 +555,7 @@ cppcoro::generator<EnumerateEntry> NativeFilesystem::enumerate(AbsPathView path)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cppcoro::generator<EnumerateEntry> NativeFilesystem::enumerateRecursively(AbsPathView path) const
|
||||
cppcoro::generator<EnumerateEntry> NativeFilesystem::enumerateRecursively(AbsPath path) const
|
||||
{
|
||||
TL_ASSERT(path.is_valid());
|
||||
|
||||
@@ -571,12 +569,9 @@ cppcoro::generator<EnumerateEntry> NativeFilesystem::enumerateRecursively(AbsPat
|
||||
co_return;
|
||||
}
|
||||
|
||||
const AbsPath rootPath(path);
|
||||
AbsPath eePath;
|
||||
const auto stdRootPath = toStdPath(path);
|
||||
|
||||
//Note, the path might not survive after the first co_yield, if it came from a rvalue, in some conditions, so use the rootPath
|
||||
|
||||
for (auto const& entry : std::filesystem::recursive_directory_iterator{ stdRootPath })
|
||||
{
|
||||
const auto status = entry.status();
|
||||
@@ -584,12 +579,12 @@ cppcoro::generator<EnumerateEntry> NativeFilesystem::enumerateRecursively(AbsPat
|
||||
if (type == std::filesystem::file_type::directory)
|
||||
{
|
||||
toFSAbsPath(eePath, entry.path());
|
||||
co_yield{ rootPath.path_to(eePath), true };
|
||||
co_yield{ path.path_to(eePath), true };
|
||||
}
|
||||
else if (type == std::filesystem::file_type::regular)
|
||||
{
|
||||
toFSAbsPath(eePath, entry.path());
|
||||
co_yield{ rootPath.path_to(eePath), false };
|
||||
co_yield{ path.path_to(eePath), false };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -441,7 +441,7 @@ GetStatResult ZipPack::getStat(AbsPathView path) const
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cppcoro::generator<EnumerateEntry> ZipPack::enumerate(AbsPathView path) const
|
||||
cppcoro::generator<EnumerateEntry> ZipPack::enumerate(AbsPath path) const
|
||||
{
|
||||
TL_ASSERT(path.is_valid());
|
||||
|
||||
@@ -508,7 +508,7 @@ void ZipPack::buildUpPath(RelPath& path, const File& file, uint32_t toIndex) con
|
||||
}
|
||||
|
||||
|
||||
cppcoro::generator<EnumerateEntry> ZipPack::enumerateRecursively(AbsPathView path) const
|
||||
cppcoro::generator<EnumerateEntry> ZipPack::enumerateRecursively(AbsPath path) const
|
||||
{
|
||||
TL_ASSERT(path.is_valid());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user