/********************************************************************************************** * setPeerBufferMap *********************************************************************************************/ bool File::setPeerBufferMap(Peer peer, uint8_t* map) { FileEntry* entry = getFileEntry(peer); if (entry != (FileEntry*) (0)) { return entry->setBufferMap(map); } return false; }
/********************************************************************************************** * getPeerBufferMap *********************************************************************************************/ const uint8_t* File::getPeerBufferMap(Peer peer) { FileEntry* entry = getFileEntry(peer); if (entry != (FileEntry*) (0)) { return entry->getBufferMap(); } return (uint8_t*) (0); }
void Cache::insertDiskEntry(const std::string& k, FileEntry* v) { // If necessary, make space while (_diskcache.size()>0 && (_diskcache.size()>=_maxDiskCacheEntries || _curDiskCacheCapacity > _maxDiskCacheCapacity)) { std::cout << "[CACHE] Deleting Disk Cache Entry: curSize = " << _curDiskCacheCapacity << ", max = " << _maxDiskCacheCapacity << "\n"; FileEntry* pEntry = _diskcache.right.begin()->info; if (!pEntry->IsReady() && !pEntry->IsFailed()) { return; // can't delete at the moment } // by purging the least-recently-used element _curDiskCacheCapacity -= ((double)pEntry->FileSize() / 1024.0 / 1024.0); if (_curDiskCacheCapacity < 0) _curDiskCacheCapacity = 0; // delete Cache entry from disk: std::string sFilename = _basedir + pEntry->LocalFile(); std::string sCacheFile = sFilename + ".cache"; if (!FileSystem::rm(sCacheFile)) std::cout << "**ERROR: Failed deleting: " << sCacheFile << "\n"; if (!FileSystem::rm(sFilename)) std::cout << "**ERROR: Failed deleting: " << sFilename << "\n"; // delete entry from list _diskcache.right.erase(_diskcache.right.begin()); } _diskcache.insert(DiskCache_t::value_type(k,0,v)); }
DWORD FileProcessor::Run(LPVOID /*arg*/) { if( PP ){ FileEntry entry; nProcessed = 0; while( !PP->quitRequested() && (isBackwards ? PP->getBack(entry) : PP->getFront(entry)) ){ // create a scoped lock without closing it immediately CRITSECTLOCK::Scope scp(PP->ioLock, 0); scope = &scp; currentEntry = &entry; _InterlockedIncrement(&PP->nProcessing); entry.compress( this, PP ); _InterlockedDecrement(&PP->nProcessing); _InterlockedIncrement(&PP->nProcessed); currentEntry = NULL; nProcessed += 1; scope = NULL; runningTotalRaw += entry.fileInfo.st_size; runningTotalCompressed += (entry.compressedSize > 0)? entry.compressedSize : entry.fileInfo.st_size; /*if( PP->verbose() > 1 )*/{ #if defined(__MACH__) mach_port_t thread = mach_thread_self(); mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; thread_basic_info_data_t info; int kr = thread_info(thread, THREAD_BASIC_INFO, (thread_info_t) &info, &count); if( kr == KERN_SUCCESS ){ userTime = info.user_time.seconds + info.user_time.microseconds * 1e-6; systemTime = info.system_time.seconds + info.system_time.microseconds * 1e-6; avCPUUsage += info.cpu_usage * 100.0 / TH_USAGE_SCALE; threadInfo = info; hasInfo = true; } mach_port_deallocate(mach_task_self(), thread); #elif defined(linux) struct rusage rtu; if (!getrusage(RUSAGE_THREAD, &rtu)) { const auto ut = rtu.ru_utime.tv_sec + rtu.ru_utime.tv_usec * 1e-6; const auto st = rtu.ru_stime.tv_sec + rtu.ru_stime.tv_usec * 1e-6; if (ut >= 0 && st >= 0) { userTime = ut, systemTime = st, hasInfo = true; } } # ifdef CLOCK_THREAD_CPUTIME_ID struct timespec ts; if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) != -1) { cpuTime = ts.tv_sec + ts.tv_nsec * 1e-9; double t = userTime + systemTime; if (cpuTime > 0) { avCPUUsage += t * 100.0 / cpuTime; } } # endif #endif } } } return DWORD(nProcessed); }
FileEntry* MemoryPackage::RegisterMemory(const MemoryData& data, const FileIdRef& fileId) { FileEntry* fileEntry = SaveFile(data, fileId.Name, nullptr, DataReadingMode::DirectMove); if (fileEntry != nullptr) { fileEntry->SetPermission(FilePermission::Read); } return fileEntry; }
pf_stat CacheBase::GetAttr(std::string path) { BlockLockMutex lock(this); FileEntry* file = Path2File(path); if(!file) throw NoSuchFileOrDir(); return file->GetAttr(); }
void CacheBase::ChMod(std::string path, mode_t mode) { BlockLockMutex lock(this); FileEntry* file = Path2File(path); if(!file) throw NoSuchFileOrDir(); pf_stat stat = file->GetAttr(); stat.mode = mode; stat.meta_mtime = time(NULL); SetAttr(path, stat); }
void CacheBase::ChOwn(std::string path, uid_t uid, gid_t gid) { BlockLockMutex lock(this); FileEntry* file = Path2File(path); if(!file) throw NoSuchFileOrDir(); pf_stat stat = file->GetAttr(); stat.uid = uid; stat.gid = gid; stat.meta_mtime = time(NULL); SetAttr(path, stat); }
static v8::Handle<v8::Value> fileCallback(const v8::Arguments& args) { if (args.Length() < 1) return throwNotEnoughArgumentsError(args.GetIsolate()); FileEntry* imp = V8FileEntry::toNative(args.Holder()); if (args.Length() <= 0 || !args[0]->IsFunction()) return throwTypeError(0, args.GetIsolate()); RefPtr<FileCallback> successCallback = V8FileCallback::create(args[0], getScriptExecutionContext()); RefPtr<ErrorCallback> errorCallback; if (args.Length() > 1 && !args[1]->IsNull() && !args[1]->IsUndefined()) { if (!args[1]->IsFunction()) return throwTypeError(0, args.GetIsolate()); errorCallback = V8ErrorCallback::create(args[1], getScriptExecutionContext()); } imp->file(successCallback, errorCallback); return v8Undefined(); }
// write a file into ark // (upon adding, all files flagged as encrypted will be encrypted) bool ArkFile::WriteFile(const FileEntry& entry) { if( !IsOpen() ) return false; // file must be external in order to write it into ark if( !entry.IsExternal() ) return false; FILE* src_fd = fopen(entry.Filename(), "rb"); if(src_fd == NULL) return false; bool result = WriteFile(src_fd, entry); fclose(src_fd); return result; }
void DFGImpl::FileSkipped(const FileEntry &SkippedFile, const Token &FilenameTok, SrcMgr::CharacteristicKind FileType) { StringRef Filename = SkippedFile.getName(); if (!FileMatchesDepCriteria(Filename.data(), FileType)) return; AddFilename(llvm::sys::path::remove_leading_dotslash(Filename)); }
CoderList FileStorage::GetFileCoders(const FileEntry& file) const { StringRef ext = Path::GetExtension(file.Name()); const CoderList* coders = GetCoderRule(ext); if (coders != nullptr) { return *coders; } return Coders(); }
error_code VFSFromYAML::openFileForRead(const Twine &Path, std::unique_ptr<vfs::File> &Result) { ErrorOr<Entry *> E = lookupPath(Path); if (!E) return E.getError(); FileEntry *F = dyn_cast<FileEntry>(*E); if (!F) // FIXME: errc::not_a_file? return error_code(errc::invalid_argument, system_category()); if (error_code EC = ExternalFS->openFileForRead(F->getExternalContentsPath(), Result)) return EC; if (!F->useExternalName(UseExternalNames)) Result->setName(Path.str()); return error_code::success(); }
void SwarmerSourceDll::GenerateMapFromFiles() { vector<string> filenames; char hash[40+1]; char tempfilename[256+1]; FileEntry entry; int num_files; num_files = m_manager.ExploreFolder("C:\\syncher\\file deposit\\distribute\\kazaa_swarm\\",&filenames); for(int i = 0; i < (int)filenames.size(); i ++) { strcpy(tempfilename,filenames[i].c_str()); m_manager.GetHashFromDeflated(tempfilename,hash); m_manager.GetEntryFromHash(hash,&entry); entry.SaveSpecial(); } }
MemoryEntry* Cache::_RequestData(const std::string& url, boost::function<void(const std::string&, MemoryEntry*, void*)> callback, bool async, void* userdata, boost::function<void(const std::string&, MemoryEntry*, void*)> callback_onthread) { MemoryEntry* result = 0; int n = url.find("http://"); if(n != 0) { result = _LoadLocalFile(url, async, false, callback, callback_onthread, url, userdata); return result; } else { // file on web -> disk cache required // Attempt to find record of the URL in disk cache const DiskCache_t::left_iterator it =_diskcache.left.find(url); if (it==_diskcache.left.end()) { // create new record FileEntry* v= new FileEntry(); insertDiskEntry(url,v); result = _LoadRemoteFile(url, v, async, callback, callback_onthread, userdata); return result; } else { // We do have it: // Update the access record view. FileEntry* entry = it->info; if (!entry->IsFailed()) // failed entries never get higher _diskcache.right.relocate(_diskcache.right.end(), _diskcache.project_right(it)); result = _LoadLocalFile(entry->LocalFile(), async, true, callback, callback_onthread, url, userdata); return result; } } return 0; }
void config_load_file(const char *szFilename) { FILE *pStream = fopen(szFilename, "r"); char szLine[LINE_BUFFER]; FileEntry *pFileEntry; int result; regmatch_t rgMatches[2]; printf("Loading %s\n", szFilename); if (!pStream) { return; } compile_regexes(FILE_ENTRIES); while (fgets(szLine, LINE_BUFFER, pStream)) { pFileEntry = FILE_ENTRIES; while (pFileEntry->szParameter) { result = regexec( pFileEntry->pRegexCompiled, /* preg */ szLine, /* string */ 2, /* nmatch */ rgMatches, /* pmatch */ 0 /* eflags */ ); if (result == 0) { /* Insert null at end of match. */ szLine[rgMatches[1].rm_eo] = '\0'; pFileEntry->store(szLine + rgMatches[1].rm_so); } pFileEntry++; } } free_regexes(FILE_ENTRIES); fclose(pStream); }
// copies a file from this ark into another ark bool ArkFile::CopyFrom(ArkFile& rDestArk, const FileEntry& destEntry, const FileEntry& srcEntry) { if( !IsOpen() ) return false; // get a file descriptor pointing to the location in the destination // ark file at which the file should be written FILE* dest_fd = rDestArk.GetHandleFromOffset(destEntry.Offset(), false); if(dest_fd == NULL) return false; return ReadFile(dest_fd, srcEntry, false); }
// copies a file from another ark into this ark bool ArkFile::CopyInto(ArkFile& rSrcArk, const FileEntry& destEntry, const FileEntry& srcEntry) { if( !IsOpen() ) return false; // get a file descriptor pointing to the location in the source // ark file at which the file should be read from FILE* src_fd = rSrcArk.GetHandleFromOffset(srcEntry.Offset(), true); if(src_fd == NULL) return false; bool result = WriteFile(src_fd, destEntry); return result; }
VisualAppearance::VisualAppearance( std::string visualAppearanceId, std::string animationsDescriptionFile ) { this->visualAppearanceId_ = visualAppearanceId; FileData* dataFromFile = b2WorldAndVisualWorld.globalGameObjectManager_->parseFileData( &animationsDescriptionFile, 5 ); FileData::iterator itData; for( itData = dataFromFile->begin(); itData < dataFromFile->end(); itData++ ) { FileEntry::iterator itEntry; FileEntry tmp = (*itData); itEntry = tmp.begin(); std::string animationId = (*itEntry); itEntry++; std::string animationFileName = (*itEntry); itEntry++; sf::Vector2i rowsAndCollumns; rowsAndCollumns.x = atoi((*itEntry).c_str()); itEntry++; rowsAndCollumns.y = atoi((*itEntry).c_str()); itEntry++; int delayPerFrame = atoi((*itEntry).c_str()); Animation* temporaryAnimation = new Animation( animationId, animationFileName, rowsAndCollumns, delayPerFrame ); if( temporaryAnimation != NULL ) { this->possibleAnimations_.push_back( temporaryAnimation ); } } if(possibleAnimations_.empty()) { exit(1); } }
Node::Node(std::vector<uint8_t>& data, std::unique_ptr<detail::Header>& header, uint32_t offset, std::string parent) { type = util::read(data, offset + NodeOffset::Type, 4); string_offset = util::read_big<uint32_t>(data, offset + NodeOffset::StringTableOffset); unknown = util::read_big<uint16_t>(data, offset + NodeOffset::Unknown); file_entries = util::read_big<uint16_t>(data, offset + NodeOffset::FileEntries); file_offset = util::read_big<uint32_t>(data, offset + NodeOffset::FileStartOffset); // Read name from the string table name = util::read(data, header->string_table() + string_offset); uint32_t subdirs = 0; for (uint32_t i = 0; i < file_entries; i++) { // Create FileEntry FileEntry entry = detail::FileEntry(data, (file_offset * 0x14) + header->file_table() + (i * 0x14)); std::string entry_name = util::read(data, header->string_table() + entry.name_offset()); std::string path = parent + name + "/" + entry_name; // Only add if it's not a . or .. directory if (entry_name != "." && entry_name != "..") { // Set full path for easier handling later entry.set_name(entry_name); entry.set_path(path); m_files[path] = entry; // If this is a directory then recurse into that node if (m_files[path].id() == 0xFFFF) { subnodes.push_back(Node(data, header, offset + ++subdirs * 0x10, parent + name + "/")); } } } }
bool FileMapTagItem::RemoveOrderItems(const FileEntry& fileEntry) { FileId fileId = FileId::ParseFrom(fileEntry.Name()); FileMapNameItem* nameItem=mItems.GetOptional(fileId.Name, nullptr); if (nameItem->RemoveOrderItems(fileEntry)) { if (!nameItem->IsEmpty()) { mItems.RemoveKey(fileId.Name); delete nameItem; } return true; } return false; }
void GotoFileList::Find(const wxString& searchtext, const std::map<wxString,wxString>& triggers) { m_tempEntry->Clear(); if (searchtext.empty()) { // Remove highlights m_searchText.clear(); SetSelection(-1); // de-select ScrollToLine(0); UpdateList(true); return; } // Convert to lower case for case insensitive search m_searchText = searchtext.Lower(); // Find all matching filenames m_items.clear(); std::vector<unsigned int> hlChars; for (unsigned int i = 0; i < m_actions.size(); ++i) AddFileIfMatching(m_searchText, m_actions[i]); sort(m_items.begin(), m_items.end()); // Check if we have a matching trigger int selection = FindMatchesAndSelection(triggers); // Update display Freeze(); SetItemCount(m_items.size()); if (m_items.empty()) SetSelection(-1); // deselect else if (selection != wxNOT_FOUND) SetSelection(selection); else SetSelection(0); RefreshAll(); Thaw(); }
// Check if we have a matching trigger int GotoFileList::FindMatchesAndSelection(const std::map<wxString,wxString>& triggers) { if (!m_items.size()) return wxNOT_FOUND; int selection = wxNOT_FOUND; std::map<wxString,wxString>::const_iterator p = triggers.find(m_searchText); if (p != triggers.end()) selection = FindPath(p->second); if (selection != wxNOT_FOUND) return selection; // Check if we have a partial match, using saved triggers for (p = triggers.begin(); p != triggers.end(); ++p) { if (!p->first.StartsWith(m_searchText)) continue; selection = FindPath(p->second); if (selection != wxNOT_FOUND) continue; // Since we have a trigger but it is not in list yet // Let's check if it exists and add it temporarily if (wxFileExists(p->second)) { m_tempEntry->SetPath(p->second); // Add entry with highlighted search chars AddFileIfMatching(m_searchText, m_tempEntry); // Find position it will end up after sort std::vector<aItem>::iterator insPos = lower_bound(m_items.begin(), m_items.end()-1, m_items.back()); selection = distance(m_items.begin(), insPos); // Move item to correct position if (m_items.size() > 1) inplace_merge(m_items.begin(), m_items.end()-1, m_items.end()); return selection; } } return selection; }
bool LafsFlat::addFile(const FileEntry& file) { WORD wEntryBuffer = 0x0000; //First bit is zero for a file int iTrailingFileSize = (static_cast<int>((file.getSize() / sizeof(WORD)) % 512 ) - 256) / 2; //Decrease one in magnitude as per spec iTrailingFileSize += (iTrailingFileSize >= 0 ? -1 : 1); WORD wEncodedTrailingSize = static_cast<WORD>(std::abs(iTrailingFileSize)); if(iTrailingFileSize < 0) wEncodedTrailingSize |= 0x80; //Set sign bit wEntryBuffer |= wEncodedTrailingSize << 7; if(m_lafsEntries.size() >= LAFS_ENTRIES_PER_FLAT) return false; m_lafsEntries.push_back(LafsEntry(wEntryBuffer, file)); return true; }
const FileEntry * FileManager::getVirtualFile(StringRef Filename, off_t Size, time_t ModificationTime) { ++NumFileLookups; // See if there is already an entry in the map. llvm::StringMapEntry<FileEntry *> &NamedFileEnt = SeenFileEntries.GetOrCreateValue(Filename); // See if there is already an entry in the map. if (NamedFileEnt.getValue() && NamedFileEnt.getValue() != NON_EXISTENT_FILE) return NamedFileEnt.getValue(); ++NumFileCacheMisses; // By default, initialize it to invalid. NamedFileEnt.setValue(NON_EXISTENT_FILE); addAncestorsAsVirtualDirs(Filename); FileEntry *UFE = 0; // Now that all ancestors of Filename are in the cache, the // following call is guaranteed to find the DirectoryEntry from the // cache. const DirectoryEntry *DirInfo = getDirectoryFromFile(*this, Filename, /*CacheFailure=*/true); assert(DirInfo && "The directory of a virtual file should already be in the cache."); // Check to see if the file exists. If so, drop the virtual file int FileDescriptor = -1; struct stat StatBuf; const char *InterndFileName = NamedFileEnt.getKeyData(); if (getStatValue(InterndFileName, StatBuf, &FileDescriptor) == 0) { // If the stat process opened the file, close it to avoid a FD leak. if (FileDescriptor != -1) close(FileDescriptor); StatBuf.st_size = Size; StatBuf.st_mtime = ModificationTime; UFE = &UniqueRealFiles.getFile(InterndFileName, StatBuf); NamedFileEnt.setValue(UFE); // If we had already opened this file, close it now so we don't // leak the descriptor. We're not going to use the file // descriptor anyway, since this is a virtual file. if (UFE->FD != -1) { close(UFE->FD); UFE->FD = -1; } // If we already have an entry with this inode, return it. if (UFE->getName()) return UFE; } if (!UFE) { UFE = new FileEntry(); VirtualFileEntries.push_back(UFE); NamedFileEnt.setValue(UFE); } UFE->Name = InterndFileName; UFE->Size = Size; UFE->ModTime = ModificationTime; UFE->Dir = DirInfo; UFE->UID = NextFileUID++; UFE->FD = -1; return UFE; }
const FileEntry * FileManager::getVirtualFile(llvm::StringRef Filename, off_t Size, time_t ModificationTime) { ++NumFileLookups; // See if there is already an entry in the map. llvm::StringMapEntry<FileEntry *> &NamedFileEnt = FileEntries.GetOrCreateValue(Filename); // See if there is already an entry in the map. if (NamedFileEnt.getValue() && NamedFileEnt.getValue() != NON_EXISTENT_FILE) return NamedFileEnt.getValue(); ++NumFileCacheMisses; // By default, initialize it to invalid. NamedFileEnt.setValue(NON_EXISTENT_FILE); // We allow the directory to not exist. If it does exist we store it. FileEntry *UFE = 0; const DirectoryEntry *DirInfo = getDirectoryFromFile(*this, Filename); if (DirInfo) { // Check to see if the file exists. If so, drop the virtual file int FileDescriptor = -1; struct stat StatBuf; const char *InterndFileName = NamedFileEnt.getKeyData(); if (getStatValue(InterndFileName, StatBuf, &FileDescriptor) == 0) { // If the stat process opened the file, close it to avoid a FD leak. if (FileDescriptor != -1) close(FileDescriptor); StatBuf.st_size = Size; StatBuf.st_mtime = ModificationTime; UFE = &UniqueFiles.getFile(InterndFileName, StatBuf); NamedFileEnt.setValue(UFE); // If we had already opened this file, close it now so we don't // leak the descriptor. We're not going to use the file // descriptor anyway, since this is a virtual file. if (UFE->FD != -1) { close(UFE->FD); UFE->FD = -1; } // If we already have an entry with this inode, return it. if (UFE->getName()) return UFE; } } if (!UFE) { UFE = new FileEntry(); VirtualFileEntries.push_back(UFE); NamedFileEnt.setValue(UFE); } // Get the null-terminated file name as stored as the key of the // FileEntries map. const char *InterndFileName = NamedFileEnt.getKeyData(); UFE->Name = InterndFileName; UFE->Size = Size; UFE->ModTime = ModificationTime; UFE->Dir = DirInfo; UFE->UID = NextFileUID++; UFE->FD = -1; return UFE; }
const FileEntry * FileManager::getVirtualFile(StringRef Filename, off_t Size, time_t ModificationTime) { ++NumFileLookups; // See if there is already an entry in the map. llvm::StringMapEntry<FileEntry *> &NamedFileEnt = SeenFileEntries.GetOrCreateValue(Filename); // See if there is already an entry in the map. if (NamedFileEnt.getValue() && NamedFileEnt.getValue() != NON_EXISTENT_FILE) return NamedFileEnt.getValue(); ++NumFileCacheMisses; // By default, initialize it to invalid. NamedFileEnt.setValue(NON_EXISTENT_FILE); addAncestorsAsVirtualDirs(Filename); FileEntry *UFE = nullptr; // Now that all ancestors of Filename are in the cache, the // following call is guaranteed to find the DirectoryEntry from the // cache. const DirectoryEntry *DirInfo = getDirectoryFromFile(*this, Filename, /*CacheFailure=*/true); assert(DirInfo && "The directory of a virtual file should already be in the cache."); // Check to see if the file exists. If so, drop the virtual file FileData Data; const char *InterndFileName = NamedFileEnt.getKeyData(); if (getStatValue(InterndFileName, Data, true, nullptr) == 0) { Data.Size = Size; Data.ModTime = ModificationTime; UFE = &UniqueRealFiles[Data.UniqueID]; NamedFileEnt.setValue(UFE); // If we had already opened this file, close it now so we don't // leak the descriptor. We're not going to use the file // descriptor anyway, since this is a virtual file. if (UFE->File) UFE->closeFile(); // If we already have an entry with this inode, return it. if (UFE->isValid()) return UFE; UFE->UniqueID = Data.UniqueID; UFE->IsNamedPipe = Data.IsNamedPipe; UFE->InPCH = Data.InPCH; } if (!UFE) { UFE = new FileEntry(); VirtualFileEntries.push_back(UFE); NamedFileEnt.setValue(UFE); } UFE->Name = InterndFileName; UFE->Size = Size; UFE->ModTime = ModificationTime; UFE->Dir = DirInfo; UFE->UID = NextFileUID++; UFE->File.reset(); return UFE; }
void Cache::dump(bool memonly) { if (!memonly) { // DUMPING DISK CACHE std::cout << "***********************\n"; std::cout << "*** DISK CACHE INFO ***\n"; std::cout << "***********************\n"; std::cout << "Capacity: " << _curDiskCacheCapacity << "\n"; std::cout << "Disk cache has " << _diskcache.right.size() << " entries\n"; DiskCache_t::right_const_iterator it = _diskcache.right.begin(); while (it != _diskcache.right.end()) { FileEntry* f = it->info; if (f->IsReady()) { std::cout << "[READY] " << it->second << " (" << f->LocalFile() << ")\n"; } else { if (f->IsFailed()) { std::cout << "[FAILED] " << it->second << "\n"; } else { std::cout << "[WAIT] " << it->second << "\n"; } } ++it; } } std::cout << "*************************\n"; std::cout << "*** MEMORY CACHE INFO ***\n"; std::cout << "*************************\n"; std::cout << "Capacity: " << _curMemoryCacheCapacity << "\n"; std::cout << "Memory cache has " << _memcache.right.size() << " entries\n"; MemoryCache_t::right_const_iterator jt = _memcache.right.begin(); while (jt != _memcache.right.end()) { MemoryEntry* m = jt->info; if (m->IsReady()) { std::cout << "[READY] " << jt->second << " (" << m->DataSize() << " bytes)\n"; } else { if (m->IsFailed()) { std::cout << "[FAILED] " << jt->second << "\n"; } else { std::cout << "[WAIT] " << jt->second << "\n"; } } jt++; } }
void Hdd::BuildTree(DirEntry* cache_dir, std::string _root) { BlockLockMutex lock(this); root = _root; if(root.empty()) throw HddAccessFailure(root); // Remove trailing / if needed if(root[root.size() -1] == '/') root = root.substr(0, root.size() -1); std::stack<std::string> path; std::string fullpath = root; DIR* d = opendir(fullpath.c_str()); if(!d) throw HddAccessFailure(root); while(1) { struct dirent* dir; FileEntry* f; while((dir = readdir(d))) { if(!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) continue; std::string f_path = fullpath + "/" + std::string(dir->d_name); struct stat stats; if(lstat(f_path.c_str(), &stats)) throw HddAccessFailure(f_path); pf_stat file_stats; file_stats.atime = stats.st_atime; file_stats.mtime = stats.st_mtime; file_stats.ctime = stats.st_ctime; // Add file if(stats.st_mode & S_IFDIR) f = new DirEntry(std::string(dir->d_name), file_stats, cache_dir); else f = new FileEntry(std::string(dir->d_name), file_stats, cache_dir); f->LoadAttr(); pf_log[W_INFO] << f->GetFullName() << " loaded."; cache_dir->AddFile(f); if(stats.st_mode & S_IFDIR) break; } if(!dir) { // End of dir, go up closedir(d); if(!path.size()) break; // Remove the last dir name from fullpath: std::string::size_type slash = fullpath.rfind("/"); fullpath = fullpath.substr(0, slash); d = opendir(fullpath.c_str()); if(!d) throw HddAccessFailure(root); // Go to the right position while((dir = readdir(d)) && strcmp(dir->d_name, path.top().c_str())) continue; if(!d) // If harddrive cache changed during reading it throw HddAccessFailure(root); path.pop(); cache_dir = cache_dir->GetParent(); } else { // Go down this dir path.push(std::string(dir->d_name)); fullpath = fullpath + "/" + std::string(dir->d_name); closedir(d); d = opendir(fullpath.c_str()); if(!d) // If harddrive cache changed during reading it throw HddAccessFailure(root); cache_dir = static_cast<DirEntry*>(f); } } }
IStream* FileStorage::WriteFile(const StringRef& path, DirectoryEntry* parent /*= nullptr*/, FileOpenMode openMode /*= FileOpenMode::DestoryWriteOrCreate*/, FileDataType dataType /*= FileDataType::Binary*/) { RETURN_NULL_IF_TRUE(IsReadOnly()); FileEntry* fileEntry = FindFile(path, parent); CoderList coders = GetFileCoders(*fileEntry); if (fileEntry == nullptr) { //not exists switch (openMode) { case FileOpenMode::ReadOnly: case FileOpenMode::ReadWrite: return nullptr; case FileOpenMode::DestoryWriteOrCreate: //create file to only write break; case FileOpenMode::DestoryReadWriteOrCreate: case FileOpenMode::AppendReadWriteClearEOFOrCreate: case FileOpenMode::AppendWriteKeepEOFOrCreate: if (coders != 0) { Log::AssertFailedFormat("Not support read & write file with coder:{}", coders); return nullptr; } ////create file to read write break; default: break; } fileEntry = FindOrCreateFileEntry(path, parent); IStream* stream = WriteFileHelper(*fileEntry, openMode, dataType); if (stream == nullptr) { RemoveFile(fileEntry); //remove back file } return stream; } else { //exists switch (openMode) { case FileOpenMode::ReadOnly: break; case FileOpenMode::ReadWrite: if (fileEntry->IsReadonly()) { Log::AssertFailedFormat("Cannot read & write readonly file:{}", path); return nullptr; } if (coders != 0) { Log::AssertFailedFormat("Not support read & write file with coder:{}", coders); return nullptr; } break; case FileOpenMode::DestoryWriteOrCreate: //use new attribute break; case FileOpenMode::AppendWriteKeepEOFOrCreate: if (coders != 0) { Log::AssertFailedFormat("Cannot append & write readonly file:{}", path); return nullptr; } break; case FileOpenMode::DestoryReadWriteOrCreate: RETURN_NULL_IF_TRUE(IsReadOnly()); if (coders != 0) { Log::AssertFailedFormat("Not support read & write file with coder:{}", coders); return nullptr; } break; case FileOpenMode::AppendReadWriteClearEOFOrCreate: if (fileEntry->IsReadonly()) { Log::AssertFailedFormat("Cannot read & write readonly file:{}", path); return nullptr; } if (GetFileCoders(*fileEntry)) { Log::AssertFailedFormat("Not support read & write file with coder:{}", coders); return nullptr; } break; default: break; } IStream* stream = WriteFileHelper(*fileEntry, openMode, dataType); RETURN_NULL_IF_NULL(stream); return stream; } }