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

touch should work with depth_search

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Lowest
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Promise type: files
    • Labels:
      None

      Description

      ;TLDR: Workaround use transformer instead of touch.

      While working on a simple example I found that the touch attribute to files promsies does not seem to work in combination with depth_search.

      Setup test structure

      rm -rf /tmp/example
      mkdir /tmp/example
      mkdir /tmp/example/dir1 
      touch /tmp/example/dir1/file1
      mkdir /tmp/example/dir1/.hidden_dir/
      touch /tmp/example/dir1/.hidden_dir/file1
      mkdir /tmp/example/dir2 
      touch /tmp/example/dir2/file1
      find /tmp/example | xargs stat | egrep "File|Modify"
      
        File: /tmp/example
      Modify: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir2
      Modify: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir2/file1
      Modify: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir1
      Modify: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir1/.hidden_dir
      Modify: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir1/.hidden_dir/file1
      Modify: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir1/file1
      Modify: 2017-09-07 12:53:38.192358301 -0500
      

      This policy is expected to update the modification time stamp of all files an directories except for those files and directories under directories that match the exclusion regex.

      body agent control { inform => "true"; }
      bundle agent main
      {
        vars:
          "exclude_dirs" slist => { "dir2", "\..*" }; # Exclude dirs named dir2 and any hidden directories
      
        files:
      
          # Update timestamp on all files except those in excluded directories. Not
          # the promised directory itself (because include_basedir isnt set in the
          # recurse_ignore body)
      
          "/tmp/example/"
            depth_search => recurse_ignore(inf, @(exclude_dirs) ),
            file_select => all,
            touch => "true";
      }
      

      There was no output indicating that cfengine made any changes and looking at timestamps we see none changed though I expected /tmp/example/dir1 and /tmp/example/dir1/file1 should have been updated.

      find /tmp/example | xargs stat | egrep "File|Modify|Change"
      
        File: /tmp/example
      Modify: 2017-09-07 12:53:38.192358301 -0500
      Change: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir2
      Modify: 2017-09-07 12:53:38.192358301 -0500
      Change: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir2/file1
      Modify: 2017-09-07 12:53:38.192358301 -0500
      Change: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir1
      Modify: 2017-09-07 12:53:38.192358301 -0500
      Change: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir1/.hidden_dir
      Modify: 2017-09-07 12:53:38.192358301 -0500
      Change: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir1/.hidden_dir/file1
      Modify: 2017-09-07 12:53:38.192358301 -0500
      Change: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir1/file1
      Modify: 2017-09-07 12:53:38.192358301 -0500
      Change: 2017-09-07 12:53:38.192358301 -0500
      

      Interestingly if I use a different attribute like transformer I can see that the depth_search directory exclusion seems to have applied correctly.

      body agent control { inform => "true"; }
      bundle agent main
      {
        vars:
          "exclude_dirs" slist => { "dir2", "\..*"  }; # Exclude dirs named dir2 and any hidden directories
      
            #depth_search => recurse_ignore(inf, @(exclude_dirs) ),
        files:
          # Update timestamp on all files except those in excluded directories
          "/tmp/example/"
            depth_search => recurse_ignore(inf, @(exclude_dirs) ),
            file_select => all,
            transformer => "/usr/bin/touch $(this.promiser)";
      }
      
      info: Transforming '/usr/bin/touch /tmp/example/dir1/file1' 
      info: Transformer '/tmp/example/dir1/file1' => '/usr/bin/touch /tmp/example/dir1/file1' seemed to work ok
      info: Transforming '/usr/bin/touch /tmp/example/dir1' 
      info: Transformer '/tmp/example/dir1' => '/usr/bin/touch /tmp/example/dir1' seemed to work ok
      

      We can see from the policy output that only /tmp/example/dir1 and /tmp/example/dir1/file1 were touched as expected. And when we inspect the timestamps we can see that they have been updated for only those files as expected.

      find /tmp/example | xargs stat | egrep "File|Modify|Change"
      
        File: /tmp/example
      Modify: 2017-09-07 12:53:38.192358301 -0500
      Change: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir2
      Modify: 2017-09-07 12:53:38.192358301 -0500
      Change: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir2/file1
      Modify: 2017-09-07 12:53:38.192358301 -0500
      Change: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir1
      Modify: 2017-09-07 12:59:12.895331685 -0500
      Change: 2017-09-07 12:59:12.895331685 -0500
        File: /tmp/example/dir1/.hidden_dir
      Modify: 2017-09-07 12:53:38.192358301 -0500
      Change: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir1/.hidden_dir/file1
      Modify: 2017-09-07 12:53:38.192358301 -0500
      Change: 2017-09-07 12:53:38.192358301 -0500
        File: /tmp/example/dir1/file1
      Modify: 2017-09-07 12:59:12.895331685 -0500
      Change: 2017-09-07 12:59:12.895331685 -0500
      

        Attachments

          Activity

            People

            • Assignee:
              a10003 Eystein Maloy Stenberg
              Reporter:
              a10042 Nick Anderson
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:

                Summary Panel