New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial refactoring of yumrepo. #2086

Merged
merged 7 commits into from Feb 14, 2014
Next

(PUP-1066) Add the ability to delete files.

Add a .destory and .destroy? in order to flag files for deletion.
We also sneak in a .entries reader in order to let us read the
entries directly.

This should fix PUP-1066 and #12687.
  • Loading branch information...
Ashley Penney
Ashley Penney committed Feb 2, 2014
commit ce83c664bc87b904c45a3f192cf5fb00a385932a
View
@@ -13,13 +13,15 @@
module Puppet::Util::IniConfig
# A section in a .ini file
class Section
attr_reader :name, :file
attr_reader :name, :file, :entries
attr_writer :destroy
def initialize(name, file)
@name = name
@file = file
@dirty = false
@entries = []
@destroy = false
end
# Has this section been modified since it's been read in
@@ -33,6 +35,11 @@ def mark_clean
@dirty = false
end
# Should the file be destroyed?
def destroy?
@destroy
end
# Add a line of text (e.g., a comment) Such lines
# will be written back out in exactly the same
# place they were read in
@@ -142,18 +149,26 @@ def store
@files.each do |file, lines|
text = ""
dirty = false
destroy = false
lines.each do |l|
if l.is_a?(Section)
destroy ||= l.destroy?
dirty ||= l.dirty?
text << l.format
l.mark_clean
else
text << l
end
end
if dirty
Puppet::Util::FileType.filetype(:flat).new(file).write(text)
return file
# We delete the file and then remove it from the list of files.
if destroy
::File.unlink(file)
@files.delete(file)

This comment has been minimized.

@adrienthebo

adrienthebo Jan 22, 2014

Contributor

This has been a longstanding bug, it would be really good to link this change to the relevant tickets and update the PR message/commits to reflect that this is fixed.

@adrienthebo

adrienthebo Jan 22, 2014

Contributor

This has been a longstanding bug, it would be really good to link this change to the relevant tickets and update the PR message/commits to reflect that this is fixed.

This comment has been minimized.

else
if dirty
Puppet::Util::FileType.filetype(:flat).new(file).write(text)
return file
end
end
end
end
ProTip! Use n and p to navigate between commits in a pull request.