Exemplo n.º 1
0
    /*
     * Update repository information and return thre repoId, otherwise empty 
     * string.
     */
    void updateRepo(const string &path) {
        RepoControl repo = RepoControl(path);
        RepoInfo info;

        try {
            repo.open();
        } catch (SystemException &e) {
            WARNING("Failed to open repository %s: %s", path.c_str(), e.what());
            return;
        }

        RWKey::sp key = infoLock.writeLock();
        if (myInfo.hasRepo(repo.getUUID())) {
            info = myInfo.getRepo(repo.getUUID());
        } else {
            info = RepoInfo(repo.getUUID(), repo.getPath());
        }
        info.updateHead(repo.getHead());
        myInfo.updateRepo(repo.getUUID(), info);

        LOG("Checked %s: %s %s", path.c_str(), repo.getHead().c_str(), repo.getUUID().c_str());
        
        repo.close();

        return;
    }
Exemplo n.º 2
0
			QList<QUrl> Core::GetPackageURLs (int packageId) const
			{
				QList<QUrl> result;

				QMap<int, QList<QString> > repo2cmpt = Storage_->GetPackageLocations (packageId);

				PackageShortInfo info = Storage_->GetPackage (packageId);
				QString pathAddition = QString ("dists/%1/all/");
				QString normalized = NormalizePackageName (info.Name_);
				pathAddition += QString ("%1/%1-%2.tar.gz")
						.arg (normalized)
						.arg (info.Versions_.at (0));

				Q_FOREACH (int repoId, repo2cmpt.keys ())
				{
					RepoInfo ri = Storage_->GetRepo (repoId);
					QUrl url = ri.GetUrl ();
					QString path = url.path ();
					if (!path.endsWith ('/'))
						path += '/';

					Q_FOREACH (const QString& component, repo2cmpt [repoId])
					{
						QUrl tmp = url;
						tmp.setPath (path + pathAddition.arg (component));
						result << tmp;
					}
				}
Exemplo n.º 3
0
	QList<QUrl> Core::GetPackageURLs (int packageId) const
	{
		QList<QUrl> result;

		const auto& repo2cmpt = Storage_->GetPackageLocations (packageId);

		PackageShortInfo info;
		try
		{
			info = Storage_->GetPackage (packageId);
		}
		catch (const std::exception& e)
		{
			qWarning () << Q_FUNC_INFO
					<< "error getting package"
					<< packageId
					<< e.what ();
			return result;
		}

		auto pathAddition = QString ("dists/%1/all/");
		const auto& normalized = NormalizePackageName (info.Name_);
		const auto& version = info.Versions_.at (0);
		pathAddition += QString ("%1/%1-%2.tar.%3")
				.arg (normalized)
				.arg (version)
				.arg (info.VersionArchivers_.value (version, "gz"));

		Q_FOREACH (int repoId, repo2cmpt.keys ())
		{
			RepoInfo ri = Storage_->GetRepo (repoId);
			QUrl url = ri.GetUrl ();
			QString path = url.path ();
			if (!path.endsWith ('/'))
				path += '/';

			Q_FOREACH (const QString& component, repo2cmpt [repoId])
			{
				QUrl tmp = url;
				tmp.setPath (path + pathAddition.arg (component));
				result << tmp;
			}
		}
Exemplo n.º 4
0
    void checkRepo(HostInfo &infoSnapshot, const std::string &uuid)
    {
        map<string, HostInfo *> hostSnapshot;
        map<string, HostInfo *>::iterator it;
        RepoInfo localInfo = infoSnapshot.getRepo(uuid);

        hostSnapshot = hosts;

        for (it = hostSnapshot.begin(); it != hostSnapshot.end(); it++) {
            list<string> repos = it->second->listRepos();
            list<string>::iterator rIt;

            for (rIt = repos.begin(); rIt != repos.end(); rIt++) {
                RepoInfo info = it->second->getRepo(uuid);

                if (info.getHead() != localInfo.getHead()) {
                    pullRepo(infoSnapshot, *(it->second), uuid);
                }
            }
        }
    }
Exemplo n.º 5
0
			RepoInfo Storage::GetRepo (int repoId)
			{
				QueryGetRepo_.bindValue (":repo_id", repoId);
				if (!QueryGetRepo_.exec ())
				{
					Util::DBLock::DumpError (QueryGetRepo_);
					throw std::runtime_error ("Query execution failed.");
				}
				if (!QueryGetRepo_.next ())
				{
					qWarning () << Q_FUNC_INFO
							<< "could not position on next record";
					throw std::runtime_error ("Could not position on next record");
				}
				RepoInfo result (QUrl::fromEncoded (QueryGetRepo_.value (0).toString ().toUtf8 ()));

				result.SetName (QueryGetRepo_.value (1).toString ());
				result.SetShortDescr (QueryGetRepo_.value (2).toString ());
				result.SetLongDescr (QueryGetRepo_.value (3).toString ());
				MaintainerInfo info =
				{
					QueryGetRepo_.value (4).toString (),
					QueryGetRepo_.value (5).toString ()
				};
				result.SetMaintainer (info);

				QueryGetRepo_.finish ();

				result.SetComponents (GetComponents (repoId));

				return result;
			}
Exemplo n.º 6
0
			int Storage::AddRepo (const RepoInfo& ri)
			{
				Util::DBLock lock (DB_);
				try
				{
					lock.Init ();
				}
				catch (const std::runtime_error& e)
				{
					qWarning () << Q_FUNC_INFO
							<< "could not acquire DB lock";
					throw;
				}

				QueryAddRepo_.bindValue (":url", Slashize (ri.GetUrl ()).toEncoded ());
				QueryAddRepo_.bindValue (":name", ri.GetName ());
				QueryAddRepo_.bindValue (":description", ri.GetShortDescr ());
				QueryAddRepo_.bindValue (":longdescr", ri.GetLongDescr ());
				QueryAddRepo_.bindValue (":maint_name", ri.GetMaintainer ().Name_);
				QueryAddRepo_.bindValue (":maint_email", ri.GetMaintainer ().Email_);
				if (!QueryAddRepo_.exec ())
				{
					Util::DBLock::DumpError (QueryAddRepo_);
					throw std::runtime_error ("Query execution failed.");
				}

				QueryAddRepo_.finish ();

				int repoId = FindRepo (Slashize (ri.GetUrl ()));
				if (repoId == -1)
				{
					qWarning () << Q_FUNC_INFO
							<< "OH SHI~, just inserted repo cannot be found!";
					throw std::runtime_error ("Just inserted repo cannot be found.");
				}

				Q_FOREACH (const QString& component, ri.GetComponents ())
					AddComponent (repoId, component);

				lock.Good ();

				return repoId;
			}
Exemplo n.º 7
0
	RepoInfo ParseRepoInfo (const QUrl& url, const QString& data)
	{
		QXmlQuery query;
		query.setFocus (data);

		RepoInfo info (url);

		QString out;
		query.setQuery ("/repo/name/text()");
		if (!query.evaluateTo (&out))
			throw QObject::tr ("Could not get repo name.");
		info.SetName (out.simplified ());

		query.setQuery ("/repo/description/short/text()");
		if (!query.evaluateTo (&out))
			throw QObject::tr ("Could not get repo description.");
		info.SetShortDescr (out.simplified ());

		query.setQuery ("/repo/description/long/text()");
		if (!query.evaluateTo (&out))
			throw QObject::tr ("Could not get long repo description.");
		info.SetLongDescr (out.simplified ());

		MaintainerInfo maintInfo;
		query.setQuery ("/repo/maintainer/name/text()");
		if (!query.evaluateTo (&out))
			throw QObject::tr ("Could not get maintainer name.");
		maintInfo.Name_ = out.simplified ();

		query.setQuery ("/repo/maintainer/email/text()");
		if (!query.evaluateTo (&out))
			throw QObject::tr ("Could not get maintainer email.");
		maintInfo.Email_ = out.simplified ();

		info.SetMaintainer (maintInfo);

		QStringList components;
		query.setQuery ("/repo/components/component/text()");
		if (query.evaluateTo (&components))
			info.SetComponents (components);
		else if (query.evaluateTo (&out))
			info.SetComponents (QStringList (out));
		else
			throw QObject::tr ("Could not get components.");

		return info;
	}
Exemplo n.º 8
0
    void pullRepo(HostInfo &localHost,
                  HostInfo &remoteHost,
                  const std::string &uuid)
    {
        RepoInfo local = localHost.getRepo(uuid);
        RepoInfo remote = remoteHost.getRepo(uuid);
        RepoControl repo = RepoControl(local.getPath());

        DLOG("Local and Remote heads mismatch on repo %s", uuid.c_str());

        repo.open();
        if (!repo.hasCommit(remote.getHead())) {
            LOG("Pulling from %s:%s",
                remoteHost.getPreferredIp().c_str(),
                remote.getPath().c_str());
            repo.pull(remoteHost.getPreferredIp(), remote.getPath());
        }
        repo.close();
    }