2017-02-08 23:19:08 +01:00
|
|
|
---
|
|
|
|
- name: ensure the testing directory is cleared before setting up test
|
|
|
|
win_file:
|
2017-11-02 00:35:19 +01:00
|
|
|
path: '{{win_find_dir}}'
|
2017-02-08 23:19:08 +01:00
|
|
|
state: absent
|
|
|
|
|
2017-11-02 00:35:19 +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: |
|
|
|
|
$directories = @(
|
|
|
|
"nested",
|
|
|
|
"single",
|
|
|
|
"link-dest\sub-link",
|
|
|
|
"hard-link-dest",
|
|
|
|
"junction-link-dest",
|
|
|
|
"broken-link-dest",
|
|
|
|
"nested\sub-nest",
|
|
|
|
"shared\folder",
|
|
|
|
"hidden",
|
|
|
|
"date",
|
|
|
|
"emptynested\nest\dir1",
|
|
|
|
"emptynested\nest\dir2"
|
|
|
|
)
|
|
|
|
foreach ($directory in $directories) {
|
|
|
|
New-Item -Path "{{win_find_dir}}\$directory" -ItemType Directory
|
|
|
|
}
|
|
|
|
|
|
|
|
$normal_content = "abcdefg1234567"
|
|
|
|
$normal_files = @(
|
|
|
|
"nested\file.ps1",
|
|
|
|
"nested\test.ps1",
|
|
|
|
"nested\out.log",
|
|
|
|
"nested\archive.log",
|
|
|
|
"nested\sub-nest\test.ps1",
|
|
|
|
"nested\sub-nest\readonly.txt",
|
|
|
|
"link-dest\link.ps1",
|
|
|
|
"single\test.ps1",
|
|
|
|
"single\hidden.ps1",
|
|
|
|
"single\out_20161101-091005.log",
|
|
|
|
"hidden\out_20161101-091005.log",
|
|
|
|
"hard-link-dest\file-abc.log"
|
|
|
|
)
|
|
|
|
foreach ($file in $normal_files) {
|
|
|
|
New-Item -Path "{{win_find_dir}}\$file" -ItemType File
|
|
|
|
[System.IO.File]::WriteAllText("{{win_find_dir}}\$file", $normal_content)
|
|
|
|
}
|
|
|
|
|
|
|
|
New-Item -Path "{{win_find_dir}}\single\small.ps1" -ItemType File
|
|
|
|
[System.IO.File]::WriteAllText("{{win_find_dir}}\single\small.ps1", "a")
|
|
|
|
|
|
|
|
New-Item -Path "{{win_find_dir}}\date\new.ps1" -ItemType File
|
|
|
|
[System.IO.File]::WriteAllText("{{win_find_dir}}\date\new.ps1", "random text for new date")
|
|
|
|
|
|
|
|
New-Item -Path "{{win_find_dir}}\date\old.ps1" -ItemType File
|
|
|
|
[System.IO.File]::WriteAllText("{{win_find_dir}}\date\old.ps1", "random text for old date")
|
|
|
|
|
|
|
|
New-Item -Path "{{win_find_dir}}\single\large.ps1" -ItemType File
|
|
|
|
Set-Content -Path "{{win_find_dir}}\single\large.ps1" -Value ('abcdefghijklmnopqrstuvwxyz' * 10000)
|
|
|
|
|
|
|
|
$share_stat = Get-WmiObject -Class Win32_Share -Filter "name='folder-share'"
|
|
|
|
if ($share_stat) {
|
|
|
|
$share_stat.Delete()
|
|
|
|
}
|
|
|
|
$wmi = [wmiClass] 'Win32_Share'
|
|
|
|
$wmi.Create("{{win_find_dir}}\shared\folder", "folder-share", 0)
|
|
|
|
|
|
|
|
cmd.exe /c mklink /D "{{win_find_dir}}\nested\link" "{{win_find_dir}}\link-dest"
|
|
|
|
cmd.exe /c mklink /D "{{win_find_dir}}\broken-link" "{{win_find_dir}}\broken-link-dest"
|
|
|
|
cmd.exe /c mklink /H "{{win_find_dir}}\hard-link-dest\hard-link.log" "{{win_find_dir}}\hard-link-dest\file-abc.log"
|
|
|
|
cmd.exe /c mklink /J "{{win_find_dir}}\junction-link" "{{win_find_dir}}\junction-link-dest"
|
2017-02-08 23:19:08 +01:00
|
|
|
|
2017-11-02 00:35:19 +01:00
|
|
|
$date = Get-Date -Year 2016 -Month 11 -Day 1 -Hour 7 -Minute 10 -Second 5 -Millisecond 0
|
|
|
|
Get-ChildItem -Path "{{win_find_dir}}" -Recurse | Where-Object { $_.Name -ne "new.ps1" } | ForEach-Object {
|
|
|
|
$_.CreationTime = $date
|
|
|
|
$_.LastAccessTime = $date
|
|
|
|
$_.LastWriteTime = $date
|
|
|
|
}
|
|
|
|
|
|
|
|
$attributes = @{
|
|
|
|
"hidden" = "Hidden"
|
|
|
|
"date" = "Hidden"
|
|
|
|
"nested\archive.log" = "Archive"
|
|
|
|
"nested\sub-nest\readonly.txt" = "ReadOnly"
|
|
|
|
"single\hidden.ps1" = "Hidden"
|
|
|
|
}
|
|
|
|
foreach ($attribute in $attributes.GetEnumerator()) {
|
|
|
|
$item = Get-Item -Path "{{win_find_dir}}\$($attribute.Name)"
|
|
|
|
$file_attributes = $item.Attributes -split ','
|
|
|
|
if ($file_attributes -notcontains $attribute.Value) {
|
|
|
|
$file_attributes += $attribute.Value
|
|
|
|
}
|
|
|
|
$item.Attributes = $file_attributes -join ','
|
|
|
|
}
|
|
|
|
|
|
|
|
Remove-Item -Path "{{win_find_dir}}\broken-link-dest" -Force
|
|
|
|
|
|
|
|
- block:
|
|
|
|
- include_tasks: tests.yml
|
|
|
|
|
|
|
|
always:
|
|
|
|
- name: remove test user
|
|
|
|
win_user:
|
|
|
|
name: '{{test_win_find_username}}'
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: remove testing folder
|
|
|
|
win_file:
|
|
|
|
path: '{{win_find_dir}}'
|
|
|
|
state: absent
|