summaryrefslogtreecommitdiff
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/provider/vcsrepo/cvs.rb87
-rw-r--r--lib/puppet/provider/vcsrepo/svn.rb6
-rw-r--r--lib/puppet/type/vcsrepo.rb32
3 files changed, 110 insertions, 15 deletions
diff --git a/lib/puppet/provider/vcsrepo/cvs.rb b/lib/puppet/provider/vcsrepo/cvs.rb
new file mode 100644
index 0000000..68d22c1
--- /dev/null
+++ b/lib/puppet/provider/vcsrepo/cvs.rb
@@ -0,0 +1,87 @@
+Puppet::Type.type(:vcsrepo).provide(:cvs) do
+ desc "Supports CVS repositories/workspaces"
+
+ commands :cvs => 'cvs'
+ defaultfor :cvs => :exists
+
+ def create
+ if !@resource.value(:source)
+ create_repository(@resource.value(:path))
+ else
+ checkout_repository
+ end
+ end
+
+ def exists?
+ if @resource.value(:source)
+ directory = File.join(@resource.value(:path), 'CVS')
+ else
+ directory = File.join(@resource.value(:path), 'CVSROOT')
+ end
+ File.directory?(directory)
+ end
+
+ def destroy
+ FileUtils.rm_rf(@resource.value(:path))
+ end
+
+ def revision
+ if File.exist?(tag_file)
+ contents = File.read(tag_file)
+ # Note: Doesn't differentiate between N and T entries
+ contents[1..-1]
+ else
+ 'MAIN'
+ end
+ end
+
+ def revision=(desired)
+ at_path do
+ cvs('update', '-r', desired, '.')
+ end
+ end
+
+ private
+
+ def tag_file
+ File.join(@resource.value(:path), 'CVS', 'Tag')
+ end
+
+ def checkout_repository
+ dirname, basename = File.split(@resource.value(:path))
+ Dir.chdir(dirname) do
+ args = ['-d', @resource.value(:source)]
+ if @resource.value(:compression)
+ args.push('-z', @resource.value(:compression))
+ end
+ args.push('checkout', '-d', basename, module_name)
+ cvs(*args)
+ end
+ if @resource.value(:revision)
+ self.revision = @resource.value(:revision)
+ end
+ end
+
+ # When the source:
+ # * Starts with ':' (eg, :pserver:...)
+ def module_name
+ if (source = @resource.value(:source))
+ source[0, 1] == ':' ? File.basename(source) : '.'
+ end
+ end
+
+ def create_repository(path)
+ cvs('-d', path, 'init')
+ end
+
+ # Note: We don't rely on Dir.chdir's behavior of automatically returning the
+ # value of the last statement -- for easier stubbing.
+ def at_path(&block) #:nodoc:
+ value = nil
+ Dir.chdir(@resource.value(:path)) do
+ value = yield
+ end
+ value
+ end
+
+end
diff --git a/lib/puppet/provider/vcsrepo/svn.rb b/lib/puppet/provider/vcsrepo/svn.rb
index 226cc63..c85ffa4 100644
--- a/lib/puppet/provider/vcsrepo/svn.rb
+++ b/lib/puppet/provider/vcsrepo/svn.rb
@@ -56,12 +56,6 @@ Puppet::Type.type(:vcsrepo).provide(:svn) do
svnadmin(*args)
end
- def reset(desired)
- at_path do
- git('reset', '--hard', desired)
- end
- end
-
# Note: We don't rely on Dir.chdir's behavior of automatically returning the
# value of the last statement -- for easier stubbing.
def at_path(&block) #:nodoc:
diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb
index b093910..7616f41 100644
--- a/lib/puppet/type/vcsrepo.rb
+++ b/lib/puppet/type/vcsrepo.rb
@@ -13,12 +13,20 @@ Puppet::Type.newtype(:vcsrepo) do
def retrieve
prov = @resource.provider
if prov
- if prov.respond_to?(:working_copy_exists?) && prov.working_copy_exists?
- :present
- elsif prov.respond_to?(:bare_exists?) && prov.bare_exists?
- :bare
+ if prov.respond_to?(:bare_exists?)
+ if prov.respond_to?(:working_copy_exists?) && prov.working_copy_exists?
+ :present
+ elsif prov.respond_to?(:bare_exists?) && prov.bare_exists?
+ :bare
+ else
+ :absent
+ end
else
- :absent
+ if prov.exists?
+ :present
+ else
+ :absent
+ end
end
else
:absent
@@ -39,10 +47,7 @@ Puppet::Type.newtype(:vcsrepo) do
end
newparam(:source) do
- desc "The source URL for the repository"
- validate do |value|
- URI.parse(value)
- end
+ desc "The source URI for the repository"
end
newparam(:fstype) do
@@ -54,4 +59,13 @@ Puppet::Type.newtype(:vcsrepo) do
newvalue(/^\S+$/)
end
+ newparam :compression do
+ desc "Compression level (used by CVS)"
+ validate do |amount|
+ unless Integer(amount).between?(0, 6)
+ raise ArgumentError, "Unsupported compression level: #{amount} (expected 0-6)"
+ end
+ end
+ end
+
end