From cda39ec9d6a0b5fab2c009046cf3570ab90db20b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 17 May 2017 18:21:22 +0300 Subject: Improve a bit virtfs based on directories. --- src/fs/virtfs/direntry.cpp | 4 +++- src/fs/virtfs/direntry.h | 2 ++ src/fs/virtfs/fs.cpp | 6 +++++- src/fs/virtfs/fsdir.cpp | 24 +++++++++++++++--------- 4 files changed, 25 insertions(+), 11 deletions(-) (limited to 'src/fs/virtfs') diff --git a/src/fs/virtfs/direntry.cpp b/src/fs/virtfs/direntry.cpp index 1ce81b97b..c178d4c88 100644 --- a/src/fs/virtfs/direntry.cpp +++ b/src/fs/virtfs/direntry.cpp @@ -28,9 +28,11 @@ namespace VirtFs DirEntry::DirEntry(const std::string &userDir0, const std::string &rootDir, const std::string &subDir0, + const std::string &rootSubDir0, FsFuncs *restrict const funcs0) : FsEntry(FsEntryType::Dir, funcs0), - userDir(userDir0) + userDir(userDir0), + rootSubDir(rootSubDir0) { root = rootDir; subDir = subDir0; diff --git a/src/fs/virtfs/direntry.h b/src/fs/virtfs/direntry.h index 93ee09166..41d9afc7c 100644 --- a/src/fs/virtfs/direntry.h +++ b/src/fs/virtfs/direntry.h @@ -33,6 +33,7 @@ struct DirEntry final : public FsEntry DirEntry(const std::string &userDir0, const std::string &rootDir, const std::string &subDir0, + const std::string &rootSubDir0, FsFuncs *restrict const funcs0); A_DELETE_COPY(DirEntry) @@ -40,6 +41,7 @@ struct DirEntry final : public FsEntry ~DirEntry(); std::string userDir; + std::string rootSubDir; }; } // namespace VirtFs diff --git a/src/fs/virtfs/fs.cpp b/src/fs/virtfs/fs.cpp index c6390b914..aa456fb4b 100644 --- a/src/fs/virtfs/fs.cpp +++ b/src/fs/virtfs/fs.cpp @@ -368,7 +368,11 @@ namespace VirtFs return false; } logger->log("Add virtual directory: " + newDir); - addEntry(new DirEntry(newDir, rootDir, subDir, FsDir::getFuncs()), + addEntry(new DirEntry(newDir, + rootDir, + subDir, + rootDir + subDir, + FsDir::getFuncs()), append); return true; } diff --git a/src/fs/virtfs/fsdir.cpp b/src/fs/virtfs/fsdir.cpp index 37c5cc795..e205e8362 100644 --- a/src/fs/virtfs/fsdir.cpp +++ b/src/fs/virtfs/fsdir.cpp @@ -65,7 +65,8 @@ namespace FsDir const std::string &filename, const FILEMTYPE mode) { - const std::string path = entry->root + entry->subDir + filename; + const std::string path = static_cast(entry)->rootSubDir + + filename; if (Files::existsLocal(path) == false) return nullptr; FILEHTYPE fd = FILEOPEN(path.c_str(), @@ -173,7 +174,7 @@ namespace FsDir std::string &realDir) { DirEntry *const dirEntry = static_cast(entry); - if (Files::existsLocal(dirEntry->root + entry->subDir + filename)) + if (Files::existsLocal(dirEntry->rootSubDir + filename)) { realDir = dirEntry->userDir; return true; @@ -185,14 +186,16 @@ namespace FsDir std::string fileName, std::string dirName A_UNUSED) { - return Files::existsLocal(entry->root + entry->subDir + fileName); + return Files::existsLocal(static_cast(entry)->rootSubDir + + fileName); } void enumerate(FsEntry *restrict const entry, std::string dirName, StringVect &names) { - const std::string path = entry->root + entry->subDir + dirName; + const std::string path = static_cast(entry)->rootSubDir + + dirName; const struct dirent *next_file = nullptr; DIR *const dir = opendir(path.c_str()); if (dir) @@ -234,7 +237,7 @@ namespace FsDir std::string dirName, bool &isDirFlag) { - std::string path = entry->root + entry->subDir + dirName; + std::string path = static_cast(entry)->rootSubDir + dirName; struct stat statbuf; if (stat(path.c_str(), &statbuf) == 0) @@ -462,7 +465,7 @@ namespace FsDir int &restrict fileSize) { const DirEntry *const dirEntry = static_cast(entry); - const std::string path = entry->root + entry->subDir + filename; + const std::string path = dirEntry->rootSubDir + filename; if (Files::existsLocal(path) == false) return nullptr; FILEHTYPE fd = FILEOPEN(path.c_str(), @@ -524,7 +527,8 @@ namespace FsDir std::string dirName, StringVect &names) { - const std::string path = entry->root + entry->subDir + dirName; + const std::string path = static_cast(entry)->rootSubDir + + dirName; const struct dirent *next_file = nullptr; DIR *const dir = opendir(path.c_str()); if (dir) @@ -573,7 +577,8 @@ namespace FsDir const std::string &dirName, StringVect &names) { - const std::string path = entry->root + entry->subDir + dirName; + const std::string path = static_cast(entry)->rootSubDir + + dirName; const struct dirent *next_file = nullptr; DIR *const dir = opendir(path.c_str()); if (dir) @@ -622,7 +627,8 @@ namespace FsDir std::string dirName, StringVect &names) { - const std::string path = entry->root + entry->subDir + dirName; + const std::string path = static_cast(entry)->rootSubDir + + dirName; const struct dirent *next_file = nullptr; DIR *const dir = opendir(path.c_str()); if (dir) -- cgit v1.2.3-70-g09d2