Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions editor/src/filesystem/filetree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,41 @@
#include <tempeh/common/typedefs.hpp>
#include <cassert>
#include <system_error>
#include <list>

namespace TempehEditor::FileSystem {

FileTree::FileTree(std::string& path_str)
namespace fs = std::filesystem;

FileTree::FileTree(const fs::path &path_str)
{
std::filesystem::path path(path_str);
std::error_code err;
assert(std::filesystem::exists(path, err) && "Path did not exists");
std::list<FileTreeMap::iterator> list;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


auto [iter, _] = hashmap.insert_or_assign(path_str.string(),
nullptr);

list.push_back(iter);

while (!list.empty()) {
auto current_entry = list.front();
list.pop_front();
for (const auto & entry : fs::directory_iterator(current_entry->first)) {

fs::path p = entry.path();

std::shared_ptr<FileTree> tree;

if (fs::path(p).filename() == ".git") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make a std::vector of excluded directory name and compare using it, rather than just a string

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably by putting the excluded directories inside the config file after config parser is done and then pushing the directories into an std::vector

continue;
}
if (fs::is_directory(p)) {
tree = std::make_shared<FileTree>(p);
}

auto [i, _] = hashmap.insert_or_assign(p.string(), tree);
list.push_back(i);
}
}
}

// TODO
Expand Down
11 changes: 5 additions & 6 deletions editor/src/filesystem/filetree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ namespace TempehEditor::FileSystem
class FileTree
{
private:
class FileTreeInternal
{
std::map<std::string, std::shared_ptr<FileTree>> hashmap;
};
std::unique_ptr<FileTreeInternal> root;
using FileTreeMap = std::map<std::string, std::shared_ptr<FileTree>>;
FileTreeMap hashmap;
public:
FileTree(std::string& path);
FileTree(const std::filesystem::path &path_str);



// Implemented as BFS
void traversal(std::function<void(FileMetaData)> f);
Expand Down
Empty file added test/dummy-dir/1.txt
Empty file.
Empty file added test/dummy-dir/2.txt
Empty file.
Empty file.
Empty file.
25 changes: 14 additions & 11 deletions test/editor/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@

TEST(FileSystem, FileTree_ObjectCreation)
{
ASSERT_DEATH({
TempehEditor::FileSystem::FileTree test_obj(std::string("/blah"));
}, "Path did not exists");
// For debugging purpose
TempehEditor::FileSystem::FileTree test_obj("/home/rahman/Projects/tempeh-engine/test/dummy-dir");

#ifdef BOOST_OS_WINDOWS
ASSERT_NO_FATAL_FAILURE({
// Uhhh... is C:\\ is not a `standard`?
TempehEditor::FileSystem::FileTree test_obj(std::string("C:\\Windows"));
});
#elif BOOST_OS_LINUX
// TODO linux
#endif
// ASSERT_DEATH({
// TempehEditor::FileSystem::FileTree test_obj(std::string("/blah"));
// }, "Path did not exists");
//
//#ifdef BOOST_OS_WINDOWS
// ASSERT_NO_FATAL_FAILURE({
// // Uhhh... is C:\\ is not a `standard`?
// TempehEditor::FileSystem::FileTree test_obj(std::string("C:\\Windows"));
// });
//#elif BOOST_OS_LINUX
// // TODO linux
//#endif

}