aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-04 03:21:00 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-04 03:21:00 +0000
commit4354c733691f901173ea67f439d0fc3edaa973c1 (patch)
tree6c655a23e4ca41d3fd09fecbaea48a250f6d7f4e
parent945146e8f41e88bc06cdaac22a2ff149f01972f1 (diff)
downloadpaludis-4354c733691f901173ea67f439d0fc3edaa973c1.tar.gz
paludis-4354c733691f901173ea67f439d0fc3edaa973c1.tar.xz
Rudimentary sync support
-rw-r--r--paludis/fake_repository.cc6
-rw-r--r--paludis/fake_repository.hh2
-rw-r--r--paludis/portage_repository.cc40
-rw-r--r--paludis/portage_repository.hh4
-rw-r--r--paludis/repository.hh15
-rw-r--r--paludis/vdb_repository.cc6
-rw-r--r--paludis/vdb_repository.hh2
-rw-r--r--src/Makefile.am1
-rw-r--r--src/command_line.cc5
-rw-r--r--src/command_line.hh3
-rw-r--r--src/paludis.cc11
-rw-r--r--src/sync.cc61
-rw-r--r--src/sync.hh33
13 files changed, 181 insertions, 8 deletions
diff --git a/paludis/fake_repository.cc b/paludis/fake_repository.cc
index f762137..f1749e6 100644
--- a/paludis/fake_repository.cc
+++ b/paludis/fake_repository.cc
@@ -224,3 +224,9 @@ FakeRepository::do_system_packages() const
return result;
}
+bool
+FakeRepository::do_sync() const
+{
+ return false;
+}
+
diff --git a/paludis/fake_repository.hh b/paludis/fake_repository.hh
index 71a75b9..47e95ea 100644
--- a/paludis/fake_repository.hh
+++ b/paludis/fake_repository.hh
@@ -83,6 +83,8 @@ namespace paludis
virtual DepAtom::Pointer do_system_packages() const;
+ virtual bool do_sync() const;
+
public:
/**
* Constructor.
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index bd43f15..a02902a 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -105,6 +105,9 @@ namespace paludis
/// Distfiles dir
FSEntry distdir;
+ /// Sync URL
+ std::string sync;
+
/// Have we loaded our category names?
mutable bool has_category_names;
@@ -167,7 +170,7 @@ namespace paludis
/// Constructor.
Implementation(const Environment * const,
const PackageDatabase * const d, const FSEntry & l, const FSEntry & p,
- const FSEntry & c, const FSEntry &, const FSEntry &);
+ const FSEntry & c, const FSEntry &, const FSEntry &, const std::string &);
/// Destructor.
~Implementation();
@@ -180,7 +183,7 @@ namespace paludis
Implementation<PortageRepository>::Implementation(const Environment * const env,
const PackageDatabase * const d,
const FSEntry & l, const FSEntry & p, const FSEntry & c,
- const FSEntry & e, const FSEntry & dd) :
+ const FSEntry & e, const FSEntry & dd, const std::string & syn) :
db(d),
env(env),
location(l),
@@ -188,6 +191,7 @@ Implementation<PortageRepository>::Implementation(const Environment * const env,
cache(c),
eclassdir(e),
distdir(dd),
+ sync(syn),
has_category_names(false),
has_repo_mask(false),
has_virtuals(false),
@@ -308,10 +312,10 @@ PortageRepository::PortageRepository(
const Environment * const e, const PackageDatabase * const d,
const FSEntry & location, const FSEntry & profile,
const FSEntry & cache, const FSEntry & eclassdir,
- const FSEntry & distdir) :
+ const FSEntry & distdir, const std::string & sync) :
Repository(PortageRepository::fetch_repo_name(location)),
PrivateImplementationPattern<PortageRepository>(new Implementation<PortageRepository>(e,
- d, location, profile, cache, eclassdir, distdir))
+ d, location, profile, cache, eclassdir, distdir, sync))
{
_info.insert(std::make_pair(std::string("location"), location));
_info.insert(std::make_pair(std::string("profile"), profile));
@@ -319,6 +323,8 @@ PortageRepository::PortageRepository(
_info.insert(std::make_pair(std::string("eclassdir"), eclassdir));
_info.insert(std::make_pair(std::string("distdir"), distdir));
_info.insert(std::make_pair(std::string("format"), std::string("portage")));
+ if (! sync.empty())
+ _info.insert(std::make_pair(std::string("sync"), sync));
}
PortageRepository::~PortageRepository()
@@ -877,8 +883,12 @@ PortageRepository::make_portage_repository(
if (m.end() == m.find("cache") || ((cache = m.find("cache")->second)).empty())
cache = location + "/metadata/cache";
+ std::string sync;
+ if (m.end() == m.find("sync") || ((sync = m.find("sync")->second)).empty())
+ ; // nothing
+
return CountedPtr<Repository>(new PortageRepository(env, db, location, profile, cache,
- eclassdir, distdir));
+ eclassdir, distdir, sync));
}
PortageRepositoryConfigurationError::PortageRepositoryConfigurationError(
@@ -1137,3 +1147,23 @@ PortageRepository::do_system_packages() const
return _imp->system_packages;
}
+bool
+PortageRepository::do_sync() const
+{
+ if (_imp->sync.empty())
+ return false;
+
+ if (0 != _imp->sync.compare(0, 8, "rsync://"))
+ throw InternalError(PALUDIS_HERE, "todo"); /// \todo fixme
+
+ std::string cmd("rsync --recursive --links --safe-links --perms --times "
+ "--compress --force --whole-file --delete --delete-after --stats "
+ "--timeout=180 --exclude=/distfiles --exclude=/packages --progress "
+ "'" + stringify(_imp->sync) + "' '" + stringify(_imp->location) + "/'");
+
+ if (0 != run_command(cmd))
+ throw InternalError(PALUDIS_HERE, "todo"); /// \todo fixme
+
+ return true;
+}
+
diff --git a/paludis/portage_repository.hh b/paludis/portage_repository.hh
index 542b918..828828c 100644
--- a/paludis/portage_repository.hh
+++ b/paludis/portage_repository.hh
@@ -94,6 +94,8 @@ namespace paludis
virtual DepAtom::Pointer do_system_packages() const;
+ virtual bool do_sync() const;
+
public:
/**
* Constructor.
@@ -102,7 +104,7 @@ namespace paludis
const PackageDatabase * const db,
const FSEntry & location, const FSEntry & profile,
const FSEntry & cache, const FSEntry & distdir,
- const FSEntry & eclassdir);
+ const FSEntry & eclassdir, const std::string & sync);
/**
* Virtual constructor.
diff --git a/paludis/repository.hh b/paludis/repository.hh
index 9274ba5..7fa40ec 100644
--- a/paludis/repository.hh
+++ b/paludis/repository.hh
@@ -158,6 +158,11 @@ namespace paludis
*/
virtual DepAtom::Pointer do_system_packages() const = 0;
+ /**
+ * Override in descendents: sync, if needed (true) or do nothing (false).
+ */
+ virtual bool do_sync() const = 0;
+
public:
/**
* Destructor.
@@ -389,6 +394,16 @@ namespace paludis
virtual bool installed() const = 0;
/**
+ * Sync, if necessary.
+ *
+ * \return True if we synced successfully, false if we skipped sync.
+ */
+ bool sync() const
+ {
+ return do_sync();
+ }
+
+ /**
* Fetch our system packages list.
*/
virtual DepAtom::Pointer system_packages() const
diff --git a/paludis/vdb_repository.cc b/paludis/vdb_repository.cc
index b45c4d1..107c719 100644
--- a/paludis/vdb_repository.cc
+++ b/paludis/vdb_repository.cc
@@ -469,3 +469,9 @@ VDBRepository::do_system_packages() const
return result;
}
+bool
+VDBRepository::do_sync() const
+{
+ return false;
+}
+
diff --git a/paludis/vdb_repository.hh b/paludis/vdb_repository.hh
index 53ecce9..d05be0a 100644
--- a/paludis/vdb_repository.hh
+++ b/paludis/vdb_repository.hh
@@ -74,6 +74,8 @@ namespace paludis
virtual DepAtom::Pointer do_system_packages() const;
+ virtual bool do_sync() const;
+
public:
/**
* Constructor.
diff --git a/src/Makefile.am b/src/Makefile.am
index 381580d..13df6ea 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,6 +16,7 @@ paludis_SOURCES = \
install.hh install.cc \
list.hh list.cc \
query.hh query.cc \
+ sync.hh sync.cc \
paludis.cc
paludis_LDADD = \
diff --git a/src/command_line.cc b/src/command_line.cc
index 6065afb..e038700 100644
--- a/src/command_line.cc
+++ b/src/command_line.cc
@@ -23,8 +23,9 @@ CommandLine::CommandLine() :
ArgsHandler(),
action_args(this, "Actions (specify exactly one)"),
- a_query(&action_args, "query", 'q', "Query for package information"),
- a_install(&action_args, "install", 'i', "Install one or more packages"),
+ a_query(&action_args, "query", 'q', "Query for package information"),
+ a_install(&action_args, "install", 'i', "Install one or more packages"),
+ a_sync(&action_args, "sync", '\0', "Sync repositories"),
a_list_repositories(&action_args, "list-repositories", '\0', "List available repositories"),
a_list_categories(&action_args, "list-categories", '\0', "List available categories"),
a_list_packages(&action_args, "list-packages", '\0', "List available packages"),
diff --git a/src/command_line.hh b/src/command_line.hh
index ca4d581..7640ef9 100644
--- a/src/command_line.hh
+++ b/src/command_line.hh
@@ -56,6 +56,9 @@ class CommandLine :
/// --install
paludis::args::SwitchArg a_install;
+ /// --sync
+ paludis::args::SwitchArg a_sync;
+
/// --list-repositories
paludis::args::SwitchArg a_list_repositories;
diff --git a/src/paludis.cc b/src/paludis.cc
index f528956..6cbee8f 100644
--- a/src/paludis.cc
+++ b/src/paludis.cc
@@ -22,6 +22,7 @@
#include "src/list.hh"
#include "src/query.hh"
#include "src/applets.hh"
+#include "src/sync.hh"
#include <paludis/paludis.hh>
#include <paludis/util/util.hh>
@@ -73,6 +74,7 @@ main(int argc, char *argv[])
if (1 != (CommandLine::get_instance()->a_query.specified() +
CommandLine::get_instance()->a_version.specified() +
CommandLine::get_instance()->a_install.specified() +
+ CommandLine::get_instance()->a_sync.specified() +
CommandLine::get_instance()->a_list_repositories.specified() +
CommandLine::get_instance()->a_list_categories.specified() +
CommandLine::get_instance()->a_list_packages.specified() +
@@ -99,6 +101,15 @@ main(int argc, char *argv[])
return do_install();
}
+ if (CommandLine::get_instance()->a_sync.specified())
+ {
+ /// \todo --sync foo?
+ if (! CommandLine::get_instance()->empty())
+ throw DoHelp("sync action tales no parameters");
+
+ return do_sync();
+ }
+
if (CommandLine::get_instance()->a_list_repositories.specified())
{
if (! CommandLine::get_instance()->empty())
diff --git a/src/sync.cc b/src/sync.cc
new file mode 100644
index 0000000..c0881ff
--- /dev/null
+++ b/src/sync.cc
@@ -0,0 +1,61 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "src/colour.hh"
+#include "src/sync.hh"
+#include <functional>
+#include <iomanip>
+#include <iostream>
+#include <paludis/paludis.hh>
+#include <string>
+
+/** \file
+ * Handle the --sync action for the main paludis program.
+ */
+
+namespace p = paludis;
+
+int do_sync()
+{
+ int return_code(0);
+
+ p::Context context("When performing sync action from command line:");
+ p::Environment * const env(p::DefaultEnvironment::get_instance());
+
+ for (p::PackageDatabase::RepositoryIterator r(env->package_database()->begin_repositories()),
+ r_end(env->package_database()->end_repositories()) ; r != r_end ; ++r)
+ {
+ std::cout << std::endl << "Sync " << (*r)->name() << ":" << std::endl << std::endl;
+
+ if ((*r)->sync())
+ {
+ std::cout << std::endl << "Sync " << (*r)->name() << " completed"
+ << std::endl << std::endl;
+ }
+ else
+ {
+ std::cout << std::endl << "Sync " << (*r)->name() << " skipped"
+ << std::endl << std::endl;
+ }
+ }
+
+ return return_code;
+}
+
+
diff --git a/src/sync.hh b/src/sync.hh
new file mode 100644
index 0000000..822c070
--- /dev/null
+++ b/src/sync.hh
@@ -0,0 +1,33 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_SRC_SYNC_HH
+#define PALUDIS_GUARD_SRC_SYNC_HH 1
+
+#include "src/command_line.hh"
+
+/** \file
+ * Declaration for the do_sync function.
+ */
+
+/// Handle --sync.
+int do_sync();
+
+#endif
+