int main(int argc, char **argv) { if (argc != 3) { printf("Usage: %s mmap_directory revision_input_file\n", argv[0]); exit(1); } struct revision_stats stats; get_file_stats(argv[2], &stats); printf("%d max user, %d max page, %"PRId64" max revision, %"PRId64" total revisions\n", stats.max_user_id, stats.max_page_id, stats.max_revision_id, stats.total_revisions); char *user_index_mmap_name = full_path(argv[1], USER_INDEX_MMAP_NAME); char *page_index_mmap_name = full_path(argv[1], PAGE_INDEX_MMAP_NAME); char *revisions_mmap_name = full_path(argv[1], REVISIONS_MMAP_NAME); char *user_index_mmap = create_mmap(user_index_mmap_name, user_index_mmap_size(&stats)); char *page_index_mmap = create_mmap(page_index_mmap_name, page_index_mmap_size(&stats)); char *revisions_mmap = create_mmap(revisions_mmap_name, revision_mmap_size(&stats)); ((struct user_header*)user_index_mmap)->count_users = stats.max_user_id + 1; ((struct page_header*)page_index_mmap)->count_pages = stats.max_page_id + 1; ((struct revision_header*)revisions_mmap)->count_revisions = stats.max_revision_id + 1; fill_mmaps(argv[2], &stats, user_index_mmap, page_index_mmap, revisions_mmap); free(user_index_mmap_name); free(page_index_mmap_name); free(revisions_mmap_name); return 0; }
int old(char* filename) { char * ffpath = full_path(filename,".md5"); char * tspath = full_path(COMPDIR,ffpath); free(ffpath); int ol = 1; if (file_exists(tspath) && file_exists(filename)) { FILE * f = fopen(tspath,"r"); char * inner = read_entire_file(f); fclose(f); inner[strlen(inner)-1]=0; struct stat file_stat; stat(filename,&file_stat); if(DEBUG){ fprintf(stderr,"%s:%d %s:%d\n",tspath,atoi(inner),filename,file_stat.st_mtime); fflush(stderr); } if(file_stat.st_mtime<=atoi(inner)) { ol = 0; } else { ol = 1; } free(inner); } free(tspath); return ol; }
void cOverworld_Manager :: Load_Dir( const std::string &dir, bool user_dir /* = 0 */ ) { // set world directory // fixme : boost should use a codecvt_facet but for now we convert to UCS-2 #ifdef _WIN32 fs::path full_path( utf8_to_ucs2( dir ) ); #else fs::path full_path( dir ); #endif fs::directory_iterator end_iter; for( fs::directory_iterator dir_itr( full_path ); dir_itr != end_iter; ++dir_itr ) { try { std::string current_dir = dir_itr->path().filename().string(); // only directories with an existing description if( fs::is_directory( *dir_itr ) && File_Exists( dir + "/" + current_dir + "/description.xml" ) ) { cOverworld *overworld = Get_from_Path( current_dir ); // already available if( overworld ) { overworld->m_description->m_user = 2; continue; } overworld = new cOverworld(); // set path overworld->m_description->m_path = current_dir; // default name is the path overworld->m_description->m_name = current_dir; // set user overworld->m_description->m_user = user_dir; objects.push_back( overworld ); overworld->Load(); } } catch( const std::exception &ex ) { printf( "%s %s\n", dir_itr->path().filename().string().c_str(), ex.what() ); } } }
void FileSystemMap::CreateMap(string const& MountPoint) { fs::path full_path(fs::initial_path<fs::path>()); full_path = fs::system_complete(fs::path(MountPoint)); if (!fs::exists(full_path)) { BOOST_THROW_EXCEPTION( invalid_argument(string(MountPoint).append(" Not found"))); } if (fs::is_directory(full_path)) { BuildMap(full_path); } else { BOOST_THROW_EXCEPTION( invalid_argument( string("Expecting directory, found :").append( full_path.c_str()))); } #ifdef __DEBUG__FSM std::cout << "\n" << FileCount << " files\n" << DirCount << " directories\n" << OtherCount << " others\n" << ErrCount << " errors\n"; #endif return; }
void cFontLoader:: ExportDFFToFile(tDistanceFontHandle font, const Twine& in_path /*= ""*/) { auto& dff = DistanceFont(font); size_t face_size = cSerialization::SerializedSize(dff.Face()); cDFFFile pair(dff, face_size); AlignedBuffer<16> buffer; cSerialization::SerializeLZMA(pair,buffer); cStringRef file_data(buffer.ptr<char>(), buffer.size()); try{ if (sys::path::has_filename(in_path)) { WriteFileToDisk(file_data, in_path); } else { cSmallVector<char, 256> path_buf; cStringRef temp_path = in_path.toNullTerminatedStringRef(path_buf); sys::path::append(path_buf, in_path, dff.FontName() + ".dff"); cStringRef full_path(path_buf.data(), path_buf.size()); WriteFileToDisk(file_data, full_path); } } catch (const Exception& e) { Log::Warn("Swallowed exception while trying to write dff file: %s", e.what()); } }
void TexManager::loadTexture(string filename, bool alpha) { unsigned int flags = SOIL_FLAG_MIPMAPS; if (alpha) flags = flags | SOIL_FLAG_MULTIPLY_ALPHA; #ifdef DEVICE char app_dir[256]; PDL_GetCallingPath(app_dir, 256); string full_path(app_dir); full_path.append(filename); #else string full_path = filename; #endif inst->texture[inst->texture_ref] = SOIL_load_OGL_texture ( full_path.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, flags ); if (inst->texture[inst->texture_ref] == 0) { printf( "SOIL loading error: '%s'\n", SOIL_last_result() ); } else { printf("loaded\n"); } inst->texture_ref++; }
std::string appendFilename(const std::string parent_path, const std::string filename) { boost::filesystem::path full_path(parent_path); full_path /= filename; // appends filename to full_path with the preferred separator return full_path.make_preferred().string(); }
static int expand_path(const char *name, int fullp, int nt, int dt, int rv) {int i, nc, ok; char *fname; char pname[PATH_MAX], rname[PATH_MAX+1]; nc = PATH_MAX - 1; ok = 1; if (fullp == TRUE) {ok = full_path(pname, nc, 1, NULL, name); if (ok != 0) rv |= 1;}; if (ok != 0) nstrncpy(pname, PATH_MAX, name, -1); fname = NULL; for (i = 0; i < nt; i++) {fname = realpath(pname, rname); if (fname == NULL) sleep(dt); else break;}; if (fname == NULL) {if (nt > 0) rv |= 2; fprintf(stdout, "%s\n", pname);} else fprintf(stdout, "%s\n", rname); return(rv);}
int metafile::unlink(int dfd, const char * name, bool recursive) { scopelock scope(mf_map_lock); istr path = full_path(dfd, name); if(!path) return -1; MF_S_DEBUG("%s", path.str()); mf_map_t::iterator itr = mf_map.find(path); if(itr != mf_map.end()) { if(itr->second->usage) { fprintf(stderr, "Warning: tried to unlink open metafile %s\n", path.str()); return -EBUSY; } /* flush it, in case something later fails */ itr->second->flush(); delete itr->second; } uint8_t type = recursive ? MF_TX_RM_R : MF_TX_UNLINK; uint16_t path_len = path.length(); journal::ovec ov[3] = {{&type, sizeof(type)}, {&path_len, sizeof(path_len)}, {&path[0], path_len}}; assert(current_journal); return current_journal->appendv(ov, 3); }
::int64_t StockReply::contentLength() { std::string full_path(configuration().errRoot() + stock_replies::toName(status())); std::string original_url; std::string content = ""; std::string line; size_t clen = content_.length(); std::ifstream ifstr(full_path.c_str(), std::ios::in | std::ios::binary); while (ifstr.good() && !ifstr.eof()) { std::getline(ifstr, line); size_t index = 0; while ((index = line.find("<-- SPECIAL CONTENT -->", index)) != line.npos) { line.replace(index,sizeof("<-- SPECIAL CONTENT -->")-1, content_); index += clen; } index = line.find("<-- ORIGINAL URL -->"); if (index != line.npos) { stock_replies::buildOriginalURL(request_, original_url); clen = original_url.length(); do { line.replace(index,sizeof("<-- ORIGINAL URL -->")-1, original_url); index += clen; } while((index = line.find("<-- ORIGINAL URL -->", index) != line.npos)); } index = line.find("<-- ORIGINAL URL ESCAPED -->"); if (index != line.npos) { if (original_url.empty()) stock_replies::buildOriginalURL(request_, original_url); std::string escapedUrl = Wt::Utils::urlEncode(original_url); clen = escapedUrl.length(); do { line.replace(index,sizeof("<-- ORIGINAL URL ESCAPED -->") - 1, escapedUrl); index += clen; } while((index = line.find("<-- ORIGINAL URL ESCAPED -->", index) != line.npos)); } content += line + "\r\n"; } ifstr.close(); if (content.empty()) content_ = stock_replies::toText(status()) + content_; else content_ = content; return content_.length(); }
void filesystem_enumerate_callback(void *data, const char *directory, const char *filename) { std::list<std::string> *list = (std::list<std::string> *)data; std::string full_path(directory); full_path.append("/"); full_path.append(filename); list->push_back(full_path); }
void AssetBrowser::openInExternalEditor(const char* path) { if (m_editor.getEngine().getPatchFileDevice()) { Lumix::StaticString<Lumix::MAX_PATH_LENGTH> full_path(m_editor.getEngine().getPatchFileDevice()->getBasePath()); full_path << path; if (PlatformInterface::fileExists(full_path)) { PlatformInterface::shellExecuteOpen(full_path); return; } } Lumix::StaticString<Lumix::MAX_PATH_LENGTH> full_path(m_editor.getEngine().getDiskFileDevice()->getBasePath()); full_path << path; PlatformInterface::shellExecuteOpen(full_path); }
string Unix_Utility::get_cwd() { fs::path full_path(fs::initial_path<fs::path>() ); full_path = fs::system_complete( "." ); string tmp_str = full_path.file_string(); tmp_str.erase( tmp_str.size() - 1 ); return tmp_str; }
// OgreScriptBuilder int OgreScriptBuilder::LoadScriptSection(const char* full_path_cstr) { // Get filename - required to retrieve file from OGRe's resource system. // This function received filename in older AngelScript versions, but now receives full path // (reconstructed wrong by CScriptBuilder because it doesn't know about OGRE's ZIP files). // TODO: Refactor the entire script building logic // - create fully RoR-custom builder instead of hacked stock CScriptBuilder + our overload. ~ only_a_ptr, 08/2017 std::string full_path(full_path_cstr); std::string filename; size_t slash_pos = full_path.rfind('/'); // AngelScript always uses forward slashes in paths. if (slash_pos != std::string::npos) { filename = full_path.substr(slash_pos+1); } else { filename = full_path; } Ogre::DataStreamPtr ds; try { ds = Ogre::ResourceGroupManager::getSingleton().openResource(filename, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME); //TODO: do not use `AUTODETECT_RESOURCE_GROUP_NAME`, use specific group, lookups are slow! //see also https://github.com/OGRECave/ogre/blob/master/Docs/1.10-Notes.md#resourcemanager-strict-mode ~ only_a_ptr, 08/2017 } catch (Ogre::Exception e) { LOG("[RoR|Scripting] exception upon loading script file '"+filename+"', message: " + e.getFullDescription()); return -1; } // In some cases (i.e. when fed a full path with '/'-s on Windows), `openResource()` will silently return NULL for datastream. ~ only_a_ptr, 08/2017 if (ds.isNull()) { LOG("[RoR|Scripting] Failed to load file '"+filename+"', reason unknown."); return -1; } // Read the entire file std::string code; code.resize(ds->size()); ds->read(&code[0], ds->size()); // hash it { char hash_result[250]; memset(hash_result, 0, 249); RoR::CSHA1 sha1; sha1.UpdateHash((uint8_t *)code.c_str(), (uint32_t)code.size()); sha1.Final(); sha1.ReportHash(hash_result, RoR::CSHA1::REPORT_HEX_SHORT); hash = Ogre::String(hash_result); } return ProcessScriptSection(code.c_str(), code.length(), filename.c_str(), 0); }
BlockInputStreams StorageStripeLog::read( const Names & column_names, const SelectQueryInfo & /*query_info*/, const Context & context, QueryProcessingStage::Enum & processed_stage, const size_t /*max_block_size*/, unsigned num_streams) { std::shared_lock<std::shared_mutex> lock(rwlock); check(column_names); processed_stage = QueryProcessingStage::FetchColumns; NameSet column_names_set(column_names.begin(), column_names.end()); if (!Poco::File(full_path() + "index.mrk").exists()) return { std::make_shared<NullBlockInputStream>() }; CompressedReadBufferFromFile index_in(full_path() + "index.mrk", 0, 0, INDEX_BUFFER_SIZE); std::shared_ptr<const IndexForNativeFormat> index{std::make_shared<IndexForNativeFormat>(index_in, column_names_set)}; BlockInputStreams res; size_t size = index->blocks.size(); if (num_streams > size) num_streams = size; for (size_t stream = 0; stream < num_streams; ++stream) { IndexForNativeFormat::Blocks::const_iterator begin = index->blocks.begin(); IndexForNativeFormat::Blocks::const_iterator end = index->blocks.begin(); std::advance(begin, stream * size / num_streams); std::advance(end, (stream + 1) * size / num_streams); res.emplace_back(std::make_shared<StripeLogBlockInputStream>( *this, context.getSettingsRef().max_read_buffer_size, index, begin, end)); } /// We do not keep read lock directly at the time of reading, because we read ranges of data that do not change. return res; }
QString XmlLookupTable::lookup(const QString &path, bool *ok) const { QHash<QString, Entry>::ConstIterator it = m_data.find(full_path(path)); bool found = (it != m_data.end()); if (ok) *ok = found; if (found) return it->data; else return QString(); // default }
Directory::Ptr Directory::get_subdir(const char* name) { ACE_TString t_name = ACE_TEXT_CHAR_TO_TCHAR(name); Map::iterator it = dirs_.find(t_name); if (it == dirs_.end()) { return make_new_subdir(t_name); } else { return new Directory(full_path(it->second), it->first, this); } }
void AssetBrowser::openInExternalEditor(const char* path) { StringBuilder<Lumix::MAX_PATH_LENGTH> full_path(m_editor.getEngine().getDiskFileDevice()->getBasePath(0)); full_path << path; if (!PlatformInterface::fileExists(path)) { full_path.data[0] = 0; full_path << m_editor.getEngine().getDiskFileDevice()->getBasePath(0); full_path << path; } PlatformInterface::shellExecuteOpen(full_path); }
static std::string MakeProjectTitle(bool with_path_breakdown = false) { ADatabase& db = AData(); if( !db.IsProjectSet() ) return "untitled.bmd"; fs::path full_path(db.GetProjectFName()); std::string res_str = fs::name_str(full_path); if( with_path_breakdown ) res_str += " (" + full_path.branch_path().string() + ")"; return res_str; }
metafile * metafile::open(int dfd, const char * name, bool create) { int fd; metafile * fp = NULL; mf_map_t::iterator itr; scopelock scope(mf_map_lock); istr path = full_path(dfd, name); if(!path) return NULL; MF_S_DEBUG("%s", path.str()); itr = mf_map.find(path); if(itr != mf_map.end()) { MF_S_DEBUG("cached"); itr->second->usage++; return itr->second; } /* open read-write just to make sure we can */ fd = openat(dfd, name, O_RDWR); if(fd < 0) { /* side effect: may non-transactionally create an empty file */ fd = openat(dfd, name, O_RDWR | O_CREAT, 0644); if(fd < 0) return NULL; fp = new metafile(path); if(!fp) goto fail_close; } else { struct stat st; if(fstat(fd, &st) < 0) goto fail_close; fp = new metafile(path); if(!fp) goto fail_close; if(fp->data.set_size(st.st_size, false) < 0) goto fail_delete; if(st.st_size && pread(fd, &fp->data[0], st.st_size, 0) != st.st_size) goto fail_delete; } ::close(fd); return fp; fail_delete: delete fp; fail_close: ::close(fd); return NULL; }
void Dictionary::loadDictionary() { // Make sure data dictionary is loaded if (!dcmDataDict.isDictionaryLoaded()) { ::boost::filesystem::path full_path(::boost::filesystem::initial_path< ::boost::filesystem::path >()); std::string dicoPath = full_path.string() + "/share/" + PRJ_NAME + "_" + FWDICOMIOEXT_VER + "/dicom.dic"; bool loaded = dcmDataDict.wrlock().loadDictionary(dicoPath.c_str()); dcmDataDict.unlock(); SLM_ASSERT("Unable to load DICOM dictionary !", loaded); SLM_TRACE("DICOM dictionary loaded !"); } }
bool file_utils::create_directories(const dynamic_string &path, bool remove_filename) { dynamic_string path_to_create(path); full_path(path_to_create); if (remove_filename) { dynamic_string pn, fn; split_path(path_to_create.get_ptr(), pn, fn); path_to_create = pn; } return create_directories_from_full_path(path_to_create); }
/*static*/ void CompilerTools::retrive_obj_path(const std::vector<std::string> &tokens, std::string &obj_path, std::string &obj_file) { std::string path; std::vector<std::string>::const_iterator fo_itor = std::find_if(tokens.begin(), tokens.end(), string_finder_pred("/Fo")); if(fo_itor != tokens.end()) path = ((*fo_itor).substr(3)); StringTools::str_replace(path, "\\\\", "\\"); StringTools::str_replace(path, "//", "//"); StringTools::str_replace(path, "\"", ""); boost::filesystem::path full_path(path); obj_path = full_path.branch_path().string(); obj_file = full_path.filename().string(); }
File::Ptr Directory::get_file(const char* name) { if (std::strlen(name) >= FSS_MAX_FILE_NAME) { throw std::runtime_error("file name too long"); } ACE_TString t_name(ACE_TEXT_CHAR_TO_TCHAR(name)); Map::iterator it = files_.find(t_name); if (it == files_.end()) { return make_new_file(t_name); } else { return new File(full_path(it->second), it->first, this); } }
inline std::wstring GetFullPathNameWrapper(std::wstring const& path) { std::vector<wchar_t> full_path(HADESMEM_DETAIL_MAX_PATH_UNICODE); DWORD len = GetFullPathNameW(path.c_str(), static_cast<DWORD>(full_path.size()), full_path.data(), nullptr); if (!len || full_path.size() < len) { DWORD const last_error = ::GetLastError(); HADESMEM_DETAIL_THROW_EXCEPTION( Error{} << ErrorString{"GetFullPathNameW failed."} << ErrorCodeWinLast{last_error} << ErrorCodeWinOther{len}); } return full_path.data(); }
value guestfs_int_mllib_full_path (value dirv, value namev) { CAMLparam2 (dirv, namev); CAMLlocal1 (rv); const char *name = NULL; char *ret; if (namev != Val_int (0)) name = String_val (Field (namev, 0)); ret = full_path (String_val (dirv), name); rv = caml_copy_string (ret); free (ret); CAMLreturn (rv); }
/* Is the given file replaced. Returns the replace name or NULL */ char* is_replaced(const char* filename){ int i, count = (sizeof replaced_files) / (sizeof (struct replaced_file)); char *full_name = full_path(filename); char *name = basename(full_name); strcpy(max_path, filename); char *dname = dirname(max_path); for(i = 0; i < count; i++){ if(!strcmp(name, replaced_files[i].original)){ if(!strcmp(dname, ".")){ sprintf(max_path, "%s", replaced_files[i].replace); } else sprintf(max_path, "%s/%s", dname, replaced_files[i].replace); return max_path; } } return NULL; }
int main( int argc, char* argv[] ) { fs::path full_path( fs::initial_path<fs::path>()); if ( argc > 1 ) { full_path = fs::system_complete( fs::path( argv[1])); } else { std::cout << "\nUsage: directoryScan [path]" << std::endl; return 0; } if (!fs::exists(full_path)) { std::cout << "\nNot found: " << full_path.string() << std::endl; return 0; } if (fs::is_directory(full_path)) { //std::vector<fs::path> ret; unsigned long file_count = 0; std::cout<<"Is a valid directory"<<std::endl; const std::string ext = ".pcd"; fs::recursive_directory_iterator it(full_path); fs::recursive_directory_iterator endit; while(it != endit) { if(fs::is_regular_file(*it) && it->path().extension() == ext) { std::cout<<it->path().filename()<<std::endl; ++file_count; //ret.push_back(it->path().filename()); } ++it; } } return 1; }
// test helpers std::string fixture_load(const std::string & fname) { // glue paths together boost::filesystem::path full_path(FIXTURES_DIR); full_path /= fname.c_str(); // get a suitable string std::string abs_fname = boost::filesystem::canonical(full_path).string(); uintmax_t size = boost::filesystem::file_size(full_path); // read the file into the vector std::vector<char>(size).swap(m_data); std::ifstream input(abs_fname.c_str()); input.read(&m_data[0], size); return abs_fname; }
/** * Get the cached file as well as metadata associated with it. * * @return if the file exists on disk, a shared_ptr to the * CachedFile object associated with the file; NULL shared_ptr * otherwise. If the file is not in cache, it will be automatically * loaded. If the cached object is out of date, it will be refreshed. */ bool FileCache::get_cached_object(const std::string& file_path, CachedFilePtr& cached_file) { //Check if the file is already being cached. CachedFilesMap::const_iterator it = cached_files_.find(file_path); if (it == cached_files_.end()) { //Start caching the file. std::string full_path(file_root_ + file_path); cached_file = CachedFilePtr(new CachedFile(full_path, expiration_period_)); cached_files_[file_path] = cached_file; } else { cached_file = it->second; } //Get the file contents. const bool found_file = cached_file->refresh_if_expired(); return found_file; }