summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-07-12 05:51:43 +0000
committerLuke Kanies <luke@madstop.com>2005-07-12 05:51:43 +0000
commit99a9f4b0c16b42ea16e1df9e38714697215fc308 (patch)
tree1c18cf5996eb0e412aba4a4752db363a0d79fabb /lib/puppet
parentd6e2102643ea380c5e7b63a722dae31ed499571d (diff)
downloadpuppet-99a9f4b0c16b42ea16e1df9e38714697215fc308.tar.gz
puppet-99a9f4b0c16b42ea16e1df9e38714697215fc308.tar.xz
puppet-99a9f4b0c16b42ea16e1df9e38714697215fc308.zip
adding link functionality
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@376 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/type/pfile.rb76
1 files changed, 73 insertions, 3 deletions
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index 5ff0432cd..e8f50e74b 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -13,7 +13,6 @@ module Puppet
class State
class PFileCreate < Puppet::State
require 'etc'
- attr_accessor :file
@name = :create
@event = :file_created
@@ -160,9 +159,79 @@ module Puppet
end
end
+ class PFileLink < Puppet::State
+ require 'etc'
+ attr_reader :link
+
+ @name = :link
+
+ # create the link
+ def self.create(file,link)
+ begin
+ debug("Creating symlink '%s' to '%s'" % [file, link])
+ unless File.symlink(file,link)
+ raise TypeError.new("Could not create symlink '%s'" % link)
+ end
+ rescue => detail
+ raise TypeError.new("Cannot create symlink '%s': %s" %
+ [file,detail])
+ end
+ end
+
+ # remove an existing link
+ def self.remove(link)
+ if FileTest.symlink?(link)
+ debug("Removing symlink '%s'" % link)
+ begin
+ File.unlink(link)
+ rescue
+ raise TypeError.new("Failed to remove symlink '%s'" % link)
+ end
+ elsif FileTest.exists?(link)
+ raise TypeError.new("Cannot remove normal file '%s'" % link)
+ else
+ debug("Symlink '%s' does not exist" % link)
+ end
+ end
+
+ def retrieve
+ if FileTest.symlink?(@link)
+ self.is = File.readlink(@link)
+ return
+ else
+ self.is = nil
+ return
+ end
+ end
+
+ # we know the link should exist, but it should also point back
+ # to us
+ def should=(link)
+ @link = link
+ @should = self.parent[:path]
+
+ # unless we're fully qualified or we've specifically allowed
+ # relative links. Relative links are currently disabled, until
+ # someone actually asks for them
+ unless @should =~ /^\// or self.parent[:relativelinks]
+ @should = File.expand_path @should
+ end
+ end
+
+ # this is somewhat complicated, because it could exist and be
+ # a file
+ def sync
+ if @is
+ self.class.remove(@is)
+ end
+ self.class.create(@should,@link)
+
+ return :link_created
+ end
+ end
+
class PFileUID < Puppet::State
require 'etc'
- attr_accessor :file
@name = :owner
@event = :inode_changed
@@ -371,7 +440,8 @@ module Puppet
Puppet::State::PFileGroup,
Puppet::State::PFileMode,
Puppet::State::PFileChecksum,
- Puppet::State::PFileSetUID
+ Puppet::State::PFileSetUID,
+ Puppet::State::PFileLink,
]
@parameters = [