diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-05-17 18:21:22 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-05-17 18:21:22 +0300 |
commit | cda39ec9d6a0b5fab2c009046cf3570ab90db20b (patch) | |
tree | cd9d1c5a6abb749d81d7f785917ceb6d0525b898 /src/fs/virtfs | |
parent | a9d80dc997f95aa17a12e4d797ecc26072a38edb (diff) | |
download | mv-cda39ec9d6a0b5fab2c009046cf3570ab90db20b.tar.gz mv-cda39ec9d6a0b5fab2c009046cf3570ab90db20b.tar.bz2 mv-cda39ec9d6a0b5fab2c009046cf3570ab90db20b.tar.xz mv-cda39ec9d6a0b5fab2c009046cf3570ab90db20b.zip |
Improve a bit virtfs based on directories.
Diffstat (limited to 'src/fs/virtfs')
-rw-r--r-- | src/fs/virtfs/direntry.cpp | 4 | ||||
-rw-r--r-- | src/fs/virtfs/direntry.h | 2 | ||||
-rw-r--r-- | src/fs/virtfs/fs.cpp | 6 | ||||
-rw-r--r-- | src/fs/virtfs/fsdir.cpp | 24 |
4 files changed, 25 insertions, 11 deletions
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<DirEntry*>(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<DirEntry*>(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<DirEntry*>(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<DirEntry*>(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<DirEntry*>(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<DirEntry*>(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<DirEntry*>(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<DirEntry*>(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<DirEntry*>(entry)->rootSubDir + + dirName; const struct dirent *next_file = nullptr; DIR *const dir = opendir(path.c_str()); if (dir) |