summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-05-12 21:54:23 +0000
committerLuke Kanies <luke@madstop.com>2005-05-12 21:54:23 +0000
commit529b9a70d55fc720db1f601f832151e5a2f6b47e (patch)
tree6a450abd39604beaabe251f725afe77c5c91eb88 /lib
parent4e03ed1822014cc7d062183f92b76e4d6debeb88 (diff)
downloadpuppet-529b9a70d55fc720db1f601f832151e5a2f6b47e.tar.gz
puppet-529b9a70d55fc720db1f601f832151e5a2f6b47e.tar.xz
puppet-529b9a70d55fc720db1f601f832151e5a2f6b47e.zip
file recursion now works
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@244 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/blink/type/file.rb81
-rw-r--r--lib/blink/type/service.rb4
-rw-r--r--lib/blink/type/state.rb3
3 files changed, 74 insertions, 14 deletions
diff --git a/lib/blink/type/file.rb b/lib/blink/type/file.rb
index 88dac5176..c3de581e6 100644
--- a/lib/blink/type/file.rb
+++ b/lib/blink/type/file.rb
@@ -43,7 +43,7 @@ module Blink
def retrieve
stat = nil
- unless stat = self.parent.stat
+ unless stat = self.parent.stat(true)
self.is = -1
Blink.debug "chown state is %d" % self.is
return
@@ -100,17 +100,19 @@ module Blink
def initialize(should)
# this is pretty hackish, but i need to make sure the number is in
# octal, yet the number can only be specified as a string right now
- unless should =~ /^0/
- should = "0" + should
+ unless should.is_a?(Integer) # i've already converted it correctly
+ unless should =~ /^0/
+ should = "0" + should
+ end
+ should = Integer(should)
end
- should = Integer(should)
super(should)
end
def retrieve
stat = nil
- unless stat = self.parent.stat
+ unless stat = self.parent.stat(true)
# a value we know we'll never get in reality
self.is = -1
return
@@ -178,7 +180,7 @@ module Blink
def retrieve
stat = nil
- unless stat = self.parent.stat
+ unless stat = self.parent.stat(true)
self.is = -1
Blink.debug "chgrp state is %d" % self.is
return
@@ -246,17 +248,13 @@ module Blink
]
@parameters = [
- :path
+ :path,
+ :recurse
]
@name = :file
@namevar = :path
- def initialize(hash)
- super
- @stat = nil
- end
-
def stat(refresh = false)
if @stat.nil? or refresh == true
begin
@@ -271,8 +269,65 @@ module Blink
return @stat
end
+ def initialize(hash)
+ arghash = hash.dup
+ super
+ @stat = nil
+ Blink.notice arghash.inspect
+
+ # if recursion is enabled and we're a directory...
+ if @parameters[:recurse] and self.stat.directory?
+ recurse = self[:recurse]
+ # we might have a string, rather than a number
+ if recurse.is_a?(String)
+ if recurse =~ /^[0-9]+$/
+ recurse = Integer(recurse)
+ elsif recurse =~ /^inf/ # infinite recursion
+ recurse = true
+ end
+ end
+
+ # unless we're at the end of the recursion
+ if recurse != 0
+ arghash.delete("recurse")
+ if recurse.is_a?(Integer)
+ recurse -= 1 # reduce the level of recursion
+ end
+
+ arghash[:recurse] = recurse
+
+ # now make each contained file/dir a child
+ unless defined? @children
+ @children = []
+ end
+
+ Dir.foreach(self[:path]) { |file|
+ next if file =~ /^\.\.?/ # skip . and ..
+
+ arghash[:path] = ::File.join(self[:path],file)
+
+ # if one of these files already exists, we're going to
+ # fail here, because this will try to clobber, which is bad
+ # mmmkay
+ #@children.push self.class.new(arghash)
+ child = nil
+ # if the file already exists...
+ if child = self.class[arghash[:path]]
+ arghash.each { |var,value|
+ next if var == :path
+ child[var] = value
+ }
+ else # create it anew
+ child = self.class.new(arghash)
+ end
+ @children.push child
+ }
+ end
+ end
+ end
+
def sync
- if self.create and ! FileTest.exist?(self.path)
+ if @states[:create] and ! FileTest.exist?(self.path)
begin
File.open(self.path,"w") { # just create an empty file
}
diff --git a/lib/blink/type/service.rb b/lib/blink/type/service.rb
index 83f780c4e..ff2d1af56 100644
--- a/lib/blink/type/service.rb
+++ b/lib/blink/type/service.rb
@@ -99,6 +99,10 @@ module Blink
:pattern
]
+ @functions = [
+ :addpath
+ ]
+
@name = :service
@namevar = :name
diff --git a/lib/blink/type/state.rb b/lib/blink/type/state.rb
index 693bd35f9..57fcf5683 100644
--- a/lib/blink/type/state.rb
+++ b/lib/blink/type/state.rb
@@ -56,7 +56,8 @@ class Blink::State < Blink::Element
# we aren't actually comparing the states themselves, we're only
# comparing the "should" value with the "is" value
def insync?
- Blink.debug "%s value is %s, should be %s" % [self,self.is,self.should]
+ Blink.debug "%s value is '%s', should be '%s'" %
+ [self,self.is.inspect,self.should.inspect]
self.is == self.should
end
#---------------------------------------------------------------