1
+ # frozen_string_literal: true
2
+
1
3
require 'etc'
2
4
3
5
# class to use in openssl providers to handle file permission (mode, group and owner)
@@ -14,8 +16,8 @@ def owner
14
16
15
17
def owner = ( should )
16
18
File . chown ( uid ( should ) , nil , resource [ :path ] )
17
- rescue => detail
18
- raise Puppet ::Error , _ ( "Failed to set owner to '% {should}': %{detail }" ) % { should : should , detail : detail } , detail . backtrace
19
+ rescue StandardError => e
20
+ raise Puppet ::Error , _ ( "Failed to set owner to '# {should } ': #{ e } " ) , detail . backtrace
19
21
end
20
22
21
23
def group
@@ -28,27 +30,27 @@ def group
28
30
29
31
def group = ( should )
30
32
File . chown ( nil , gid ( should ) , resource [ :path ] )
31
- rescue => detail
32
- raise Puppet ::Error , _ ( "Failed to set group to '% {should}': %{detail }" ) % { should : should , detail : detail } , detail . backtrace
33
+ rescue StandardError => e
34
+ raise Puppet ::Error , _ ( "Failed to set group to '# {should } ': #{ e } " ) , detail . backtrace
33
35
end
34
36
35
37
# Return the mode as an octal string, not as an integer.
36
38
def mode
37
39
if File . exist? ( @resource [ :path ] )
38
- '0%o' % ( File . stat ( @resource [ :path ] ) . mode & 0o07777 )
40
+ format ( '0%o' , ( File . stat ( @resource [ :path ] ) . mode & 0o07777 ) )
39
41
else
40
42
:absent
41
43
end
42
44
end
43
45
44
46
# Set the file mode, converting from a string to an integer.
45
47
def mode = ( should )
46
- File . chmod ( Integer ( '0' + should ) , @resource [ :path ] )
48
+ File . chmod ( Integer ( "0 #{ should } " ) , @resource [ :path ] )
47
49
end
48
50
49
51
def set_file_perm ( filename , owner = nil , group = nil , mode = nil )
50
52
File . chown ( uid ( owner ) , nil , resource [ :path ] ) if owner
51
53
File . chown ( nil , gid ( group ) , resource [ :path ] ) if group
52
- File . chmod ( Integer ( '0' + mode ) , filename ) if mode
54
+ File . chmod ( Integer ( "0 #{ mode } " ) , filename ) if mode
53
55
end
54
56
end
0 commit comments