aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Saleem Abdulrasool <compnerd@compnerd.org> 2013-05-12 11:32:59 -0700
committerAvatar Saleem Abdulrasool <compnerd@compnerd.org> 2013-05-18 14:07:32 -0700
commit6bdc2e7523f8b2eebf78401356f568cace26f301 (patch)
treef625a1dcb31286850744387d4172a3c86cc82fff
parent97d0f19557cbc209dab9fbfe8fcf74d9238d6161 (diff)
downloadpaludis-6bdc2e7523f8b2eebf78401356f568cace26f301.tar.gz
paludis-6bdc2e7523f8b2eebf78401356f568cace26f301.tar.xz
merger: refactor merge display
This moves the stringification of the classification, and the formatting of the merge display into FSMerger so that it may be shared across the VDB merger and the NDBAM merger. This will be used internally in FSMerger for selective parts. Signed-off-by: Saleem Abdulrasool <compnerd@compnerd.org>
-rw-r--r--paludis/fs_merger.cc35
-rw-r--r--paludis/fs_merger.hh3
-rw-r--r--paludis/ndbam_merger.cc40
-rw-r--r--paludis/repositories/e/vdb_merger.cc39
4 files changed, 82 insertions, 35 deletions
diff --git a/paludis/fs_merger.cc b/paludis/fs_merger.cc
index bbe4466..e29890b 100644
--- a/paludis/fs_merger.cc
+++ b/paludis/fs_merger.cc
@@ -1060,3 +1060,38 @@ FSMerger::make_arrows(const FSMergerStatusFlags & flags) const
return result;
}
+void
+FSMerger::display_merge(const EntryType & type, const FSPath & path,
+ const FSMergerStatusFlags & flags,
+ const std::string & renamed) const
+{
+ const auto real_path(path.strip_leading(_imp->params.root().realpath()));
+ std::ostringstream message;
+
+ message << make_arrows(flags);
+
+ switch (type)
+ {
+ case et_dir:
+ message << " [dir] ";
+ break;
+ case et_file:
+ message << " [obj] ";
+ break;
+ case et_sym:
+ message << " [sym] ";
+ break;
+
+ case et_misc:
+ case et_nothing:
+ case last_et:
+ throw FSMergerError("Unexpected entry type merged at: " + stringify(real_path));
+ }
+
+ message << stringify(real_path);
+ if (!renamed.empty())
+ message << " (" << renamed << ")";
+
+ display_override(message.str());
+}
+
diff --git a/paludis/fs_merger.hh b/paludis/fs_merger.hh
index e9bde0f..e0f2848 100644
--- a/paludis/fs_merger.hh
+++ b/paludis/fs_merger.hh
@@ -229,6 +229,9 @@ namespace paludis
///\}
virtual std::string make_arrows(const FSMergerStatusFlags & flags) const;
+ virtual void display_merge(const EntryType &, const FSPath &,
+ const FSMergerStatusFlags &,
+ const std::string & = "") const;
public:
///\name Basic operations
diff --git a/paludis/ndbam_merger.cc b/paludis/ndbam_merger.cc
index 7eed0a2..24ce4e2 100644
--- a/paludis/ndbam_merger.cc
+++ b/paludis/ndbam_merger.cc
@@ -159,24 +159,24 @@ namespace
void
NDBAMMerger::record_install_file(const FSPath & src, const FSPath & dst_dir, const std::string & dst_name, const FSMergerStatusFlags & flags)
{
- std::string tidy(stringify((dst_dir / dst_name).strip_leading(_imp->realroot))),
- tidy_real(stringify((dst_dir / src.basename()).strip_leading(_imp->realroot)));
+ const auto file(dst_dir / src.basename());
+ const auto renamed_file(dst_dir / dst_name);
- FSPath dst_dir_name(dst_dir / dst_name);
- FSStat dst_dir_name_stat(dst_dir_name);
+ const std::string tidy(stringify(renamed_file.strip_leading(_imp->realroot))),
+ tidy_real(stringify(file.strip_leading(_imp->realroot)));
+
+ FSStat dst_dir_name_stat(renamed_file);
time_t timestamp(dst_dir_name_stat.mtim().seconds());
- SafeIFStream infile(dst_dir_name);
+ SafeIFStream infile(renamed_file);
if (! infile)
- throw FSMergerError("Cannot read '" + stringify(dst_dir_name) + "'");
+ throw FSMergerError("Cannot read '" + stringify(renamed_file) + "'");
MD5 md5(infile);
- std::string line(make_arrows(flags) + " [obj] " + tidy_real);
- if (tidy_real != tidy)
- line.append(" (" + FSPath(tidy).basename() + ")");
- display_override(line);
+ display_merge(et_file, file, flags,
+ src.basename() == dst_name ? "" : dst_name);
std::string part;
if (_imp->params.parts())
@@ -194,8 +194,10 @@ NDBAMMerger::record_install_file(const FSPath & src, const FSPath & dst_dir, con
void
NDBAMMerger::record_install_dir(const FSPath & src, const FSPath & dst_dir, const FSMergerStatusFlags & flags)
{
- std::string tidy(stringify((dst_dir / src.basename()).strip_leading(_imp->realroot)));
- display_override(make_arrows(flags) + " [dir] " + tidy);
+ const auto dir(dst_dir / src.basename());
+ const std::string tidy(stringify(dir.strip_leading(_imp->realroot)));
+
+ display_merge(et_dir, dir, flags);
*_imp->contents_file << "type=dir path=" << escape(tidy) << std::endl;
}
@@ -203,8 +205,9 @@ NDBAMMerger::record_install_dir(const FSPath & src, const FSPath & dst_dir, cons
void
NDBAMMerger::record_install_under_dir(const FSPath & dst, const FSMergerStatusFlags & flags)
{
- std::string tidy(stringify(dst.strip_leading(_imp->realroot)));
- display_override(make_arrows(flags) + " [dir] " + tidy);
+ const std::string tidy(stringify(dst.strip_leading(_imp->realroot)));
+
+ display_merge(et_dir, dst, flags);
*_imp->contents_file << "type=dir path=" << escape(tidy) << std::endl;
}
@@ -212,11 +215,12 @@ NDBAMMerger::record_install_under_dir(const FSPath & dst, const FSMergerStatusFl
void
NDBAMMerger::record_install_sym(const FSPath & src, const FSPath & dst_dir, const FSMergerStatusFlags & flags)
{
- std::string tidy(stringify((dst_dir / src.basename()).strip_leading(_imp->realroot)));
- std::string target((dst_dir / src.basename()).readlink());
- Timestamp timestamp((dst_dir / src.basename()).stat().mtim());
+ const auto sym(dst_dir / src.basename());
+ const std::string tidy(stringify(sym.strip_leading(_imp->realroot)));
+ const std::string target(sym.readlink());
+ const Timestamp timestamp(sym.stat().mtim());
- display_override(make_arrows(flags) + " [sym] " + tidy);
+ display_merge(et_sym, sym, flags);
*_imp->contents_file << "type=sym path=" << escape(tidy);
*_imp->contents_file << " target=" << escape(target);
diff --git a/paludis/repositories/e/vdb_merger.cc b/paludis/repositories/e/vdb_merger.cc
index 9d033e3..af74b35 100644
--- a/paludis/repositories/e/vdb_merger.cc
+++ b/paludis/repositories/e/vdb_merger.cc
@@ -148,20 +148,21 @@ VDBMerger::extend_hook(const Hook & h)
void
VDBMerger::record_install_file(const FSPath & src, const FSPath & dst_dir, const std::string & dst_name, const FSMergerStatusFlags & flags)
{
- std::string tidy(stringify((dst_dir / dst_name).strip_leading(_imp->realroot))),
- tidy_real(stringify((dst_dir / src.basename()).strip_leading(_imp->realroot)));
- Timestamp timestamp((dst_dir / dst_name).stat().mtim());
+ const auto file(dst_dir / src.basename());
+ const auto renamed_file(dst_dir / dst_name);
- SafeIFStream infile(FSPath(dst_dir / dst_name));
+ const std::string tidy(stringify(renamed_file.strip_leading(_imp->realroot))),
+ tidy_real(stringify(file.strip_leading(_imp->realroot)));
+ const Timestamp timestamp(renamed_file.stat().mtim());
+
+ SafeIFStream infile(renamed_file);
if (! infile)
- throw FSMergerError("Cannot read '" + stringify(FSPath(dst_dir / dst_name)) + "'");
+ throw FSMergerError("Cannot read '" + stringify(renamed_file) + "'");
MD5 md5(infile);
- std::string line(make_arrows(flags) + " [obj] " + tidy_real);
- if (tidy_real != tidy)
- line.append(" (" + FSPath(tidy).basename() + ")");
- display_override(line);
+ display_merge(et_file, renamed_file, flags,
+ src.basename() == dst_name ? "" : dst_name);
*_imp->contents_file << "obj " << tidy_real << " " << md5.hexsum() << " " << timestamp.seconds() << std::endl;
}
@@ -169,8 +170,10 @@ VDBMerger::record_install_file(const FSPath & src, const FSPath & dst_dir, const
void
VDBMerger::record_install_dir(const FSPath & src, const FSPath & dst_dir, const FSMergerStatusFlags & flags)
{
- std::string tidy(stringify((dst_dir / src.basename()).strip_leading(_imp->realroot)));
- display_override(make_arrows(flags) + " [dir] " + tidy);
+ const auto dir(dst_dir / src.basename());
+ const std::string tidy(stringify(dir.strip_leading(_imp->realroot)));
+
+ display_merge(et_dir, dir, flags);
*_imp->contents_file << "dir " << tidy << std::endl;
}
@@ -178,8 +181,9 @@ VDBMerger::record_install_dir(const FSPath & src, const FSPath & dst_dir, const
void
VDBMerger::record_install_under_dir(const FSPath & dst_dir, const FSMergerStatusFlags & flags)
{
- std::string tidy(stringify(dst_dir.strip_leading(_imp->realroot)));
- display_override(make_arrows(flags) + " [dir] " + tidy);
+ const std::string tidy(stringify(dst_dir.strip_leading(_imp->realroot)));
+
+ display_merge(et_dir, dst_dir, flags);
*_imp->contents_file << "dir " << tidy << std::endl;
}
@@ -187,11 +191,12 @@ VDBMerger::record_install_under_dir(const FSPath & dst_dir, const FSMergerStatus
void
VDBMerger::record_install_sym(const FSPath & src, const FSPath & dst_dir, const FSMergerStatusFlags & flags)
{
- std::string tidy(stringify((dst_dir / src.basename()).strip_leading(_imp->realroot)));
- std::string target((dst_dir / src.basename()).readlink());
- Timestamp timestamp((dst_dir / src.basename()).stat().mtim());
+ const auto sym(dst_dir / src.basename());
+ const std::string tidy(stringify(sym.strip_leading(_imp->realroot)));
+ const std::string target(sym.readlink());
+ const Timestamp timestamp(sym.stat().mtim());
- display_override(make_arrows(flags) + " [sym] " + tidy);
+ display_merge(et_sym, sym, flags);
*_imp->contents_file << "sym " << tidy << " -> " << target << " " << timestamp.seconds() << std::endl;
}