diff --git a/examples/basicExample.cpp b/examples/basicExample.cpp index 9b3412f..a143c27 100644 --- a/examples/basicExample.cpp +++ b/examples/basicExample.cpp @@ -41,12 +41,13 @@ int main() { std::shared_ptr telemetryRootNode; telemetryRootNode = telemetry::Directory::create(); - // path to root dir, which has to exist before the program starts. - // The path is local to where the program is called from. + // The path to root dir is local to where the program is called from. std::string fusePath = "fusedir"; // Linking root dir to the chosen directory on disk. - telemetry::appFs::AppFsFuse fuse = telemetry::appFs::AppFsFuse(telemetryRootNode, fusePath, true, false); + // If the fourth argument is true it means the directory on disk doesn't need to + // exist before starting program. + telemetry::appFs::AppFsFuse fuse = telemetry::appFs::AppFsFuse(telemetryRootNode, fusePath, true, true); fuse.start(); // The filesystem is still just empty. // / @@ -91,7 +92,6 @@ int main() { // │ └─ time // └─ time - // Don't forget to create directory named fusedir // Waiting for ctrl+c. In the meantime you can open another terminal and // navigate to the newly linked directory. Just reading the new time file // should print the time elapsed in seconds since the start of the program. diff --git a/examples/holderExample.cpp b/examples/holderExample.cpp index 968a81b..d9da7b6 100644 --- a/examples/holderExample.cpp +++ b/examples/holderExample.cpp @@ -9,6 +9,8 @@ #include #include +// Object that collects it's own telemetry or owns +// telemetry files or directories. class IOwnTelemetryFiles { public: void configTelemetry(const std::shared_ptr& rootDir) { @@ -39,13 +41,12 @@ int main() { std::string fusePath = "fusedir"; - telemetry::appFs::AppFsFuse fuse = telemetry::appFs::AppFsFuse(telemetryRootNode, fusePath); + telemetry::appFs::AppFsFuse fuse = telemetry::appFs::AppFsFuse(telemetryRootNode, fusePath, true, true); fuse.start(); - // Object that collects it's own telemetry or owns - // telemetry files or directories. // The files callbacks get disabled when the telemetry holder - // is destroyed. + // is destroyed and if the files and dirs don't have another reference + // elsewhere they get destroyed too. IOwnTelemetryFiles object; // Configuration of telemetry inside of the object. diff --git a/examples/utilsExample.cpp b/examples/utilsExample.cpp index b005c47..b168072 100644 --- a/examples/utilsExample.cpp +++ b/examples/utilsExample.cpp @@ -16,7 +16,7 @@ void traverseDir(std::shared_ptr& dir, int depth) { // Using utils to check if a directory is a root directory if(telemetry::utils::isRootDirectory(dir->getFullPath())) { - std::cout << "start\n"; + std::cout << "root\n"; } // looping through files and dirs in directory @@ -40,7 +40,8 @@ void traverseDir(std::shared_ptr& dir, int depth) { try { std::cout << telemetry::contentToString(file->read()); } catch(std::exception& ex) { - std::cout << ex.what() << "\n"; + // File::read operation not supported + // std::cout << ex.what() << "\n"; } } } @@ -53,7 +54,7 @@ int main() { std::string fusePath = "fusedir"; - telemetry::appFs::AppFsFuse fuse = telemetry::appFs::AppFsFuse(telemetryRootNode, fusePath); + telemetry::appFs::AppFsFuse fuse = telemetry::appFs::AppFsFuse(telemetryRootNode, fusePath, true, true); fuse.start(); // Let's create a more complex dir structure @@ -68,15 +69,15 @@ int main() { auto dir2 = dir1->addDir("dir2"); auto dir3 = dir1->addDir("dir3"); - const int nFiles = 5; - for(int index = 0; index < nFiles; index++) { - auto file = dir2->addFile("file" + std::to_string(index + 4), emptyFileOps); - } + auto file4 = dir2->addFile("file4", emptyFileOps); + auto file5 = dir2->addFile("file5", emptyFileOps); + auto file6 = dir2->addFile("file6", emptyFileOps); + auto file7 = dir2->addFile("file7", emptyFileOps); - auto file9 = dir3->addFile("file9", emptyFileOps); + auto file8 = dir3->addFile("file8", emptyFileOps); // And now traverse the directory with the use of telemetry utils - traverseDir(telemetryRootNode, 0); + traverseDir(telemetryRootNode, 1); // Utils can also give you a node from path auto node = telemetry::utils::getNodeFromPath(telemetryRootNode, "/dir1/dir2/file5");