Skip to content

Commit 0b39f5a

Browse files
committed
return owner for files on windows
1 parent 1a38adc commit 0b39f5a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lib/train/extras/file_windows.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ def mounted
5151
nil
5252
end
5353

54+
# PS C:\> Get-Acl .\test | select owner,group,audit | ConvertTo-Json
55+
# {
56+
# "Owner": "BUILTIN\\Administrators",
57+
# "Group": "DEFAULT-CHEF-WI\\None",
58+
# }
59+
def owner
60+
cmd = @backend.run_command(
61+
"Get-Acl '#{@spath}' | select owner, group | ConvertTo-Json"
62+
)
63+
begin
64+
owner = JSON.parse(cmd.stdout)
65+
rescue JSON::ParserError => _e
66+
return nil
67+
end
68+
69+
# check that we got a response
70+
return nil if owner.nil? || owner['Owner'].nil?
71+
owner['Owner']
72+
end
73+
5474
def type
5575
if attributes.include?('Archive')
5676
return :file
@@ -61,7 +81,7 @@ def type
6181
end
6282

6383
%w{
64-
mode owner group uid gid mtime size selinux_label
84+
mode group uid gid mtime size selinux_label
6585
}.each do |field|
6686
define_method field.to_sym do
6787
nil

0 commit comments

Comments
 (0)