예제 #1
0
파일: TeaSafe.cpp 프로젝트: airk42/teasafe
    SharedFile
    TeaSafe::setAndGetCachedFile(std::string const &path,
                                 SharedCompoundFolder const &parentEntry,
                                 OpenDisposition openMode) const
    {

        // very strictly limit the size of the cache to being able to hold
        // on to one entry only. TODO. does this mean that a map is a map
        // idea? We could just use a single pair.
        if(m_fileCache.size() > 1) {
            FileCache().swap(m_fileCache);
        }

        auto it(m_fileCache.find(path));
        if(it != m_fileCache.end()) {

            // note: need to also check if the openMode is different to the cached
            // version in which case the cached version should probably be rebuilt
            if(!it->second->getOpenDisposition().equals(openMode)) {
                m_fileCache.erase(path);
            } else {
                return it->second;
            }
        }

        auto sf(std::make_shared<File>(parentEntry->getFile(boost::filesystem::path(path).filename().string(),
                                                                   openMode)));
        m_fileCache.insert(std::make_pair(path, sf));
        return sf;
    }
예제 #2
0
파일: CoreFS.cpp 프로젝트: benhj/KnoxCrypt
 void
 CoreFS::setCachedFile(std::string const &path,
                        SharedCompoundFolder const &parentEntry,
                        OpenDisposition openMode) const
 {
     auto theName = boost::filesystem::path(path).filename().string();
     if(m_cachedFileAndPath) {
         if( m_cachedFileAndPath->first != path ||
            !m_cachedFileAndPath->second->getOpenDisposition().equals(openMode)) {
             m_cachedFileAndPath->second = std::make_shared<File>(parentEntry->getFile(theName, openMode));
         }
     } else {
         m_cachedFileAndPath.reset(new FileAndPathPair(path,
                                                       std::make_shared<File>(parentEntry->getFile(theName,
                                                                                                   openMode))));
     }
 }
예제 #3
0
파일: CoreFS.cpp 프로젝트: benhj/KnoxCrypt
 void
 CoreFS::removeAllChildFoldersToo(::boost::filesystem::path const &path,
                                   SharedCompoundFolder const &f)
 {
     std::vector<SharedEntryInfo> infos = f->listFolderEntries();
     for (auto const & entry : infos) {
         auto entryPath = path;
         entryPath /= entry->filename();
         removeFolderFromCache(entryPath);
     }
 }