Skip to content

Commit 5bc60d0

Browse files
committed
vcsrepo: add mode option
Signed-off-by: Robin H. Johnson <[email protected]> Reference: #598
1 parent 051cbc0 commit 5bc60d0

File tree

12 files changed

+69
-23
lines changed

12 files changed

+69
-23
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).
44

5+
## UNRELEASED
6+
7+
### Added
8+
9+
- support for directory modes for repos [\#599](https://github.com/puppetlabs/puppetlabs-vcsrepo/issues/599) ([robbat2](https://github.com/robbat2))
10+
511
## [v5.4.0](https://github.com/puppetlabs/puppetlabs-vcsrepo/tree/v5.4.0) (2023-01-31)
612

713
[Full Changelog](https://github.com/puppetlabs/puppetlabs-vcsrepo/compare/v5.3.0...v5.4.0)

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -785,37 +785,37 @@ For information on the classes and types, see the [REFERENCE.md](https://github.
785785

786786
Features: `bare_repositories`, `depth`, `multiple_remotes`, `reference_tracking`, `ssh_identity`, `submodules`, `user`
787787

788-
Parameters: `depth`, `ensure`, `excludes`, `force`, `group`, `identity`, `owner`, `path`, `provider`, `remote`, `revision`, `source`, `user`
788+
Parameters: `depth`, `ensure`, `excludes`, `force`, `group`, `identity`, `owner`, `path`, `provider`, `remote`, `revision`, `source`, `user`, `mode`
789789

790790
##### `bzr` - Supports the Bazaar VCS.
791791

792792
Features: `reference_tracking`
793793

794-
Parameters: `ensure`, `excludes`, `force`, `group`, `owner`, `path`, `provider`, `revision`, `source`
794+
Parameters: `ensure`, `excludes`, `force`, `group`, `owner`, `path`, `provider`, `revision`, `source`, `mode`
795795

796796
##### `cvs` - Supports the CVS VCS.
797797

798798
Features: `cvs_rsh`, `gzip_compression`, `modules`, `reference_tracking`, `user`
799799

800-
Parameters: `compression`, `cvs_rsh`, `ensure`, `excludes`, `force`, `group`, `module`, `owner`, `path`, `provider`
800+
Parameters: `compression`, `cvs_rsh`, `ensure`, `excludes`, `force`, `group`, `module`, `owner`, `path`, `provider`, `mode`
801801

802802
##### `hg` - Supports the Mercurial VCS.
803803

804804
Features: `reference_tracking`, `ssh_identity`, `user`
805805

806-
Parameters: `ensure`, `excludes`, `force`, `group`, `identity`, `owner`, `path`, `provider`, `revision`, `source`, `user`
806+
Parameters: `ensure`, `excludes`, `force`, `group`, `identity`, `owner`, `path`, `provider`, `revision`, `source`, `user`, `mode`
807807

808808
##### `p4` - Supports the Perforce VCS.
809809

810810
Features: `p4config`, `reference_tracking`
811811

812-
Parameters: `ensure`, `excludes`, `force`, `group`, `owner`, `p4config`, `path`, `provider`, `revision`, `source`
812+
Parameters: `ensure`, `excludes`, `force`, `group`, `owner`, `p4config`, `path`, `provider`, `revision`, `source`, `mode`
813813

814814
##### `svn` - Supports the Subversion VCS.
815815

816816
Features: `basic_auth`, `configuration`, `conflict`, `depth`, `filesystem_types`, `reference_tracking`
817817

818-
Parameters: `basic_auth_password`, `basic_auth_username`, `configuration`, `conflict`, `ensure`, `excludes`, `force`, `fstype`, `group`, `includes`, `owner`, `path`, `provider`, `revision`, `source`, `trust_server_cert`
818+
Parameters: `basic_auth_password`, `basic_auth_username`, `configuration`, `conflict`, `ensure`, `excludes`, `force`, `fstype`, `group`, `includes`, `owner`, `path`, `provider`, `revision`, `source`, `trust_server_cert`, `mode`
819819

820820
<a id="features"></a>
821821
#### Features

REFERENCE.md

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ The following parameters are available in the `vcsrepo` type.
7777
* [`trust_server_cert`](#-vcsrepo--trust_server_cert)
7878
* [`umask`](#-vcsrepo--umask)
7979
* [`user`](#-vcsrepo--user)
80+
* [`mode`](#-vcsrepo--mode)
8081

8182
##### <a name="-vcsrepo--basic_auth_password"></a>`basic_auth_password`
8283

@@ -203,3 +204,6 @@ Sets the umask to be used for all repo operations
203204

204205
The user to run for repository operations
205206

207+
##### <a name="-vcsrepo--mode"></a>`mode`
208+
209+
Sets the mode for the repository directory (non-recursive).

lib/puppet/provider/vcsrepo.rb

+11-3
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,26 @@ def check_force
1515

1616
private
1717

18-
def set_ownership
18+
def set_ownership_and_permissions
1919
owner = @resource.value(:owner) || nil
2020
group = @resource.value(:group) || nil
21+
mode = @resource.value(:mode) || nil
2122
excludes = @resource.value(:excludes) || nil
23+
# Change the permission on the repo itself.
24+
# The VCS should maintain permissions on files within the checkout.
25+
FileUtils.chmod(mode, @resource.value(:path)) unless mode.nil?
26+
# We might have no work to do, and this makes it easier for the callers.
27+
return if owner.nil? && group.nil?
28+
2229
if excludes.nil? || excludes.empty?
23-
FileUtils.chown_R(owner, group, @resource.value(:path))
30+
FileUtils.chown_R(owner, group, @resource.value(:path)) unless owner.nil? && group.nil?
2431
else
25-
FileUtils.chown(owner, group, files)
32+
FileUtils.chown(owner, group, files) unless owner.nil? && group.nil?
2633
end
2734
end
2835

2936
def files
37+
# Expensive on large repos
3038
excludes = @resource.value(:excludes)
3139
path = @resource.value(:path)
3240
Dir["#{path}/**/*"].reject { |f| excludes.any? { |p| f.start_with?("#{path}/#{p}") } }

lib/puppet/provider/vcsrepo/bzr.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,6 @@ def clone_repository(revision)
103103
end
104104

105105
def update_owner
106-
set_ownership if @resource.value(:owner) || @resource.value(:group)
106+
set_ownership_and_permissions if @resource.value(:owner) || @resource.value(:group) || @resource.value(:mode)
107107
end
108108
end

lib/puppet/provider/vcsrepo/cvs.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def create_repository(path)
136136
end
137137

138138
def update_owner
139-
set_ownership if @resource.value(:owner) || @resource.value(:group)
139+
set_ownership_and_permissions if @resource.value(:owner) || @resource.value(:group) || @resource.value(:mode)
140140
end
141141

142142
def runcvs(*args)

lib/puppet/provider/vcsrepo/git.rb

+12-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def create
3939
end
4040

4141
end
42-
update_owner_and_excludes
42+
update_owner_permission_and_excludes
4343
end
4444

4545
def destroy
@@ -101,7 +101,7 @@ def revision=(desired)
101101
if !ensure_bare_or_mirror? && @resource.value(:submodules) == :true
102102
update_submodules
103103
end
104-
update_owner_and_excludes
104+
update_owner_permission_and_excludes
105105
end
106106

107107
def bare_exists?
@@ -239,7 +239,7 @@ def update_references
239239
at_path do
240240
git_remote_action('fetch', @resource.value(:remote))
241241
git_remote_action(*fetch_tags_args, @resource.value(:remote))
242-
update_owner_and_excludes
242+
update_owner_permission_and_excludes
243243
end
244244
end
245245

@@ -256,6 +256,8 @@ def convert_working_copy_to_bare
256256
FileUtils.mv(File.join(@resource.value(:path), '.git'), tempdir)
257257
FileUtils.rm_rf(@resource.value(:path))
258258
FileUtils.mv(tempdir, @resource.value(:path))
259+
FileUtils.chown(@resource.value(:user), @resource.value(:group), @resource.value(:path)) if @resource.value(:user) || @resource.value(:group)
260+
FileUtils.chmod(@resource.value(:mode), @resource.value(:path)) if @resource.value(:mode)
259261
at_path do
260262
exec_git('config', '--local', '--bool', 'core.bare', 'true')
261263
return unless @resource.value(:ensure) == :mirror
@@ -275,13 +277,15 @@ def convert_bare_to_working_copy
275277
notice 'Converting bare repository to working copy repository'
276278
FileUtils.mv(@resource.value(:path), tempdir)
277279
FileUtils.mkdir(@resource.value(:path))
280+
FileUtils.chown(@resource.value(:user), @resource.value(:group), @resource.value(:path)) if @resource.value(:user) || @resource.value(:group)
281+
FileUtils.chmod(@resource.value(:mode), @resource.value(:path)) if @resource.value(:mode)
278282
FileUtils.mv(tempdir, File.join(@resource.value(:path), '.git'))
279283
if commits?
280284
at_path do
281285
exec_git('config', '--local', '--bool', 'core.bare', 'false')
282286
reset('HEAD')
283287
git_with_identity('checkout', '--force')
284-
update_owner_and_excludes
288+
update_owner_permission_and_excludes
285289
end
286290
end
287291
set_no_mirror if mirror?
@@ -415,7 +419,8 @@ def init_repository
415419
else
416420
# normal init
417421
FileUtils.mkdir(@resource.value(:path))
418-
FileUtils.chown(@resource.value(:user), nil, @resource.value(:path)) if @resource.value(:user)
422+
FileUtils.chown(@resource.value(:user), @resource.value(:group), @resource.value(:path)) if @resource.value(:user) || @resource.value(:group)
423+
FileUtils.chmod(@resource.value(:mode), @resource.value(:path)) if @resource.value(:mode)
419424
args = ['init']
420425
if @resource.value(:ensure) == :bare
421426
args << '--bare'
@@ -598,10 +603,8 @@ def get_revision(rev = 'HEAD')
598603
end
599604

600605
# @!visibility private
601-
def update_owner_and_excludes
602-
if @resource.value(:owner) || @resource.value(:group)
603-
set_ownership
604-
end
606+
def update_owner_permission_and_excludes
607+
set_ownership_and_permissions if @resource.value(:owner) || @resource.value(:group) || @resource.value(:mode)
605608
set_excludes if @resource.value(:excludes)
606609
end
607610

lib/puppet/provider/vcsrepo/hg.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def clone_repository(revision)
116116
end
117117

118118
def update_owner
119-
set_ownership if @resource.value(:owner) || @resource.value(:group)
119+
set_ownership_and_permissions if @resource.value(:owner) || @resource.value(:group) || @resource.value(:mode)
120120
end
121121

122122
def sensitive?

lib/puppet/provider/vcsrepo/p4.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def source=(_desired)
101101
private
102102

103103
def update_owner
104-
set_ownership if @resource.value(:owner) || @resource.value(:group)
104+
set_ownership_and_permissions if @resource.value(:owner) || @resource.value(:group) || @resource.value(:mode)
105105
end
106106

107107
# Sync the client workspace files to head or specified revision.

lib/puppet/provider/vcsrepo/svn.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def create_repository(path)
265265
end
266266

267267
def update_owner
268-
set_ownership if @resource.value(:owner) || @resource.value(:group)
268+
set_ownership_and_permissions if @resource.value(:owner) || @resource.value(:group) || @resource.value(:mode)
269269
end
270270

271271
def update_includes(paths)

lib/puppet/type/vcsrepo.rb

+4
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ def insync?(is)
215215
desc 'The group/gid that owns the repository files'
216216
end
217217

218+
newparam :mode do
219+
desc 'The permission for the repository directory itself (not recursive)'
220+
end
221+
218222
newparam :user do
219223
desc 'The user to run for repository operations'
220224
end

spec/acceptance/clone_repo_spec.rb

+21
Original file line numberDiff line numberDiff line change
@@ -624,4 +624,25 @@
624624
it { is_expected.to be_mode '664' }
625625
end
626626
end
627+
628+
context 'with mode' do
629+
pp = <<-MANIFEST
630+
vcsrepo { "#{tmpdir}/testrepo_mode":
631+
ensure => present,
632+
provider => git,
633+
source => "file://#{tmpdir}/testrepo.git",
634+
mode => 'u=rwX,g=rX,o=X',
635+
}
636+
MANIFEST
637+
it 'clones a repo' do
638+
# Run it twice and test for idempotency
639+
idempotent_apply(pp)
640+
end
641+
642+
describe file("#{tmpdir}/testrepo_mode") do
643+
# NOTE: '0664' is not supported by 'be_mode'; this must be three digits
644+
# unless the first octet is non-zero.
645+
it { is_expected.to be_mode '751' }
646+
end
647+
end
627648
end

0 commit comments

Comments
 (0)