Skip to content

Commit bd2d5c7

Browse files
committed
Merge pull request puppetlabs#915 from runejuhl/support-symbolic-filemode
Add support for symbolic file modes
2 parents a656880 + 7d5d99d commit bd2d5c7

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,14 @@ Unacceptable input example:
299299

300300
Matches acceptable ensure values for service resources.
301301

302-
Acceptable input examples:
302+
Acceptable input examples:
303303

304304
```shell
305305
stopped
306306
running
307307
```
308308

309-
Unacceptable input example:
309+
Unacceptable input example:
310310

311311
```shell
312312
true
@@ -371,7 +371,7 @@ C:/whatever
371371

372372
#### `Stdlib::Filemode`
373373

374-
Matches valid four digit modes in octal format.
374+
Matches octal file modes consisting of 1 to 4 numbers and symbolic file modes.
375375

376376
Acceptable input examples:
377377

@@ -383,10 +383,14 @@ Acceptable input examples:
383383
1777
384384
```
385385

386+
```shell
387+
a=Xr,g=w
388+
```
389+
386390
Unacceptable input examples:
387391

388392
```shell
389-
644
393+
x=r,a=wx
390394
```
391395

392396
```shell

spec/type_aliases/filemode_spec.rb

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1+
# coding: utf-8
2+
13
require 'spec_helper'
24

35
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
46
describe 'Stdlib::Filemode' do
57
describe 'valid modes' do
6-
['0644', '1644', '2644', '4644', '0123', '0777'].each do |value|
8+
[
9+
'7',
10+
'12',
11+
'666',
12+
13+
'0000',
14+
'0644',
15+
'1644',
16+
'2644',
17+
'4644',
18+
'0123',
19+
'0777',
20+
21+
'a=,o-r,u+X,g=w',
22+
'a=Xr,+0',
23+
'u=rwx,g+rX',
24+
'u+s,g-s',
25+
].each do |value|
726
describe value.inspect do
827
it { is_expected.to allow_value(value) }
928
end
@@ -13,21 +32,22 @@
1332
describe 'invalid modes' do
1433
context 'with garbage inputs' do
1534
[
35+
true,
36+
false,
37+
:keyword,
1638
nil,
1739
[nil],
1840
[nil, nil],
1941
{ 'foo' => 'bar' },
2042
{},
2143
'',
2244
'ネット',
23-
'644',
24-
'7777',
25-
'1',
26-
'22',
27-
'333',
2845
'55555',
2946
'0x123',
3047
'0649',
48+
49+
'=8,X',
50+
'x=r,a=wx',
3151
].each do |value|
3252
describe value.inspect do
3353
it { is_expected.not_to allow_value(value) }

types/filemode.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
type Stdlib::Filemode = Pattern[/^[0124]{1}[0-7]{3}$/]
1+
# See `man chmod.1` for the regular expression for symbolic mode
2+
type Stdlib::Filemode = Pattern[/^(([0-7]{1,4})|(([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+)(,([ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+))*))$/]

0 commit comments

Comments
 (0)