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"
|
|
|
|
)
|
2019-03-19 01:30:11 +01:00
|
|
|
|
|
|
|
$tmp_dir = '{{ win_find_dir }}'
|
2017-11-02 00:35:19 +01:00
|
|
|
foreach ($directory in $directories) {
|
2019-03-19 01:30:11 +01:00
|
|
|
New-Item -Path "$tmp_dir\$directory" -ItemType Directory
|
2017-11-02 00:35:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$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) {
|
2019-03-19 01:30:11 +01:00
|
|
|
New-Item -Path "$tmp_dir\$file" -ItemType File
|
|
|
|
[System.IO.File]::WriteAllText("$tmp_dir\$file", $normal_content)
|
2017-11-02 00:35:19 +01:00
|
|
|
}
|
|
|
|
|
2019-03-19 01:30:11 +01:00
|
|
|
New-Item -Path "$tmp_dir\single\small.ps1" -ItemType File
|
|
|
|
[System.IO.File]::WriteAllText("$tmp_dir\single\small.ps1", "a")
|
2017-11-02 00:35:19 +01:00
|
|
|
|
2019-03-19 01:30:11 +01:00
|
|
|
New-Item -Path "$tmp_dir\date\new.ps1" -ItemType File
|
|
|
|
[System.IO.File]::WriteAllText("$tmp_dir\date\new.ps1", "random text for new date")
|
2017-11-02 00:35:19 +01:00
|
|
|
|
2019-03-19 01:30:11 +01:00
|
|
|
New-Item -Path "$tmp_dir\date\old.ps1" -ItemType File
|
|
|
|
[System.IO.File]::WriteAllText("$tmp_dir\date\old.ps1", "random text for old date")
|
2017-11-02 00:35:19 +01:00
|
|
|
|
2019-03-19 01:30:11 +01:00
|
|
|
New-Item -Path "$tmp_dir\single\large.ps1" -ItemType File
|
|
|
|
Set-Content -LiteralPath "$tmp_dir\single\large.ps1" -Value ('abcdefghijklmnopqrstuvwxyz' * 10000)
|
2017-11-02 00:35:19 +01:00
|
|
|
|
|
|
|
$share_stat = Get-WmiObject -Class Win32_Share -Filter "name='folder-share'"
|
|
|
|
if ($share_stat) {
|
|
|
|
$share_stat.Delete()
|
|
|
|
}
|
|
|
|
$wmi = [wmiClass] 'Win32_Share'
|
2019-03-19 01:30:11 +01:00
|
|
|
$wmi.Create("$tmp_dir\shared\folder", "folder-share", 0)
|
|
|
|
|
|
|
|
cmd.exe /c mklink /D "$tmp_dir\nested\link" "$tmp_dir\link-dest"
|
|
|
|
cmd.exe /c mklink /D "$tmp_dir\broken-link" "$tmp_dir\broken-link-dest"
|
|
|
|
cmd.exe /c mklink /H "$tmp_dir\hard-link-dest\hard-link.log" "$tmp_dir\hard-link-dest\file-abc.log"
|
|
|
|
cmd.exe /c mklink /J "$tmp_dir\junction-link" "$tmp_dir\junction-link-dest"
|
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
|
2019-03-19 01:30:11 +01:00
|
|
|
Set-Location -LiteralPath $tmp_dir
|
|
|
|
Get-ChildItem -Recurse | Where-Object { $_.Name -ne "new.ps1" } | ForEach-Object {
|
2017-11-02 00:35:19 +01:00
|
|
|
$_.CreationTime = $date
|
|
|
|
$_.LastAccessTime = $date
|
|
|
|
$_.LastWriteTime = $date
|
|
|
|
}
|
2019-03-19 01:30:11 +01:00
|
|
|
Pop-Location
|
2017-11-02 00:35:19 +01:00
|
|
|
|
|
|
|
$attributes = @{
|
|
|
|
"hidden" = "Hidden"
|
|
|
|
"date" = "Hidden"
|
|
|
|
"nested\archive.log" = "Archive"
|
|
|
|
"nested\sub-nest\readonly.txt" = "ReadOnly"
|
|
|
|
"single\hidden.ps1" = "Hidden"
|
|
|
|
}
|
|
|
|
foreach ($attribute in $attributes.GetEnumerator()) {
|
2019-03-19 01:30:11 +01:00
|
|
|
$item = Get-Item -LiteralPath "$tmp_dir\$($attribute.Name)"
|
2017-11-02 00:35:19 +01:00
|
|
|
$file_attributes = $item.Attributes -split ','
|
|
|
|
if ($file_attributes -notcontains $attribute.Value) {
|
|
|
|
$file_attributes += $attribute.Value
|
|
|
|
}
|
|
|
|
$item.Attributes = $file_attributes -join ','
|
|
|
|
}
|
|
|
|
|
2019-03-19 01:30:11 +01:00
|
|
|
Remove-Item -LiteralPath "$tmp_dir\broken-link-dest" -Force
|
2017-11-02 00:35:19 +01:00
|
|
|
|
|
|
|
- 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
|