Merge pull request #35 from sodabrew/dummy-provider
[puppet_vcsrepo.git] / lib / puppet / provider / vcsrepo / svn.rb
1 require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
2
3 Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo) do
4   desc "Supports Subversion repositories"
5
6   optional_commands :svn      => 'svn',
7            :svnadmin => 'svnadmin'
8
9   has_features :filesystem_types, :reference_tracking, :basic_auth
10
11   def create
12     if !@resource.value(:source)
13       create_repository(@resource.value(:path))
14     else
15       checkout_repository(@resource.value(:source),
16                           @resource.value(:path),
17                           @resource.value(:revision))
18     end
19     update_owner
20   end
21
22   def working_copy_exists?
23     File.directory?(File.join(@resource.value(:path), '.svn'))
24   end
25
26   def exists?
27     working_copy_exists?
28   end
29
30   def destroy
31     FileUtils.rm_rf(@resource.value(:path))
32   end
33
34   def latest?
35     at_path do
36       if self.revision < self.latest then
37         return false
38       else
39         return true
40       end
41     end
42   end
43
44   def buildargs
45     args = ['--non-interactive']
46     if @resource.value(:basic_auth_username) && @resource.value(:basic_auth_password)
47       args.push('--username', @resource.value(:basic_auth_username))
48       args.push('--password', @resource.value(:basic_auth_password))
49       args.push('--no-auth-cache')
50     end
51     return args
52   end
53
54   def latest
55     args = buildargs.push('info', '-r', 'HEAD')
56     at_path do
57       svn(*args)[/^Last Changed Rev:\s+(\d+)/m, 1]
58     end
59   end
60
61   def revision
62     args = buildargs.push('info')
63     at_path do
64       svn(*args)[/^Last Changed Rev:\s+(\d+)/m, 1]
65     end
66   end
67
68   def revision=(desired)
69     args = buildargs.push('update', '-r', desired)
70     at_path do
71       svn(*args)
72     end
73     update_owner
74   end
75
76   private
77
78   def checkout_repository(source, path, revision)
79     args = buildargs.push('checkout')
80     if revision
81       args.push('-r', revision)
82     end
83     args.push(source, path)
84     svn(*args)
85   end
86
87   def create_repository(path)
88     args = ['create']
89     if @resource.value(:fstype)
90       args.push('--fs-type', @resource.value(:fstype))
91     end
92     args << path
93     svnadmin(*args)
94   end
95
96   def update_owner
97     if @resource.value(:owner) or @resource.value(:group)
98       set_ownership
99     end
100   end
101 end