@@ -37,28 +37,42 @@ double HybridMmfilePackage::getEncryptedFileSize(const std::string& path) {
3737 return getFileSize (getAbsolutePath (path)) - sizeof (EncryptedFileHeader);
3838}
3939
40+ static std::vector<ReadDirItem> _readDir (const std::string& absPath) {
41+ std::vector<ReadDirItem> items;
42+ try {
43+ for (const auto & entry : std::filesystem::directory_iterator (absPath)) {
44+ ReadDirItem item;
45+ item.name = entry.path ().filename ().string ();
46+ item.path = entry.path ().string ();
47+ item.isFile = entry.is_regular_file ();
48+ item.isDirectory = entry.is_directory ();
49+ item.size = item.isFile ? entry.file_size () : 0 ;
50+ item.mtime = std::chrono::duration_cast<std::chrono::seconds>(entry.last_write_time ().time_since_epoch ()).count ();
51+ items.push_back (item);
52+ }
53+ } catch (const std::exception& e) {
54+ // Handle errors (e.g., directory does not exist, permissions issue)
55+ throw std::runtime_error (std::string (" Failed to read directory: " ) + e.what ());
56+ }
57+ return items;
58+ }
59+
60+ std::vector<ReadDirItem> HybridMmfilePackage::readDirSync (const std::string& path) {
61+ std::string absPath = getAbsolutePath (path);
62+ return _readDir (absPath);
63+ }
64+
4065std::shared_ptr<Promise<std::vector<ReadDirItem>>> HybridMmfilePackage::readDir (const std::string& path) {
4166 std::string absPath = getAbsolutePath (path);
4267 return Promise<std::vector<ReadDirItem>>::async ([=]() -> std::vector<ReadDirItem> {
4368 // This runs on a separate Thread!
44- std::vector<ReadDirItem> items;
45- try {
46- for (const auto & entry : std::filesystem::directory_iterator (absPath)) {
47- ReadDirItem item;
48- item.name = entry.path ().filename ().string ();
49- item.path = entry.path ().string ();
50- item.isFile = entry.is_regular_file ();
51- item.isDirectory = entry.is_directory ();
52- item.size = item.isFile ? entry.file_size () : 0 ;
53- item.mtime = std::chrono::duration_cast<std::chrono::seconds>(entry.last_write_time ().time_since_epoch ()).count ();
54- items.push_back (item);
55- }
56- } catch (const std::exception& e) {
57- // Handle errors (e.g., directory does not exist, permissions issue)
58- throw std::runtime_error (std::string (" Failed to read directory: " ) + e.what ());
59- }
60- return items;
61- });
69+ return _readDir (absPath);
70+ });
71+ }
72+
73+ void HybridMmfilePackage::unlinkSync (const std::string& path) {
74+ std::string absPath = getAbsolutePath (path);
75+ std::filesystem::remove_all (absPath);
6276}
6377
6478std::shared_ptr<Promise<void >> HybridMmfilePackage::unlink (const std::string& path) {
@@ -69,4 +83,5 @@ std::shared_ptr<Promise<void>> HybridMmfilePackage::unlink(const std::string& pa
6983 });
7084}
7185
86+
7287} // namespace margelo::nitro::mmfile
0 commit comments