diff options
author | Adam Jacob <adam@hjksolutions.com> | 2008-04-28 22:46:39 -0700 |
---|---|---|
committer | Adam Jacob <adam@hjksolutions.com> | 2008-04-28 22:46:39 -0700 |
commit | 2307eb8a7abbbf87676359c9bdffe14758d7c1ad (patch) | |
tree | 9cf86efa34705af6d9697a5a62d6a6671c1efda7 /lib | |
parent | 21cc606e60acc25d8741757eacc2c5459cdd1472 (diff) | |
download | chef-2307eb8a7abbbf87676359c9bdffe14758d7c1ad.tar.gz |
Adding a directory resource and provider
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/platform.rb | 3 | ||||
-rw-r--r-- | lib/chef/provider.rb | 2 | ||||
-rw-r--r-- | lib/chef/provider/directory.rb | 62 |
3 files changed, 65 insertions, 2 deletions
diff --git a/lib/chef/platform.rb b/lib/chef/platform.rb index bebdcfa297..a37bb105c8 100644 --- a/lib/chef/platform.rb +++ b/lib/chef/platform.rb @@ -32,7 +32,8 @@ class Chef :gentoo => {}, :solaris => {}, :default => { - :file => Chef::Provider::File + :file => Chef::Provider::File, + :directory => Chef::Provider::Directory } } diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb index 018f687069..32e2491028 100644 --- a/lib/chef/provider.rb +++ b/lib/chef/provider.rb @@ -30,7 +30,7 @@ class Chef end def action_nothing - Chef::Log.debug("Doing nothing for #{self.to_s}") + Chef::Log.debug("Doing nothing for #{@new_resource.to_s}") true end diff --git a/lib/chef/provider/directory.rb b/lib/chef/provider/directory.rb new file mode 100644 index 0000000000..e30ca1894d --- /dev/null +++ b/lib/chef/provider/directory.rb @@ -0,0 +1,62 @@ +# +# Author:: Adam Jacob (<adam@hjksolutions.com>) +# Copyright:: Copyright (c) 2008 HJK Solutions, LLC +# License:: GNU General Public License version 2 or later +# +# This program and entire repository is free software; you can +# redistribute it and/or modify it under the terms of the GNU +# General Public License as published by the Free Software +# Foundation; either version 2 of the License, or any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +require 'digest/md5' +require 'etc' +require File.join(File.dirname(__FILE__), "file") + +class Chef + class Provider + class Directory < Chef::Provider::File + def load_current_resource + @current_resource = Chef::Resource::Directory.new(@new_resource.name) + @current_resource.path(@new_resource.path) + if ::File.exist?(@current_resource.path) && ::File.directory?(@current_resource.path) + cstats = ::File.stat(@current_resource.path) + @current_resource.owner(cstats.uid) + @current_resource.group(cstats.gid) + @current_resource.mode("%o" % (cstats.mode & 007777)) + end + @current_resource + end + + def action_create + unless ::File.exists?(@new_resource.path) + Chef::Log.info("Creating #{@new_resource} at #{@new_resource.path}") + ::Dir.mkdir(@new_resource.path) + @new_resource.updated = true + end + set_owner if @new_resource.owner != nil + set_group if @new_resource.group != nil + set_mode if @new_resource.mode != nil + end + + def action_delete + if ::File.exists?(@new_resource.path) && ::File.writable?(@new_resource.path) + Chef::Log.info("Deleting #{@new_resource} at #{@new_resource.path}") + ::Dir.delete(@new_resource.path) + @new_resource.updated = true + else + raise RuntimeError, "Cannot delete #{@new_resource} at #{@new_resource_path}!" if ::File.exists?(@new_resource.path) + end + end + end + end +end
\ No newline at end of file |