Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Virtual File System (VFS)

🌍 Languages: English | Русский


Русский

Библиотека VFS предоставляет абстрактный слой для работы с виртуальной файловой системой.
Она реализует единый интерфейс для создания, удаления, чтения и навигации по файлам и директориям, поддерживая две реализации: Linux-подобную и Windows-подобную.


✨ Возможности

  • Создание и удаление файлов и директорий
  • Чтение и запись содержимого файлов
  • Проверка существования файлов и директорий
  • Навигация по дереву файловой системы через итераторы
  • Доступ к атрибутам файлов (время создания, обновления, доступа, скрытые, read-only и т. д.)
  • Кроссплатформенные реализации: linux_iml и windows_iml

🏗 Архитектура

Общие интерфейсы

  • IFileSystem — основной интерфейс файловой системы
    Методы: createFile, deleteFile, createDirectory, deleteDirectory, readFile, writeFile, fileExists, directoryExists, createIterator.

  • IFile — интерфейс файла
    Методы: getName, getSize, getContent, setContent, getAttributes.

  • IDirectory — интерфейс директории
    Методы: работа с файлами (addFile, removeFile, getFile, fileExists) и поддиректориями (addSubdirectory, removeSubdirectory, getSubdirectory, subdirectoryExists).

  • IDirectoryIterator — итератор по дереву
    Методы: goToSubdirectory, goToParentDirectory, getCurrentPath, getCurrentDirectory.

  • FileAttributes — атрибуты файла
    Содержат даты (created, updated, lastAccess) и флаги (hidden, readOnly).


Реализации

Linux

  • linux_iml::File — файл Linux-реализации.
  • linux_iml::Directory — директория Linux-реализации.
  • linux_iml::FileTree — дерево файлов.
  • linux_iml::Iterator — итератор по директориям.
  • LinuxFileSystem — реализация интерфейса IFileSystem для Linux.

Windows

  • windows_iml::File — файл Windows-реализации.
  • windows_iml::Directory — директория Windows-реализации.
  • windows_iml::FileTree — дерево файлов.
  • windows_iml::Iterator — итератор по директориям.
  • WindowsFileSystem — реализация интерфейса IFileSystem для Windows.

📂 Пример использования

Linux

#include "vfs/vfs.hpp"

int main() {
    vfs::LinuxFileSystem fs;

    fs.createDirectory("/project");
    fs.createFile("/project/main.cpp", "int main() { return 0; }");

    if (fs.fileExists("/project/main.cpp")) {
        std::string content = fs.readFile("/project/main.cpp");
        fs.writeFile("/project/main.cpp", content + "\n// updated");
    }

    return 0;
}

Windows

#include "vfs/vfs.hpp"

int main() {
    vfs::WindowsFileSystem fs('C');

    fs.createDirectory("C:\\project");
    fs.createFile("C:\\project\\main.cpp", "int main() { return 0; }");

    if (fs.fileExists("C:\\project\\main.cpp")) {
        std::string content = fs.readFile("C:\\project\\main.cpp");
        fs.writeFile("C:\\project\\main.cpp", content + "\n// updated");
    }

    return 0;
}

🧪 Тестирование и ⚙️ Сборка VFS

🧪 Тестирование

В проекте используется GoogleTest (и при необходимости GoogleMock) для модульного тестирования.
Тесты покрывают основные компоненты библиотеки:

  • File — проверка работы с именами, содержимым, атрибутами.
  • Directory — работа с файлами и поддиректориями.
  • FileTree и Iterator — навигация по дереву.
  • FileSystem (Linux и Windows) — комплексные сценарии создания, чтения и удаления файлов и директорий.

Запуск тестов:

cd build
cmake ..
make
ctest

Если тесты не нужны, их сборку можно отключить:

cmake -DBUILD_MODULE_TESTS=OFF ..

⚙️ Сборка

Сборка выполняется через CMake:

mkdir build && cd build
cmake ..
make

Выбор типа библиотеки

Библиотека может быть собрана как статическая (.a / .lib) или динамическая (.so / .dll). Выбор управляется переменной BUILD_SHARED_LIBS:

  • Статическая (по умолчанию):
cmake -DBUILD_SHARED_LIBS=OFF ..
  • Динамическая:
cmake -DBUILD_SHARED_LIBS=ON ..

Использование в других проектах

Встраивание через add_subdirectory Вы можете подключить библиотеку напрямую в свой проект:

add_subdirectory(vfs)
target_link_libraries(my_project PRIVATE vfs)

English

Virtual File System (VFS)

The VFS library provides an abstraction layer for working with a virtual file system.
It implements a unified interface for creating, deleting, reading, and navigating files and directories, supporting two implementations: Linux-like and Windows-like.


✨ Features

  • Create and delete files and directories
  • Read and write file contents
  • Check existence of files and directories
  • Navigate through file system tree via iterators
  • Access file attributes (creation time, update time, access time, hidden, read-only, etc.)
  • Cross-platform implementations: linux_iml and windows_iml

🏗 Architecture

Common Interfaces

  • IFileSystem — main file system interface
    Methods: createFile, deleteFile, createDirectory, deleteDirectory, readFile, writeFile, fileExists, directoryExists, createIterator.

  • IFile — file interface
    Methods: getName, getSize, getContent, setContent, getAttributes.

  • IDirectory — directory interface
    Methods: working with files (addFile, removeFile, getFile, fileExists) and subdirectories (addSubdirectory, removeSubdirectory, getSubdirectory, subdirectoryExists).

  • IDirectoryIterator — tree iterator
    Methods: goToSubdirectory, goToParentDirectory, getCurrentPath, getCurrentDirectory.

  • FileAttributes — file attributes
    Contains dates (created, updated, lastAccess) and flags (hidden, readOnly).


Implementations

Linux

  • linux_iml::File — Linux implementation file.
  • linux_iml::Directory — Linux implementation directory.
  • linux_iml::FileTree — file tree.
  • linux_iml::Iterator — directory iterator.
  • LinuxFileSystem — implementation of IFileSystem interface for Linux.

Windows

  • windows_iml::File — Windows implementation file.
  • windows_iml::Directory — Windows implementation directory.
  • windows_iml::FileTree — file tree.
  • windows_iml::Iterator — directory iterator.
  • WindowsFileSystem — implementation of IFileSystem interface for Windows.

📂 Usage Examples

Linux

#include "vfs/vfs.hpp"

int main() {
    vfs::LinuxFileSystem fs;

    fs.createDirectory("/project");
    fs.createFile("/project/main.cpp", "int main() { return 0; }");

    if (fs.fileExists("/project/main.cpp")) {
        std::string content = fs.readFile("/project/main.cpp");
        fs.writeFile("/project/main.cpp", content + "\n// updated");
    }

    return 0;
}

Windows

#include "vfs/vfs.hpp"

int main() {
    vfs::WindowsFileSystem fs('C');

    fs.createDirectory("C:\\project");
    fs.createFile("C:\\project\\main.cpp", "int main() { return 0; }");

    if (fs.fileExists("C:\\project\\main.cpp")) {
        std::string content = fs.readFile("C:\\project\\main.cpp");
        fs.writeFile("C:\\project\\main.cpp", content + "\n// updated");
    }

    return 0;
}

🧪 Testing and ⚙️ Building VFS

🧪 Testing

The project uses GoogleTest (and GoogleMock if needed) for unit testing. Tests cover the main components of the library:

  • File — testing work with names, content, attributes.
  • Directory — working with files and subdirectories.
  • FileTree и Iterator — tree navigation.
  • FileSystem (Linux and Windows) — complex scenarios of creating, reading and deleting files and directories.

Running tests:

cd build
cmake ..
make
ctest

If tests are not needed, their build can be disabled:

cmake -DBUILD_MODULE_TESTS=OFF ..

⚙️ Building

Building is done via CMake:

mkdir build && cd build
cmake ..
make

Library Type Selection

The library can be built as static (.a / .lib) or dynamic (.so / .dll). The choice is controlled by the BUILD_SHARED_LIBS variable:

  • Static (default):
cmake -DBUILD_SHARED_LIBS=OFF ..
  • Dynamic:
cmake -DBUILD_SHARED_LIBS=ON ..

Usage in Other Projects

Embedding via add_subdirectory You can connect the library directly to your project:

add_subdirectory(vfs)
target_link_libraries(my_project PRIVATE vfs)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages