Whitespace
[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, :configuration
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
52     if @resource.value(:force)
53       args.push('--force')
54     end
55
56     if @resource.value(:configuration)
57       args.push('--config-dir', @resource.value(:configuration))
58     end
59
60     return args
61   end
62
63   def latest
64     args = buildargs.push('info', '-r', 'HEAD')
65     at_path do
66       svn(*args)[/^Last Changed Rev:\s+(\d+)/m, 1]
67     end
68   end
69
70   def revision
71     args = buildargs.push('info')
72     at_path do
73       svn(*args)[/^Last Changed Rev:\s+(\d+)/m, 1]
74     end
75   end
76
77   def revision=(desired)
78     args = buildargs.push('update', '-r', desired)
79     at_path do
80       svn(*args)
81     end
82     update_owner
83   end
84
85   private
86
87   def checkout_repository(source, path, revision)
88     args = buildargs.push('checkout')
89     if revision
90       args.push('-r', revision)
91     end
92     args.push(source, path)
93     svn(*args)
94   end
95
96   def create_repository(path)
97     args = ['create']
98     if @resource.value(:fstype)
99       args.push('--fs-type', @resource.value(:fstype))
100     end
101     args << path
102     svnadmin(*args)
103   end
104
105   def update_owner
106     if @resource.value(:owner) or @resource.value(:group)
107       set_ownership
108     end
109   end
110 end