{"id":21956950,"url":"https://github.com/lesomnus/vfs","last_synced_at":"2025-04-23T15:24:36.627Z","repository":{"id":169117288,"uuid":"639536232","full_name":"lesomnus/vfs","owner":"lesomnus","description":"Virtual File System with `std::filesystem` API.","archived":false,"fork":false,"pushed_at":"2023-08-12T09:19:46.000Z","size":296,"stargazers_count":21,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-30T01:04:49.650Z","etag":null,"topics":["filesystem","fs","memfs","unionfs","vfs"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lesomnus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-11T16:53:19.000Z","updated_at":"2025-01-12T16:38:37.000Z","dependencies_parsed_at":"2024-11-29T08:40:57.564Z","dependency_job_id":"eceaeda2-848f-42b9-aa0a-a0a4ae05f5aa","html_url":"https://github.com/lesomnus/vfs","commit_stats":null,"previous_names":["lesomnus/vfs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lesomnus%2Fvfs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lesomnus%2Fvfs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lesomnus%2Fvfs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lesomnus%2Fvfs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lesomnus","download_url":"https://codeload.github.com/lesomnus/vfs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250458442,"owners_count":21433874,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filesystem","fs","memfs","unionfs","vfs"],"created_at":"2024-11-29T08:40:49.857Z","updated_at":"2025-04-23T15:24:36.621Z","avatar_url":"https://github.com/lesomnus.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vfs\n\n[![test](https://github.com/lesomnus/vfs/actions/workflows/test.yaml/badge.svg)](https://github.com/lesomnus/vfs/actions/workflows/test.yaml)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/14de41c183224821af5004302a830441)](https://app.codacy.com/gh/lesomnus/vfs/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\n[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/14de41c183224821af5004302a830441)](https://app.codacy.com/gh/lesomnus/vfs/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_coverage)\n\nVirtual File System that provides interface of `std::filesystem`.\n\n## Example\n\n```cpp\n#include \u003ccassert\u003e\n#include \u003cmemory\u003e\n#include \u003cstring\u003e\n\n#include \u003cvfs.hpp\u003e\n\nvoid work(vfs::Fs\u0026 fs) {\n\tfs.create_directories(\"foo/bar\");\n\tfs.create_symlink(\"foo/bar\", \"baz\");\n\n\t*fs.open_write(\"baz/food\") \u003c\u003c \"Royale with cheese\";\n}\n\nint main(int argc, char* argv[]) {\n\tauto sandbox = vfs::make_vfs();\n\twork(*sandbox);\n\n\tstd::string line;\n\tstd::getline(*sandbox-\u003eopen_read(\"foo/bar/food\"), line);\n\t\n\tassert(line == \"Royale with cheese\");\n\n\treturn 0;\n}\n```\n\n## Features\n\n### File Systems\n- `vfs::make_os_fs` Proxy of `std::filesystem`.\n- `vfs::make_vfs` Basic file system.\n- `vfs::make_mem_fs` Files are stored on the memory.\n- `vfs::make_union_fs` Provides a single coherent file system over multiple file systems.\n- `vfs::make_read_only_fs` Makes the given file system read-only.\n\n### Utilities\n- `vfs::Fs::change_root` Changes the root directory.\n- `vfs::Fs::mount` Mounts different file system.\n- `vfs::Fs::copy` Copies a file between file systems.\n\n\n## About Current Working Directory\n\n```cpp\n#include \u003ccassert\u003e\n#include \u003cfilesystem\u003e\n\n#include \u003cvfs.hpp\u003e\n\nint main(int argc, char* argv[]) {\n\t// Assume a directory \"/tmp/foo/\" and a regular file \"/tmp/bar/foo\" exist.\n\t{\n\t\tnamespace fs = std::filesystem;\n\n\t\tfs::current_path(\"/tmp\");\n\t\tassert(fs::is_directory(\"foo\")); // References \"/tmp/foo/\".\n\n\t\tfs::current_path(\"/tmp/bar\");\n\t\tassert(not fs::is_directory(\"foo\")); // References \"/tmp/bar/foo\".\n\t}\n\n\t{\n\t\tauto const fs = vfs::make_os_fs();\n\n\t\tauto const tmp = fs-\u003ecurrent_path(\"/tmp\");\n\t\tassert(tmp-\u003eis_directory(\"foo\")); // References \"/tmp/foo/\".\n\n\t\tauto const bar = fs-\u003ecurrent_path(\"/tmp/bar\");\n\t\tassert(not bar-\u003eis_directory(\"foo\")); // References \"/tmp/bar/foo\".\n\t\tassert(tmp-\u003eis_directory(\"foo\"));     // References \"/tmp/foo/\".\n\t}\n\n\treturn 0;\n}\n```\n\nStandard `std::filesystem::current_path(std::filesystem::path const\u0026 p)` changes the Current Working Directory (CWD), which can have an impact on any code in the current process that relies on relative paths, potentially causing unintended results.\n\nIn *vfs*, since the file system is an object, each `vfs::Fs` holds its own CWD. `vfs::Fs::current_path(...)` returns a new instance that references the same file system but has a different CWD, instead of replacing the CWD of the existing instance.\n\n\n## Mount\n\n```cpp\n#include \u003ccassert\u003e\n#include \u003cfilesystem\u003e\n#include \u003cfstream\u003e\n#include \u003cstring\u003e\n\n#include \u003cvfs.hpp\u003e\n\nint main(int argc, char* argv[]) {\n\tnamespace fs = std::filesystem;\n\n\tauto const sandbox = vfs::make_vfs();\n\tsandbox-\u003ecreate_directories(\"foo/bar\");\n\n\tsandbox-\u003emount(\"foo/bar\", *vfs::make_os_fs(), \"/tmp\");\n\t*sandbox-\u003eopen_write(\"foo/bar/food\") \u003c\u003c \"Royale with cheese\";\n\tasser(sandbox-\u003eexists(\"foo/bar/food\"));\n\tasser(fs::exists(\"/tmp/food\"));\n\n\t{\n\t\tstd::string line;\n\t\tstd::getline(*sandbox-\u003eopen_read(\"foo/bar/food\"), line);\n\t\tasser(line == \"Royale with cheese\");\n\t}\n\n\t{\n\t\tstd::ifstream food(\"/tmp/food\");\n\t\tstd::string   line;\n\t\tstd::getline(food, line);\n\t\tasser(line == \"Royale with cheese\");\n\t}\n\n\tsandbox-\u003eunmount(\"foo/bar\");\n\tasser(not sandbox-\u003eexists(\"foo/bar/food\"));\n\tasser(fs::exists(\"/tmp/food\"));\n\n\treturn 0;\n}\n```\n\n`Fs::mount` is similar to a bind mount.\nIt allows you to mount a file from a filesystem to a different path or mount a file from a different filesystem.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flesomnus%2Fvfs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flesomnus%2Fvfs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flesomnus%2Fvfs/lists"}