void ConnectionClient::startProcess() { TIME_SCOPE_DURATION("ConnectionClient::startProcess"); if (!isProcessIsRunning()) { connectProcessFinished(); connectStandardOutputAndError(); process()->start(processPath(), {connectionName()}); process()->waitForStarted(); resetProcessAliveTimer(); } }
void BilateralBFS::solve() { while(findAugmentingPath()) { processPath(); } int numEdgesInMatching = computeMatchset(); computeInvitees(); if(invitees.size() != numEdgesInMatching){ std::cerr << "Num edges in matching: " << numEdgesInMatching << " does not equal num invitees: " << invitees.size() << "!!!" << std::endl; } }
void FormMain::setFolders( const QListWidget & cur, const QListWidget & exc ) { qApp->setOverrideCursor( Qt::WaitCursor ); for ( int i = 0; i < cur.count(); ++i ) { qint64 commonSize = 0; QTreeWidgetItem * rootItem = processPath( cur.item( i )->text(), commonSize, exc ); if ( rootItem ) tree->addTopLevelItem( rootItem ); } qApp->restoreOverrideCursor(); statusBar()->showMessage( "Finished", 3000 ); // 3 seconds }
QString QgsWFSUtils::getCacheDirectory( bool createIfNotExisting ) { QString baseDirectory( getBaseCacheDirectory( createIfNotExisting ) ); QString processPath( QStringLiteral( "pid_%1" ).arg( QCoreApplication::applicationPid() ) ); if ( createIfNotExisting ) { QMutexLocker locker( &sMutex ); if ( !QDir( baseDirectory ).exists( processPath ) ) { QgsDebugMsg( QString( "Creating our cache dir %1/%2" ).arg( baseDirectory, processPath ) ); QDir( baseDirectory ).mkpath( processPath ); } if ( sCounter == 0 && sKeepAliveWorks ) { sThread = new QgsWFSUtilsKeepAlive(); sThread->start(); } sCounter ++; } return QDir( baseDirectory ).filePath( processPath ); }
void InMemoryView::crawler( const std::shared_ptr<w_root_t>& root, SyncView::LockedPtr& view, PendingCollection::LockedPtr& coll, const w_string& dir_name, struct timeval now, bool recursive) { struct watchman_file *file; const watchman_dir_ent* dirent; char path[WATCHMAN_NAME_MAX]; bool stat_all = false; if (watcher_->flags & WATCHER_HAS_PER_FILE_NOTIFICATIONS) { stat_all = watcher_->flags & WATCHER_COALESCED_RENAME; } else { // If the watcher doesn't give us per-file notifications for // watched dirs, then we'll end up explicitly tracking them // and will get updates for the files explicitly. // We don't need to look at the files again when we crawl stat_all = false; } auto dir = resolveDir(view, dir_name, true); // Detect root directory replacement. // The inode number check is handled more generally by the sister code // in stat.cpp. We need to special case it for the root because we never // generate a watchman_file node for the root and thus never call // InMemoryView::statPath (we'll fault if we do!). // Ideally the kernel would have given us a signal when we've been replaced // but some filesystems (eg: BTRFS) do not emit appropriate inotify events // for things like subvolume deletes. We've seen situations where the // root has been replaced and we got no notifications at all and this has // left the cookie sync mechanism broken forever. if (dir_name == root->root_path) { try { auto st = getFileInformation(dir_name.c_str(), root->case_sensitive); if (st.ino != view->rootInode) { // If it still exists and the inode doesn't match, then we need // to force recrawl to make sure we're in sync. // We're lazily initializing the rootInode to 0 here, so we don't // need to do this the first time through (we're already crawling // everything in that case). if (view->rootInode != 0) { root->scheduleRecrawl( "root was replaced and we didn't get notified by the kernel"); return; } recursive = true; view->rootInode = st.ino; } } catch (const std::system_error& err) { handle_open_errno(root, dir, now, "getFileInformation", err.code()); markDirDeleted(view, dir, now, true); return; } } memcpy(path, dir_name.data(), dir_name.size()); path[dir_name.size()] = 0; w_log(W_LOG_DBG, "opendir(%s) recursive=%s\n", path, recursive ? "true" : "false"); /* Start watching and open the dir for crawling. * Whether we open the dir prior to watching or after is watcher specific, * so the operations are rolled together in our abstraction */ std::unique_ptr<watchman_dir_handle> osdir; try { osdir = watcher_->startWatchDir(root, dir, path); } catch (const std::system_error& err) { handle_open_errno(root, dir, now, "opendir", err.code()); markDirDeleted(view, dir, now, true); return; } if (dir->files.empty()) { // Pre-size our hash(es) if we can, so that we can avoid collisions // and re-hashing during initial crawl uint32_t num_dirs = 0; #ifndef _WIN32 struct stat st; int dfd = osdir->getFd(); if (dfd != -1 && fstat(dfd, &st) == 0) { num_dirs = (uint32_t)st.st_nlink; } #endif // st.st_nlink is usually number of dirs + 2 (., ..). // If it is less than 2 then it doesn't follow that convention. // We just pass it through for the dir size hint and the hash // table implementation will round that up to the next power of 2 apply_dir_size_hint( dir, num_dirs, uint32_t(root->config.getInt("hint_num_files_per_dir", 64))); } /* flag for delete detection */ for (auto& it : dir->files) { auto file = it.second.get(); if (file->exists) { file->maybe_deleted = true; } } try { while ((dirent = osdir->readDir()) != nullptr) { // Don't follow parent/self links if (dirent->d_name[0] == '.' && (!strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, ".."))) { continue; } // Queue it up for analysis if the file is newly existing w_string name(dirent->d_name, W_STRING_BYTE); file = dir->getChildFile(name); if (file) { file->maybe_deleted = false; } if (!file || !file->exists || stat_all || recursive) { auto full_path = dir->getFullPathToChild(name); w_log( W_LOG_DBG, "in crawler calling process_path on %s\n", full_path.c_str()); processPath( root, view, coll, full_path, now, ((recursive || !file || !file->exists) ? W_PENDING_RECURSIVE : 0), dirent); } } } catch (const std::system_error& exc) { log(ERR, "Error while reading dir ", path, ": ", exc.what(), ", re-adding to pending list to re-assess\n"); coll->add(path, now, 0); } osdir.reset(); // Anything still in maybe_deleted is actually deleted. // Arrange to re-process it shortly for (auto& it : dir->files) { auto file = it.second.get(); if (file->exists && (file->maybe_deleted || (file->stat.isDir() && recursive))) { coll->add( dir, file->getName().data(), now, recursive ? W_PENDING_RECURSIVE : 0); } } }
bool Mesh::initMaterials(const aiScene* pScene, const std::string& Filename) { // Extract the directory part from the file name std::string::size_type slashIndex = Filename.find_last_of("/"); std::string dir; if (slashIndex == std::string::npos) { dir = "."; } else if (slashIndex == 0) { dir = "/"; } else { dir = Filename.substr(0, slashIndex); } bool res = true; // Initialize the materials for (unsigned int i = 0; i < pScene->mNumMaterials; i++) { const aiMaterial* pMaterial = pScene->mMaterials[i]; textures[i] = NULL; if (pMaterial->GetTextureCount(aiTextureType_DIFFUSE) > 0) { aiString Path; if (pMaterial->GetTexture(aiTextureType_UNKNOWN, 0, &Path, NULL, NULL, NULL, NULL, NULL) == AI_SUCCESS) { StringPathUPtr sp = processPath(std::string(Path.data)); std::string FullPath = dir + "/" + sp->filename; textures[i] = std::unique_ptr<Texture>(new Texture(GL_TEXTURE_2D, FullPath.c_str())); if (!textures[i]->load()) { printf("Error loading texture '%s'\n", FullPath.c_str()); res = false; } else { printf("Loaded texture '%s'\n", FullPath.c_str()); } } } // Load a white texture in case the model does not include its own texture if (!textures[i]) { textures[i] = std::unique_ptr<Texture>(new Texture(GL_TEXTURE_2D, config.getFallbackTexture())); res = textures[i]->load(); } } return res; }
int main(int argc, char *argv[]) { // // Build the default directory for the schema files std::string processPath(queryCurrentProcessPath()); configSchemaDir = processPath.substr(0, processPath.find_last_of(PATHSEPSTR)) + PATHSEPSTR + configSchemaRelativeDir; if (argc == 1) { usage(); return 0; } // // Read options and validate if (!processOptions(argc, argv)) { return 1; // get out now } if (!validate()) { usage(); return 1; } // // Create an environment manager reference and load the schema try { pEnvMgr = getEnvironmentMgrInstance(envType); std::cout << "Loading schema defined by " << masterSchemaFile << "..."; // note that these are hardcoded for HPCC at this time, but could be made into options std::map<std::string, std::string> cfgParms; cfgParms["buildset"] = "buildset.xml"; // Not used right now, and probably never will be cfgParms["support_libs"] = "libcfgsupport_addrequiredinstances"; std::string pluginsPath = configSchemaPluginsDir; if (!pEnvMgr->loadSchema(configSchemaDir, masterSchemaFile, cfgParms)) { throw CliException(pEnvMgr->getLastSchemaMessage()); } } catch (const ParseException &pe) { std::cout << "There was a problem creating the environment manager instance: " << pe.what() << std::endl; } catch(const CliException &e) { std::cout << "There was a problem loading the schema: " << e.what() << std::endl; } // // Create the modification template try { pTemplate = new EnvModTemplate(pEnvMgr, modTemplateSchemaFile); pTemplate->loadTemplateFromFile(modTemplateFile); } catch (const TemplateException &te) { std::cout << "There was a problem loading the modification template: " << te.what() << std::endl; return 1; } // // If list inputs was given, list them and get out if (listInputs) { std::cout << "Template inputs:" << std::endl; auto templateInputs = pTemplate->getVariables(); for (auto &pInput : templateInputs) { std::cout << pInput->getName() << " - " << pInput->getDescription() << std::endl; } return 0; // get out } // // Process the input file if given here // // If the user provided any inputs, assign them if (!userInputs.empty()) { for (auto &userInput: userInputs) { try { auto pInput = pTemplate->getVariable(userInput.inputName); auto values = splitString(userInput.inputValue, ","); for (auto &value: values) { pInput->addValue(value); } } catch (const TemplateException &te) { std::cout << "There was a problem: " << te.what() << std::endl; return 0; // get out } } } // // If there is an environment, load it and apply if (!envFile.empty()) { if (!pEnvMgr->loadEnvironment(envFile)) { std::cout << "There was a problem loading the environment: " << std::endl << pEnvMgr->getLastEnvironmentMessage() << std::endl; return 1; } try { pTemplate->execute(); } catch (const TemplateExecutionException &te) { std::cout << te.what() << std::endl; return 1; } // // Write results if (!envOutputFile.empty()) { pEnvMgr->saveEnvironment(envOutputFile); std::cout << "Results written to " << envOutputFile << std::endl; } else { std::cout << "Resuls not saved." << std::endl; } } else { std::cout << "No problems found in the modification template" << std::endl; } std::cout << "Done" << std::endl; return 0; }
QTreeWidgetItem * FormMain::processPath( const QString & path, qint64 & dirSize, const QListWidget & exc, int parent_id ) { statusBar()->showMessage( path ); qApp->processEvents(); QDir dir( path ); if ( ! dir.exists() ) return 0; const int dbDirId = dbSaveFolder( dir, parent_id ); if ( dbDirId == -1 ) return 0; QTreeWidgetItem * item = new QTreeWidgetItem(); item->setIcon( 0, QIcon(":/blue.png" ) ); if ( dir.isRoot() ) item->setText( 0, dir.rootPath() ); else item->setText( 0, dir.dirName() ); item->setData( 0, Qt::UserRole, dbDirId ); qint64 dir_size = 0; // folders QFileInfoList list = dir.entryInfoList( QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Drives, QDir::Name ); const int dirCount = list.size(); for ( int i = 0; i < list.size(); ++i ) { /* if ( exclude( list[ i ] ) ) continue; */ bool e = false; for ( int j = 0; j < exc.count(); ++j ) if ( list[ i ].absoluteFilePath() == exc.item( j )->text() ) { e = true; break; } if ( e ) continue; item->addChild( processPath( list[ i ].absoluteFilePath(), dir_size, exc, dbDirId ) ); } // files list = dir.entryInfoList( QDir::Files | QDir::Hidden | QDir::System, QDir::Type ); #ifdef DEBUG qDebug() << "files count: " << dir.dirName() << list.size(); #endif for ( int i = 0; i < list.size(); ++ i ) { dbSaveFile( list[ i ], dbDirId ); dir_size += list[ i ].size(); } // percents QHash< QString, int > counts; for ( int i = 0; i < list.size(); ++i ) { const QString suffix = list[ i ].suffix().toLower(); if ( counts.contains( suffix ) ) counts[ suffix ] += 1; else counts[ suffix ] = 1; } dbSavePercents( counts, dbDirId, dirCount + list.size() ); dbSaveFolderSize( dbDirId, dir_size ); dirSize += dir_size; return item; }