summaryrefslogtreecommitdiff
path: root/lib/chef/provider/directory.rb
diff options
context:
space:
mode:
authorAdam Jacob <adam@hjksolutions.com>2008-04-28 22:46:39 -0700
committerAdam Jacob <adam@hjksolutions.com>2008-04-28 22:46:39 -0700
commit2307eb8a7abbbf87676359c9bdffe14758d7c1ad (patch)
tree9cf86efa34705af6d9697a5a62d6a6671c1efda7 /lib/chef/provider/directory.rb
parent21cc606e60acc25d8741757eacc2c5459cdd1472 (diff)
downloadchef-2307eb8a7abbbf87676359c9bdffe14758d7c1ad.tar.gz
Adding a directory resource and provider
Diffstat (limited to 'lib/chef/provider/directory.rb')
-rw-r--r--lib/chef/provider/directory.rb62
1 files changed, 62 insertions, 0 deletions
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