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

functions (e.g. islink(), fileexists()) should work with $(this.promiser)

    XMLWordPrintable

    Details

      Description

      At least islink() and fileexists() does not seem to handle $(this.promiser).

      bundle agent init
      {
        files:
            "/tmp/file-symlink-this-promiser"
              link_from => u_ln_s("/tmp/file"),
              move_obstructions => "true";
      
            "/tmp/file-symlink-file-exists"
              link_from => u_ln_s("/tmp/file"),
              move_obstructions => "true";
      
      
            "/tmp/file-symlink-explicit"
              link_from => u_ln_s("/tmp/file"),
              move_obstructions => "true";
      }
      bundle agent test
      {
        files:
            "/tmp/file-symlink-this-promiser"
              delete => u_tidy,
              if => islink($(this.promiser));
      
             "/tmp/file-symlink-file-exists"
              delete => u_tidy,
              if => fileexists($(this.promiser));
      
            "/tmp/file-symlink-explicit"
              delete => u_tidy,
              if => islink("/tmp/file-symlink-explicit");
      }
      bundle agent check
      {
        reports:
            "$(this.promise_filename) $(with)"
              with => ifelse( or( fileexists("/tmp/file-symlink-this-promiser"),
                                  fileexists("/tmp/file-symlink-file-exists")),
                                  "FAIL", "Pass" );
      
            "/tmp/file-symlink-this-promiser should have been deleted but wasn't"
              if => fileexists("/tmp/file-symlink-this-promiser");
      
            "/tmp/file-symlink-file-exists should have been deleted but wasn't"
              if => fileexists("/tmp/file-symlink-file-exists");
      
            "Note: /tmp/file-symlink-explicit was deleted as expected"
              unless => fileexists("/tmp/file-symlink-explicit");
      }
      bundle agent __main__
      {
        methods:
            "init";
            "test";
            "check";
      }
      body link_from u_ln_s(x)
      # @brief Symlink to `x`, even if it does not exist
      # @param x Path to symlink
      #@ **Example:**
      #@ ```cf3
      #@ bundle agent example u_ln_s {
      #@   files:
      #@     "$(symlink_path)"
      #@       link_from => u_ln_s("$(python)"),
      #@       move_obstructions => "true",
      #@       if => isvariable("python");
      #@ }
      #@ ```
      {
              link_type => "symlink";
              source => "$(x)";
              when_no_source => "force";
      }
      body delete u_tidy
      {
              dirlinks => "delete";
              rmdirs   => "true";
      }
      
          info: Linked files '/tmp/file-symlink-file-exists' -> '/tmp/file'
          info: files promise '/tmp/file-symlink-file-exists' repaired
          info: Linked files '/tmp/file-symlink-explicit' -> '/tmp/file'
          info: files promise '/tmp/file-symlink-explicit' repaired
          info: Deleted file '/tmp/file-symlink-explicit'
          info: files promise '/tmp/file-symlink-explicit' repaired
      R: /home/nickanderson/org/cfengine3-FJj5BU FAIL
      R: /tmp/file-symlink-this-promiser should have been deleted but wasn't
      R: /tmp/file-symlink-file-exists should have been deleted but wasn't
      R: Note: /tmp/file-symlink-explicit was deleted as expected
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                a10042 Nick Anderson
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Summary Panel