Jira (PUP-6092) Identify Windows-specific file/folder flags in Windows (e.g. hidden, archive)

0 views
Skip to first unread message

Paul Anderson (JIRA)

unread,
Mar 24, 2016, 1:10:09 PM3/24/16
to puppe...@googlegroups.com
Paul Anderson created an issue
 
Puppet / New Feature PUP-6092
Identify Windows-specific file/folder flags in Windows (e.g. hidden, archive)
Issue Type: New Feature New Feature
Affects Versions: PUP 4.4.0
Assignee: Kylo Ginsberg
Components: Client
Created: 2016/03/24 10:09 AM
Environment:

A Windows system with a file or folder with the hidden attribute set, e.g. C:\hidden
Puppet agent installed

Priority: Normal Normal
Reporter: Paul Anderson

Puppet describe file "c:\hidden" does not provide any way to identify if that file is hidden. In Linux, identifying hidden files is .trivial and not an attribute. However, the Windows platform does this very differently.

The file provider for windows (whether POSIX or Windows, i'll let the Dev's decide) should indicate the relevant attributes, including its hidden-ness, archive-iness, etc.

Additionally, the ability to easily set these attributes would be nice, rather than having to call an exec to powershell, attrib.exe, etc.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.4.13#64028-sha1:b7939e9)
Atlassian logo

Kylo Ginsberg (JIRA)

unread,
Mar 24, 2016, 1:11:08 PM3/24/16
to puppe...@googlegroups.com

Kylo Ginsberg (JIRA)

unread,
Mar 24, 2016, 1:11:12 PM3/24/16
to puppe...@googlegroups.com

Kylo Ginsberg (JIRA)

unread,
Mar 24, 2016, 1:11:14 PM3/24/16
to puppe...@googlegroups.com

Paul Anderson (JIRA)

unread,
Mar 24, 2016, 1:38:32 PM3/24/16
to puppe...@googlegroups.com
Paul Anderson commented on New Feature PUP-6092
 
Re: Identify Windows-specific file/folder flags in Windows (e.g. hidden, archive)

Craig Gomes is unavailable for a few days and suggested that Ethan Brown may be able to put eyes on this.

Craig Gomes (JIRA)

unread,
Mar 24, 2016, 1:39:03 PM3/24/16
to puppe...@googlegroups.com

Ethan Brown (JIRA)

unread,
Mar 24, 2016, 1:49:03 PM3/24/16
to puppe...@googlegroups.com

Ethan Brown (JIRA)

unread,
Mar 24, 2016, 1:49:06 PM3/24/16
to puppe...@googlegroups.com

Paul Anderson (JIRA)

unread,
Mar 24, 2016, 2:20:03 PM3/24/16
to puppe...@googlegroups.com
Paul Anderson commented on New Feature PUP-6092
 
Re: Identify Windows-specific file/folder flags in Windows (e.g. hidden, archive)

Right now, PS is using work arounds for this. We have to exec out to powershell set these attributes, and there's not a good way to check the attributes to perform conditional logic. It's a hack, it's ugly and the customer doesn't like it. That said, this isn't impacting the delivery schedule for any customer. It's just a feature request at this point.

Paul Anderson (JIRA)

unread,
Mar 24, 2016, 2:47:04 PM3/24/16
to puppe...@googlegroups.com
Paul Anderson commented on New Feature PUP-6092

file

{ 'c:/hidden': ensure => directory, }

exec { 'Make hidden':
command => 'attrib +h c:/hidden',
path => $::path,
onlyif => 'if (-Not (Get-ItemProperty -Path C:\hidden).mode | select-string h)

{exit 1}

',
provider => 'powershell',
require => File['c:/hidden'],
}

Hat tip to Nate McCurdy

Nate McCurdy (JIRA)

unread,
Mar 24, 2016, 2:48:11 PM3/24/16
to puppe...@googlegroups.com
Nate McCurdy commented on New Feature PUP-6092

Here's what we'll end up doing. The DSC module probably would've been cleaner, but the customer prefers not to use DSC due to it's PowerShell5 requirement.

file { 'c:/hidden':
  ensure => directory,
}
 
exec { 'Make hidden':
  command  => 'attrib +h c:/hidden',
  path     => $::path,
  onlyif   => 'if (-Not (Get-ItemProperty -Path C:\hidden).mode | select-string h) {exit 1}',
  provider => 'powershell',
  require  => File['c:/hidden'],
}

Paul Anderson (JIRA)

unread,
Mar 24, 2016, 2:49:04 PM3/24/16
to puppe...@googlegroups.com
Paul Anderson updated an issue
 
Change By: Paul Anderson
Comment: {{file { 'c:/hidden':

  ensure => directory,
}

exec { 'Make hidden':
  command  => 'attrib +h c:/hidden',
  path     => $::path,
  onlyif   => 'if (-Not (Get-ItemPro{{monospaced text}}perty -Path C:\hidden).mode | select-string h) {exit 1}',

  provider => 'powershell',
  require  => File['c:/hidden'],
}

Hat tip to [~nate.mccurdy]}}

Ethan Brown (JIRA)

unread,
Mar 24, 2016, 4:25:11 PM3/24/16
to puppe...@googlegroups.com
Ethan Brown commented on New Feature PUP-6092
 
Re: Identify Windows-specific file/folder flags in Windows (e.g. hidden, archive)

There is actually a way to apply conditional logic to workaround the fact that the file type does not support setting attributes using an exec. I would recommend the approach that I've outlined below as it relies on cmd.exe instead of PowerShell, and will therefore execute much more quickly.

The dir commands take switches for the attributes which can then be used to query the file system, to ensure idempotency. For instance:

C:\>dir /ah c:\pagefile.sys
 Volume in drive C is Windows 2008
 Volume Serial Number is D8AA-E11A
 
 Directory of c:\
 
03/23/2016  04:33 PM       536,870,912 pagefile.sys
               1 File(s)    536,870,912 bytes
               0 Dir(s)   6,025,601,024 bytes free
 
C:\>dir /ah c:\missing.file
 Volume in drive C is Windows 2008
 Volume Serial Number is D8AA-E11A
 
 Directory of c:\
 
File Not Found
 
C:\>dir /ah c:\inetpub
 Volume in drive C is Windows 2008
 Volume Serial Number is D8AA-E11A
 
 Directory of c:\inetpub
 
File Not Found

I have implemented a manifest that will write foo.txt and mark it as hidden when it's not already hidden:

$attrib = 'h'
$filepath = 'c:\foo.txt'
 
file { $filepath:
  ensure => present,
  content => 'bar'
}
 
exec { 'foo attributes':
  command => "c:\\windows\\system32\\cmd.exe /c attrib +${attrib} ${filepath}",
  onlyif => "c:\\windows\\system32\\cmd.exe /c dir \\a${attrib} ${filepath} | findstr \"File Not Found\"",
  require => File[$filepath]
}

If you wish to extend the example to multiple attributes, some modifications would be necessary (or you'd have to call exec multiple times) – the attrib command can take an argument like +shr, but dir must have the args separated like /as /ah /ar. Exercise left up to the reader if that's necessary.

Sean McDonald (JIRA)

unread,
May 16, 2017, 3:17:04 PM5/16/17
to puppe...@googlegroups.com
Sean McDonald updated an issue
 
Change By: Sean McDonald
Team: Agent
This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe)
Atlassian logo

Sean McDonald (JIRA)

unread,
May 16, 2017, 3:17:06 PM5/16/17
to puppe...@googlegroups.com

Sean McDonald (JIRA)

unread,
May 16, 2017, 3:25:03 PM5/16/17
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Mar 5, 2020, 2:54:03 AM3/5/20
to puppe...@googlegroups.com
Josh Cooper commented on New Feature PUP-6092
 
Re: Identify Windows-specific file/folder flags in Windows (e.g. hidden, archive)

It's unlikely that we'll address this issue anytime soon, so closing Please reopen if this is still a concern.

This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages