Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-2048

filestat's linktarget argument fails on relative target paths

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Built-in functions
    • Labels:
      None
    • Platform:
      Ubuntu
    • Steps to reproduce:
      Manual steps provided

      Description

      The @linktarget@ argument of CFEngine's @filestat@ function seems to have trouble with relative paths. When used on a link with a relative target, an error is thrown (visible in inform mode) that states "filestat bailing on link [...] because it could not be read". If @linktarget_shallow@ is used, this error does not appear.

      Note that despite the error, @filestat@ returns a value for the link target (which is a regular file in my example below). If the symlink was recursive this behavior could be problematic.

      Standalone test bundle:

      <pre>
      body common control
      {
      bundlesequence =>

      { "test_filestat", }

      ;
      }

      bundle agent test_filestat
      {
      vars:

      "link_target"
      string => filestat("/tmp/link_to_my_file", "linktarget");

      classes:

      "link_exists"
      expression => fileexists("/tmp/link_to_my_file");
      "link_target_is_correct"
      expression => strcmp("$(link_target)", "my_file");

      files:

      "/tmp/my_file"
      create => "true";

      "/tmp/link_to_my_file"
      link_from => ln_s("my_file"); # relative target

      reports:

      link_target_is_correct::
      "Link target $(link_target) is correct!";
      }

      1. required body from standard libraries
        body link_from ln_s
        {
        link_type => "symlink";
        source => "$";
        when_no_source => "force";
        }
        </pre>

      Output on first run:

      <pre>
      $ cf-agent -KIf ./filestat.cf
      2015-07-16T18:58:53+0000 info: /default/test_filestat/files/'/tmp/my_file'[0]: Created file '/tmp/my_file', mode 0600
      2015-07-16T18:58:53+0000 info: /default/test_filestat/files/'/tmp/link_to_my_file'[0]: Linked files '/tmp/link_to_my_file' -> 'my_file'
      R: Link target my_file is correct!
      </pre>

      Output on subsequent run:

      <pre>
      $ cf-agent -KIf ./filestat.cf
      2015-07-16T18:59:02+0000 info: /default/test_filestat/vars: filestat bailing on link 'my_file' (original '/tmp/link_to_my_file') because it could not be read
      2015-07-16T18:59:02+0000 info: /default/test_filestat/vars: filestat bailing on link 'my_file' (original '/tmp/link_to_my_file') because it could not be read
      2015-07-16T18:59:02+0000 info: /default/test_filestat/vars: filestat bailing on link 'my_file' (original '/tmp/link_to_my_file') because it could not be read
      2015-07-16T18:59:02+0000 info: /default/test_filestat/vars: filestat bailing on link 'my_file' (original '/tmp/link_to_my_file') because it could not be read
      2015-07-16T18:59:02+0000 info: /default/test_filestat/vars: filestat bailing on link 'my_file' (original '/tmp/link_to_my_file') because it could not be read
      R: Link target my_file is correct!
      </pre>

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                a10038 jimis (Dimitrios Apostolou)
                Reporter:
                ianwestcott Ian Westcott
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Summary Panel

                    Time Tracking

                    Estimated:
                    Original Estimate - 5 hours
                    5h
                    Remaining:
                    Not Specified
                    Logged:
                    Time Not Required
                    Not Specified