aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-01-22 09:26:00 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-01-22 09:26:00 +0000
commit1463d109f49cc0a9c7e3a3aaf2217c5e525956ba (patch)
tree20a22c308bd35669770cbfd40ce3a059cb365f48
parent2f59c0d7c93f5286db1b73d001c96ea60e2dc544 (diff)
downloadpaludis-1463d109f49cc0a9c7e3a3aaf2217c5e525956ba.tar.gz
paludis-1463d109f49cc0a9c7e3a3aaf2217c5e525956ba.tar.xz
Move common cookie code into util/
-rw-r--r--paludis/repositories/e/ebuild.cc5
-rw-r--r--paludis/repositories/unpackaged/installed_repository.cc11
-rw-r--r--paludis/util/cookie.cc34
-rw-r--r--paludis/util/cookie.hh39
-rw-r--r--paludis/util/files.m41
5 files changed, 79 insertions, 11 deletions
diff --git a/paludis/repositories/e/ebuild.cc b/paludis/repositories/e/ebuild.cc
index f60de2d..dcc9f39 100644
--- a/paludis/repositories/e/ebuild.cc
+++ b/paludis/repositories/e/ebuild.cc
@@ -43,6 +43,7 @@
#include <paludis/util/visitor_cast.hh>
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/set.hh>
+#include <paludis/util/cookie.hh>
#include <paludis/about.hh>
#include <paludis/environment.hh>
@@ -871,11 +872,9 @@ WriteBinaryEbuildCommand::operator() ()
if (! EAPIData::get_instance()->eapi_from_string("pbin-1+" + params.package_id->eapi()->exported_name)->supported)
throw InstallActionError("Don't know how to write binary ebuilds using EAPI 'pbin-1+" + params.package_id->eapi()->exported_name);
- std::string cookie("1." + stringify(getpid()) + "." + stringify(time(0)));
-
std::string bindistfile(stringify(params.destination_repository->name()) + "--" + stringify(params.package_id->name().category)
+ "--" + stringify(params.package_id->name().package) + "-" + stringify(params.package_id->version())
- + "--" + cookie);
+ + "--" + cookie());
std::string ebuild_cmd(getenv_with_default("PALUDIS_EBUILD_DIR", LIBEXECDIR "/paludis") +
"/write_binary_ebuild.bash '" +
diff --git a/paludis/repositories/unpackaged/installed_repository.cc b/paludis/repositories/unpackaged/installed_repository.cc
index afb68e1..d4181df 100644
--- a/paludis/repositories/unpackaged/installed_repository.cc
+++ b/paludis/repositories/unpackaged/installed_repository.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007 Ciaran McCreesh
+ * Copyright (c) 2007, 2008 Ciaran McCreesh
*
* 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
@@ -29,6 +29,7 @@
#include <paludis/util/set.hh>
#include <paludis/util/dir_iterator.hh>
#include <paludis/util/system.hh>
+#include <paludis/util/cookie.hh>
#include <paludis/stringify_formatter.hh>
#include <paludis/action.hh>
#include <paludis/environment.hh>
@@ -253,13 +254,7 @@ InstalledUnpackagedRepository::merge(const MergeOptions & m)
}
FSEntry target_ver_dir(uid_dir);
- {
- struct timeval t;
- gettimeofday(&t, 0);
- std::ostringstream magic;
- magic << std::hex << t.tv_usec << "x" << t.tv_sec;
- target_ver_dir /= (stringify(m.package_id->version()) + ":" + stringify(m.package_id->slot()) + ":" + magic.str());
- }
+ target_ver_dir /= (stringify(m.package_id->version()) + ":" + stringify(m.package_id->slot()) + ":" + cookie());
if (target_ver_dir.exists())
throw InstallActionError("Temporary merge directory '" + stringify(target_ver_dir) + "' already exists, probably "
diff --git a/paludis/util/cookie.cc b/paludis/util/cookie.cc
new file mode 100644
index 0000000..407db42
--- /dev/null
+++ b/paludis/util/cookie.cc
@@ -0,0 +1,34 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Ciaran McCreesh
+ *
+ * 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 <paludis/util/cookie.hh>
+#include <paludis/util/stringify.hh>
+#include <sys/types.h>
+#include <sys/time.h>
+
+using namespace paludis;
+
+std::string
+paludis::cookie()
+{
+ struct timeval t;
+ gettimeofday(&t, 0);
+ return "C." + stringify(::getpid()) + "." + stringify(t.tv_sec) + "." + stringify(t.tv_usec) + ".C";
+}
+
diff --git a/paludis/util/cookie.hh b/paludis/util/cookie.hh
new file mode 100644
index 0000000..6aeebe6
--- /dev/null
+++ b/paludis/util/cookie.hh
@@ -0,0 +1,39 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Ciaran McCreesh
+ *
+ * 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_PALUDIS_UTIL_COOKIE_HH
+#define PALUDIS_GUARD_PALUDIS_UTIL_COOKIE_HH 1
+
+#include <paludis/util/attributes.hh>
+#include <string>
+
+namespace paludis
+{
+ /**
+ * Return a magic cookie string.
+ *
+ * The cookie string will not contain any weird characters. It's derived
+ * from a combination of the process ID and the current time.
+ *
+ * \ingroup g_utils
+ */
+ std::string cookie() PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
+}
+
+#endif
diff --git a/paludis/util/files.m4 b/paludis/util/files.m4
index 8825e6f..e2b3bc4 100644
--- a/paludis/util/files.m4
+++ b/paludis/util/files.m4
@@ -13,6 +13,7 @@ add(`attributes', `hh')
add(`config_file', `hh', `cc', `se', `test', `testscript')
add(`clone', `hh', `impl')
add(`condition_variable', `hh', `cc', `test')
+add(`cookie', `hh', `cc')
add(`create_iterator', `hh', `fwd', `impl', `test')
add(`damerau_levenshtein', `hh', `cc', `test')
add(`destringify', `hh', `cc', `test')