On Apr 3, 2010, at 3:06 PM, Markus Roberts wrote:

> >This could be reduced to:

           content_checksum = Puppet::Util.withumask(umask) do
File.open(path, File::CREAT|File::WRONLY|File::TRUNC, mode) { |f| write_content(f) }
           end

Or if I'm not mistaken:

content_checksum = Puppet::Util.withumask(umask) { File.open(path,'w' , mode) { |f| write_content(f) } }

I don't think 'w' does FILE::TRUNC - that is, it appends rather than overwrites, and we specifically always want to overwrite.

I'd bet lunch that "a" that appends and that "w" truncates (to make it a fair bet, I haven't actually checked yet).

Hmphf.  You're right.

You can all start calling me Luke "is there some way we can make this more complex?" Kanies, I guess. :/


+        def write_content(file)
+            checksum = nil
+            if content = property(:content)
+                checksum = content.write(file)
+            else # we have a sole ensure property
+                file.print ""
+            end
+            checksum
+        end

What is the purpose of the

    file.print ""

That is, opening a file and then closing it without writing anything still creates it in all OSes, right? Isn't this routine doing the same thing as:

       def write_content(file)
           (content = property(:content)) && content.write(file)l
       end


If you say 'ensure => file' but don't specify content, we need to just create an empty file, and this seemed the easiest way to do that. I suppose :ensure could instead set 'content' to "", but I don't know that that's particularly cleaner.

Ok, but if you don't have content (it's nil) this will open the file and close it without writing anything to it which should, if I'm not mistaken, create an empty file. We shouldn't need to do anything else (set content to "", print a "" if content is nil, or anything else). Does that make sense?

Based on my score here, just do what you think is reasonable. :)

--
An entrepreneur is somebody who steals office supplies from home and
brings them into work. -- Auren Hoffman
---------------------------------------------------------------------
Luke Kanies  -|-   http://puppetlabs.com   -|-   +1(615)594-8199

--
You received this message because you are subscribed to the Google Groups "Puppet 
Developers" group.
To post to this group, send email to puppet-...@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to