Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions libpromises/files_links.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,22 @@ PromiseResult VerifyLink(EvalContext *ctx, char *destination, const char *source
return PROMISE_RESULT_NOOP;
}
/* else */

/* The mirrored symlink's target is in the chroot, show the real one. */
const char *real_linkbuf = linkbuf;
if (ChrootChanges() && IsAbsoluteFileName(linkbuf))
{
real_linkbuf = ToNormalRoot(linkbuf);
}

if (attr->move_obstructions)
{
if (MakingChanges(ctx, pp, attr, &result, "remove incorrect link '%s'", destination))
{
if (unlink(ToChangesPath(destination)) == -1)
{
RecordFailure(ctx, pp, attr, "Error removing link '%s' (points to '%s' not '%s')",
destination, linkbuf, to);
destination, real_linkbuf, to);
return PROMISE_RESULT_FAIL;
}
RecordChange(ctx, pp, attr, "Overrode incorrect link '%s'", destination);
Expand All @@ -205,7 +213,7 @@ PromiseResult VerifyLink(EvalContext *ctx, char *destination, const char *source
{
RecordFailure(ctx, pp, attr,
"Link '%s' points to '%s' not '%s', but not moving obstructions",
destination, linkbuf, to);
destination, real_linkbuf, to);
return PROMISE_RESULT_FAIL;
}
}
Expand Down
45 changes: 45 additions & 0 deletions tests/acceptance/29_simulate_mode/symlink_error_real_path.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
body common control
{
inputs => { "../default.sub.cf" };
bundlesequence => { default("$(this.promise_filename)") };
version => "1.0";
}

bundle agent init
{
files:
"$(G.testroot)/target-old" create => "true";
"$(G.testroot)/target-new" create => "true";

"$(G.testroot)/wrong-target"
link_from => linkfrom("$(G.testroot)/target-old", "symlink");
}

bundle agent test
{
meta:
"test_soft_fail"
string => "(solaris|aix|hpux|windows)",
# ENT-6540 exotics fail to delete chroot
# ENT-10254 tests fail on Windows due to CRLF
meta => { "ENT-6540", "ENT-10254" };

"description" -> { "ENT-14714" }
string => "Test that --simulate mode reports the real target of a wrong symlink, not its path in the changes chroot";
}

bundle agent check
{
vars:
"command"
string => "$(sys.cf_agent) -Kf $(this.promise_filename).sub --simulate=diff";

methods:
"check"
usebundle => dcs_passif_output(
".*\QLink '$(G.testroot)/wrong-target' points to '$(G.testroot)/target-old' not '$(G.testroot)/target-new', but not moving obstructions\E.*",
".*points to[^\n]*\Q.changes/\E.*",
$(command),
$(this.promise_filename)
);
}
11 changes: 11 additions & 0 deletions tests/acceptance/29_simulate_mode/symlink_error_real_path.cf.sub
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
body common control
{
inputs => { "../default.sub.cf" };
}

bundle agent main
{
files:
"$(G.testroot)/wrong-target"
link_from => linkfrom("$(G.testroot)/target-new", "symlink");
}
Loading