2017-04-03 20:38:34 +02:00
|
|
|
- name: remove win_stat testing directories for clean slate
|
2017-01-27 23:51:12 +01:00
|
|
|
win_file:
|
2017-11-16 22:22:57 +01:00
|
|
|
path: '{{win_stat_dir}}'
|
2017-01-27 23:51:12 +01:00
|
|
|
state: absent
|
|
|
|
|
2017-11-16 22:22:57 +01:00
|
|
|
# while most of the setup can be done with modules, it is quicker to do them
|
|
|
|
# all in bulk than with with_items to save each round trip over WinRM
|
|
|
|
- name: set test files and folders
|
|
|
|
win_shell: |
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$directories = @(
|
|
|
|
"folder",
|
|
|
|
"folder space",
|
|
|
|
"nested\nested",
|
|
|
|
"shared",
|
|
|
|
"hidden",
|
|
|
|
"link-dest",
|
|
|
|
"junction-dest"
|
|
|
|
)
|
|
|
|
|
|
|
|
foreach ($directory in $directories) {
|
|
|
|
New-Item -Path "{{win_stat_dir}}\$directory" -ItemType Directory
|
|
|
|
}
|
|
|
|
|
|
|
|
$normal_content = "abc"
|
|
|
|
$normal_files = @(
|
|
|
|
"nested\file.ps1",
|
|
|
|
"nested\read-only.ps1",
|
|
|
|
"nested\archive.ps1",
|
|
|
|
"nested\hidden.ps1",
|
|
|
|
"nested\nested\file.ps1",
|
|
|
|
"folder space\file.ps1"
|
|
|
|
)
|
|
|
|
foreach ($file in $normal_files) {
|
|
|
|
New-Item -Path "{{win_stat_dir}}\$file" -ItemType File
|
|
|
|
[System.IO.File]::WriteAllText("{{win_stat_dir}}\$file", $normal_content)
|
|
|
|
}
|
|
|
|
|
|
|
|
$share_stat = Get-WmiObject -Class Win32_Share -Filter "name='folder-share'"
|
|
|
|
if ($share_stat) {
|
|
|
|
$share_stat.Delete()
|
|
|
|
}
|
|
|
|
$wmi = [wmiClass] 'Win32_Share'
|
|
|
|
$wmi.Create("{{win_stat_dir}}\shared", "folder-share", 0)
|
|
|
|
|
|
|
|
cmd.exe /c mklink /D "{{win_stat_dir}}\link" "{{win_stat_dir}}\link-dest"
|
|
|
|
cmd.exe /c mklink /H "{{win_stat_dir}}\nested\hard-link.ps1" "{{win_stat_dir}}\nested\file.ps1"
|
|
|
|
cmd.exe /c mklink /J "{{win_stat_dir}}\junction-link" "{{win_stat_dir}}\junction-dest"
|
|
|
|
|
|
|
|
$date = Get-Date -Year 2016 -Month 11 -Day 1 -Hour 7 -Minute 10 -Second 5 -Millisecond 0
|
|
|
|
Get-ChildItem -Path "{{win_stat_dir}}" -Recurse | ForEach-Object {
|
|
|
|
$_.CreationTime = $date
|
|
|
|
$_.LastAccessTime = $date
|
|
|
|
$_.LastWriteTime = $date
|
|
|
|
}
|
|
|
|
|
|
|
|
$attributes = @{
|
|
|
|
"hidden" = "Hidden"
|
|
|
|
"nested\read-only.ps1" = "ReadOnly"
|
|
|
|
"nested\archive.ps1" = "Archive"
|
|
|
|
"nested\hidden.ps1" = "Hidden"
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($attribute in $attributes.GetEnumerator()) {
|
|
|
|
$item = Get-Item -Path "{{win_stat_dir}}\$($attribute.Name)"
|
|
|
|
$file_attributes = $item.Attributes -split ','
|
|
|
|
if ($file_attributes -notcontains $attribute.Value) {
|
|
|
|
$file_attributes += $attribute.Value
|
|
|
|
}
|
|
|
|
$item.Attributes = $file_attributes -join ','
|
|
|
|
}
|
|
|
|
# weird issue, need to access the file in anyway to get the correct date stats
|
|
|
|
Test-Path {{win_stat_dir}}\nested\hard-link.ps1
|
|
|
|
|
|
|
|
- block:
|
|
|
|
- include_tasks: tests.yml
|
|
|
|
|
|
|
|
always:
|
|
|
|
- name: remove testing folder
|
|
|
|
win_file:
|
|
|
|
path: '{{win_stat_dir}}'
|
|
|
|
state: absent
|