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

File editing should promise lock the file promise not individual line promises

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Done
    • Priority: (None)
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Promise type: files
    • Labels:
      None

      Description

      Any type of edit_line or edit_template promise breaks down into separate
      promises for each line to be edited in the promiser file. This leads to
      odd behavior. When combined with an empty it is possible for the file
      to not contain all the required lines because some lines were locked
      during the run. Consider this example:

      <pre>
      body common control {

      bundlesequence =>

      { "main", }

      ;

      inputs =>

      { "cfengine_stdlib.cf", }

      ;
      }

      bundle agent main

      { methods: "any" usebundle => test; }

      bundle agent test {

      files:
      "/tmp/editline.txt"
      create => 'true',
      edit_defaults => empty,
      edit_template => "${sys.workdir}/inputs/editline.tmp";
      }
      </pre>

      And the template:
      <pre>
      [%CFEngine linux:: %]
      line1
      line2
      line3

      [%CFEngine line4:: %]
      line4

      [%CFEngine never:: %]
      line5

      </pre>
      If you run it and get the right timing with locks. This happens:

      <pre>
      neil@ettin ~/.cfagent/inputs $ cf-agent -If ./editline.cf -D line4 &&
      cat /tmp/editline.txt
      line1
      line2
      line3

      neil@ettin ~/.cfagent/inputs $ cf-agent -If ./editline.cf -D line4 &&
      cat /tmp/editline.txt
      -> Edited file /tmp/editline.txt
      !! Method invoked repairs
      line4

      </pre>
      I think the lock should be on the original promiser file and not the
      individual lines that may or may not make up the file. It would be more efficient.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                neilhwatson Neil Watson
              • Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Summary Panel