aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-31 15:46:46 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-31 15:46:46 +0100
commit5f87d680ce4dbf996caa81b3f82f30e06dc0a0c6 (patch)
tree534ce36b8bfb60b5c57860708f276ffa9d16c4bc
parent9a06044eef6c4b40c4405c103faade1f88cf5a39 (diff)
downloadpaludis-5f87d680ce4dbf996caa81b3f82f30e06dc0a0c6.tar.gz
paludis-5f87d680ce4dbf996caa81b3f82f30e06dc0a0c6.tar.xz
Move symlink rewriting into Merger
-rw-r--r--paludis/fs_merger.cc51
-rw-r--r--paludis/fs_merger.hh1
-rw-r--r--paludis/merger.cc29
-rw-r--r--paludis/merger.hh1
4 files changed, 40 insertions, 42 deletions
diff --git a/paludis/fs_merger.cc b/paludis/fs_merger.cc
index 7d5d85a..659948a 100644
--- a/paludis/fs_merger.cc
+++ b/paludis/fs_merger.cc
@@ -436,26 +436,6 @@ FSMerger::install_file(const FSEntry & src, const FSEntry & dst_dir, const std::
}
void
-FSMerger::rewrite_symlink_as_needed(const FSEntry & src, const FSEntry & dst_dir)
-{
- if (! symlink_needs_rewriting(src))
- return;
-
- FSCreateCon createcon(MatchPathCon::get_instance()->match(stringify(dst_dir / src.basename()), S_IFLNK));
-
- FSEntry real_image(_imp->params.image().realpath());
- FSEntry dst(src.readlink());
- std::string fixed_dst(stringify(dst.strip_leading(real_image)));
-
- Log::get_instance()->message("merger.rewriting_symlink", ll_qa, lc_context) << "Rewriting bad symlink: "
- << src << " -> " << dst << " to " << fixed_dst;
-
- FSEntry s(dst_dir / src.basename());
- s.unlink();
- s.symlink(fixed_dst);
-}
-
-void
FSMerger::track_renamed_dir_recursive(const FSEntry & dst)
{
for (DirIterator d(dst, { dio_include_dotfiles, dio_inode_sort }), d_end ; d != d_end ; ++d)
@@ -620,33 +600,26 @@ FSMerger::install_sym(const FSEntry & src, const FSEntry & dst_dir)
if (0 != (src.permissions() & (S_ISVTX | S_ISUID | S_ISGID)))
result += msi_setid_bits;
- bool do_sym(false);
+ bool do_sym(true);
- if (symlink_needs_rewriting(src))
- rewrite_symlink_as_needed(src, dst_dir);
- else
+ FSCreateCon createcon(MatchPathCon::get_instance()->match(stringify(dst), S_IFLNK));
+ std::pair<MergedMap::const_iterator, MergedMap::const_iterator> ii(
+ _imp->merged_ids.equal_range(src.lowlevel_id()));
+ for (MergedMap::const_iterator i = ii.first ; i != ii.second ; ++i)
{
- do_sym = true;
- FSCreateCon createcon(MatchPathCon::get_instance()->match(stringify(dst), S_IFLNK));
- std::pair<MergedMap::const_iterator, MergedMap::const_iterator> ii(
- _imp->merged_ids.equal_range(src.lowlevel_id()));
- for (MergedMap::const_iterator i = ii.first ; i != ii.second ; ++i)
+ if (0 == ::link(i->second.c_str(), stringify(dst).c_str()))
{
- if (0 == ::link(i->second.c_str(), stringify(dst).c_str()))
- {
- do_sym = false;
- result += msi_as_hardlink;
- break;
- }
- Log::get_instance()->message("merger.sym.link_failed", ll_debug, lc_context)
- << "link(" << i->second + ", " << stringify(dst) << ") failed: "
- << ::strerror(errno);
+ do_sym = false;
+ result += msi_as_hardlink;
+ break;
}
+ Log::get_instance()->message("merger.sym.link_failed", ll_debug, lc_context)
+ << "link(" << i->second + ", " << stringify(dst) << ") failed: "
+ << ::strerror(errno);
}
if (do_sym)
{
- FSCreateCon createcon(MatchPathCon::get_instance()->match(stringify(dst), S_IFLNK));
if (0 != ::symlink(stringify(src.readlink()).c_str(), stringify(dst).c_str()))
throw FSMergerError("Couldn't create symlink at '" + stringify(dst) + "': "
+ stringify(::strerror(errno)));
diff --git a/paludis/fs_merger.hh b/paludis/fs_merger.hh
index ba58f52..a3553cd 100644
--- a/paludis/fs_merger.hh
+++ b/paludis/fs_merger.hh
@@ -131,7 +131,6 @@ namespace paludis
private:
void track_renamed_dir_recursive(const FSEntry &);
void relabel_dir_recursive(const FSEntry &, const FSEntry &);
- void rewrite_symlink_as_needed(const FSEntry &, const FSEntry &);
void try_to_copy_xattrs(const FSEntry &, int, FSMergerStatusFlags &);
Pimp<FSMerger>::ImpPtr & _imp;
diff --git a/paludis/merger.cc b/paludis/merger.cc
index 43404f9..f81f9f4 100644
--- a/paludis/merger.cc
+++ b/paludis/merger.cc
@@ -23,6 +23,7 @@
#include <paludis/util/dir_iterator.hh>
#include <paludis/util/log.hh>
#include <paludis/util/pimp-impl.hh>
+#include <paludis/selinux/security_context.hh>
#include <paludis/environment.hh>
#include <paludis/hook.hh>
#include <set>
@@ -334,11 +335,15 @@ Merger::on_sym(bool is_check, const FSEntry & src, const FSEntry & dst)
display_override("--- [skp] " + tidy);
return;
}
+
}
- else
+
+ if (symlink_needs_rewriting(src))
{
- if (symlink_needs_rewriting(src) && ! _imp->params.options()[mo_rewrite_symlinks])
+ if (! _imp->params.options()[mo_rewrite_symlinks])
on_error(is_check, "Symlink to image detected at: " + stringify(src) + " (" + src.readlink() + ")");
+ else if (! is_check)
+ rewrite_symlink_as_needed(src, dst);
}
on_sym_main(is_check, src, dst);
@@ -439,3 +444,23 @@ Merger::on_done_merge()
{
}
+void
+Merger::rewrite_symlink_as_needed(const FSEntry & src, const FSEntry & dst_dir)
+{
+ if (! symlink_needs_rewriting(src))
+ return;
+
+ FSCreateCon createcon(MatchPathCon::get_instance()->match(stringify(dst_dir / src.basename()), S_IFLNK));
+
+ FSEntry real_image(_imp->params.image().realpath());
+ FSEntry dst(src.readlink());
+ std::string fixed_dst(stringify(dst.strip_leading(real_image)));
+
+ Log::get_instance()->message("merger.rewriting_symlink", ll_qa, lc_context) << "Rewriting bad symlink: "
+ << src << " -> " << dst << " to " << fixed_dst;
+
+ FSEntry s(src);
+ s.unlink();
+ s.symlink(fixed_dst);
+}
+
diff --git a/paludis/merger.hh b/paludis/merger.hh
index a6d2781..4eb3dfc 100644
--- a/paludis/merger.hh
+++ b/paludis/merger.hh
@@ -74,6 +74,7 @@ namespace paludis
{
protected:
bool symlink_needs_rewriting(const FSEntry &);
+ void rewrite_symlink_as_needed(const FSEntry &, const FSEntry &);
void set_skipped_dir(const bool);
void do_ownership_fixes_recursive(const FSEntry &);
bool fixed_ownership_for(const FSEntry &);