void checkIn( const boost::program_options::variables_map & options ) { BACKTRACE_BEGIN boost::filesystem::path reportFile = options[ "reportFile" ].as< std::string >(); unsigned reportIntervalSeconds = options[ "reportIntervalSeconds" ].as< unsigned >(); boost::filesystem::path workDir = stripTrailingSlash( options[ "arg1" ].as< std::string >() ); std::string label = options[ "arg2" ].as< std::string >(); Osmosis::Chain::Chain chain( options[ "objectStores" ].as< std::string >(), false, false ); if ( chain.count() > 1 ) THROW( Error, "--objectStores must contain one object store in a checkin operation" ); bool md5 = options.count( "MD5" ) > 0; boost::filesystem::path draftsPath = workDir / Osmosis::ObjectStore::DirectoryNames::DRAFTS; if ( boost::filesystem::exists( draftsPath ) ) THROW( Error, "workDir must not contain " << draftsPath ); Osmosis::Client::CheckIn instance( workDir, label, chain.single(), md5, reportFile, reportIntervalSeconds ); instance.go(); BACKTRACE_END }
void checkOut( const boost::program_options::variables_map & options ) { BACKTRACE_BEGIN boost::filesystem::path reportFile = options[ "reportFile" ].as< std::string >(); unsigned reportIntervalSeconds = options[ "reportIntervalSeconds" ].as< unsigned >(); boost::filesystem::path workDir = stripTrailingSlash( options[ "arg1" ].as< std::string >() ); std::string label = options[ "arg2" ].as< std::string >(); bool putIfMissing = options.count( "putIfMissing" ) > 0; bool chainTouch = options.count( "noChainTouch" ) == 0; Osmosis::Chain::Chain chain( options[ "objectStores" ].as< std::string >(), putIfMissing, chainTouch ); bool md5 = options.count( "MD5" ) > 0; bool removeUnknownFiles = options.count( "removeUnknownFiles" ) > 0; bool myUIDandGIDcheckout = options.count( "myUIDandGIDcheckout" ) > 0; std::vector< std::string > ignores; if ( options.count( "ignore" ) > 0 ) boost::split( ignores, options[ "ignore" ].as< std::string >(), boost::is_any_of( ":" ) ); workDir = boost::filesystem::absolute( workDir ); std::string workDirString = workDir.string(); for ( auto & ignore : ignores ) { ignore = std::move( boost::filesystem::absolute( ignore ).string() ); if ( ignore.size() < workDirString.size() or ignore.substr( 0, workDirString.size() ) != workDirString ) THROW( Error, "ignore '" << ignore << "' is not under checkout path '" << workDirString << "'" ); TRACE_INFO( "will ignore '" << ignore << "'" ); } boost::filesystem::path draftsPath = workDir / Osmosis::ObjectStore::DirectoryNames::DRAFTS; boost::filesystem::remove_all( draftsPath ); Osmosis::FilesystemUtils::clearUMask(); Osmosis::Client::Ignores ignoresInstance( ignores ); ignoresInstance.append( draftsPath.string() ); Osmosis::Client::CheckOut instance( workDir, label, chain, md5, removeUnknownFiles, myUIDandGIDcheckout, ignoresInstance, reportFile, reportIntervalSeconds, chainTouch ); instance.go(); BACKTRACE_END }
void HTTPServer::handleRequest(HTTPRequestPtr& http_request, TCPConnectionPtr& tcp_conn) { if (! http_request->isValid()) { // the request is invalid or an error occured PION_LOG_INFO(m_logger, "Received an invalid HTTP request"); m_bad_request_handler(http_request, tcp_conn); return; } PION_LOG_DEBUG(m_logger, "Received a valid HTTP request"); // strip off trailing slash if the request has one std::string resource_requested(stripTrailingSlash(http_request->getResource())); // apply any redirection RedirectMap::const_iterator it = m_redirects.find(resource_requested); unsigned int num_redirects = 0; while (it != m_redirects.end()) { if (++num_redirects > MAX_REDIRECTS) { PION_LOG_ERROR(m_logger, "Maximum number of redirects (HTTPServer::MAX_REDIRECTS) exceeded for requested resource: " << http_request->getOriginalResource()); m_server_error_handler(http_request, tcp_conn, "Maximum number of redirects (HTTPServer::MAX_REDIRECTS) exceeded for requested resource"); return; } resource_requested = it->second; http_request->changeResource(resource_requested); it = m_redirects.find(resource_requested); } // if authentication activated, check current request if (m_auth) { // try to verify authentication if (! m_auth->handleRequest(http_request, tcp_conn)) { // the HTTP 401 message has already been sent by the authentication object PION_LOG_DEBUG(m_logger, "Authentication required for HTTP resource: " << resource_requested); if (http_request->getResource() != http_request->getOriginalResource()) { PION_LOG_DEBUG(m_logger, "Original resource requested was: " << http_request->getOriginalResource()); } return; } } // search for a handler matching the resource requested RequestHandler request_handler; if (findRequestHandler(resource_requested, request_handler)) { // try to handle the request try { request_handler(http_request, tcp_conn); PION_LOG_DEBUG(m_logger, "Found request handler for HTTP resource: " << resource_requested); if (http_request->getResource() != http_request->getOriginalResource()) { PION_LOG_DEBUG(m_logger, "Original resource requested was: " << http_request->getOriginalResource()); } } catch (HTTPResponseWriter::LostConnectionException& e) { // the connection was lost while or before sending the response PION_LOG_WARN(m_logger, "HTTP request handler: " << e.what()); tcp_conn->setLifecycle(TCPConnection::LIFECYCLE_CLOSE); // make sure it will get closed tcp_conn->finish(); } catch (std::bad_alloc&) { // propagate memory errors (FATAL) throw; } catch (std::exception& e) { // recover gracefully from other exceptions thrown request handlers PION_LOG_ERROR(m_logger, "HTTP request handler: " << e.what()); m_server_error_handler(http_request, tcp_conn, e.what()); } } else { // no web services found that could handle the request PION_LOG_INFO(m_logger, "No HTTP request handlers found for resource: " << resource_requested); if (http_request->getResource() != http_request->getOriginalResource()) { PION_LOG_DEBUG(m_logger, "Original resource requested was: " << http_request->getOriginalResource()); } m_not_found_handler(http_request, tcp_conn); } }