Git Product home page Git Product logo

Comments (4)

MarkGibbons avatar MarkGibbons commented on August 19, 2024 1

I'll probably add something to allow folks to avoid your initial situation. Repeated inserts is a really nasty thing to have happen.

from line.

MarkGibbons avatar MarkGibbons commented on August 19, 2024

HI mrswadge,

The sample filters are intended to be idempotent. They are designed to do what you want to tell them to do. They should not insert a line multiple times. Do you have an example of using filter_lines that inserts lines over and over again?

Thinking about it, this might be the case you have a problem with.

In your example above if the newline you insert matches the regex in match then every time the resource runs lines will be inserted. Both after the original match and after the newline match. I can make that experience safer by disallowing that case. The replace filter (not yet published) won't let you insert lines that would be replaced for instance.

Thanks,
Mark

from line.

mrswadge avatar mrswadge commented on August 19, 2024

Hi Mark,

I've worked out what my issue was now and I believe that it is working as intended. My action was modifying a java.security file, specifically the area below.

#
# Default login configuration file
#
#login.config.url.1=file:${user.home}/.java.login.config

I was using the following code

def to_regexp(value, flags=Regexp::IGNORECASE)
  return (value.instance_of? Regexp) ? value : Regexp.new("#{Regexp.escape(value)}", flags)
end

match = to_regexp('login.config.url.1')
newline = 'login.config.url.1=file:${java.home}/lib/security/Application.login.config'

filter_lines "modify #{path}/java.security" do
  path "#{path}/java.security"
  filters after: [match, newline, :last]
end

First time it correctly inserted the line:

#
# Default login configuration file
#
#login.config.url.1=file:${user.home}/.java.login.config
login.config.url.1=file:${java.home}/lib/security/Application.login.config

Each subsequent time it added a new line.

#
# Default login configuration file
#
#login.config.url.1=file:${user.home}/.java.login.config
login.config.url.1=file:${java.home}/lib/security/Application.login.config
login.config.url.1=file:${java.home}/lib/security/Application.login.config

To stop this, I have now changed my match to the following and this is now idempotent.

match = to_regexp('#login.config.url.1')

I will close off this issue.

Cheers,
Stuart

from line.

lock avatar lock commented on August 19, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

from line.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.