2017-12-12 04:07:56 +00:00
|
|
|
- name: make sure symlink file does not exist
|
|
|
|
test_symlink_file:
|
|
|
|
src: '{{win_stat_dir}}\file-link.txt'
|
|
|
|
state: absent
|
|
|
|
|
2017-04-03 18:38:34 +00:00
|
|
|
- name: remove win_stat testing directories for clean slate
|
2017-01-27 22:51:12 +00:00
|
|
|
win_file:
|
2017-11-16 21:22:57 +00:00
|
|
|
path: '{{win_stat_dir}}'
|
2017-01-27 22:51:12 +00:00
|
|
|
state: absent
|
|
|
|
|
2017-11-16 21:22:57 +00: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",
|
2017-12-12 04:07:56 +00:00
|
|
|
"nested\hard-target.txt",
|
2017-11-16 21:22:57 +00:00
|
|
|
"nested\read-only.ps1",
|
|
|
|
"nested\archive.ps1",
|
|
|
|
"nested\hidden.ps1",
|
|
|
|
"nested\nested\file.ps1",
|
2017-12-12 04:07:56 +00:00
|
|
|
"folder space\file.ps1",
|
|
|
|
"link-dest\file.txt"
|
2017-11-16 21:22:57 +00:00
|
|
|
)
|
|
|
|
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"
|
2017-12-12 04:07:56 +00:00
|
|
|
cmd.exe /c mklink /H "{{win_stat_dir}}\nested\hard-link.ps1" "{{win_stat_dir}}\nested\hard-target.txt"
|
2017-11-16 21:22:57 +00:00
|
|
|
cmd.exe /c mklink /J "{{win_stat_dir}}\junction-link" "{{win_stat_dir}}\junction-dest"
|
2017-12-12 04:07:56 +00:00
|
|
|
cmd.exe /c mklink /D "{{win_stat_dir}}\nested\nested\link-rel" "..\..\link-dest"
|
2017-11-16 21:22:57 +00:00
|
|
|
|
|
|
|
$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 ','
|
|
|
|
}
|
2017-12-12 04:07:56 +00:00
|
|
|
|
2017-11-16 21:22:57 +00:00
|
|
|
# weird issue, need to access the file in anyway to get the correct date stats
|
|
|
|
Test-Path {{win_stat_dir}}\nested\hard-link.ps1
|
|
|
|
|
2017-12-12 04:07:56 +00:00
|
|
|
# mklink.exe and win_file cannot do this right now so we need a custom module
|
|
|
|
- name: create file symlink
|
|
|
|
test_symlink_file:
|
|
|
|
src: '{{win_stat_dir}}\file-link.txt'
|
|
|
|
target: '{{win_stat_dir}}\nested\file.ps1'
|
|
|
|
state: present
|
|
|
|
|
2017-11-16 21:22:57 +00:00
|
|
|
- block:
|
|
|
|
- include_tasks: tests.yml
|
|
|
|
|
|
|
|
always:
|
2017-12-12 04:07:56 +00:00
|
|
|
- name: make sure symlink file does not exist
|
|
|
|
test_symlink_file:
|
|
|
|
src: '{{win_stat_dir}}\file-link.txt'
|
|
|
|
state: absent
|
|
|
|
|
2017-11-16 21:22:57 +00:00
|
|
|
- name: remove testing folder
|
|
|
|
win_file:
|
|
|
|
path: '{{win_stat_dir}}'
|
|
|
|
state: absent
|
2017-12-12 04:07:56 +00:00
|
|
|
|
|
|
|
- name: ensure test user is deleted
|
|
|
|
win_user:
|
|
|
|
name: '{{win_stat_user}}'
|
|
|
|
state: absent
|
|
|
|
|
2018-01-17 04:16:34 +00:00
|
|
|
- name: ensure test user profile is deleted
|
2017-12-12 04:07:56 +00:00
|
|
|
win_shell: rmdir /S /Q {{profile_dir_out.stdout_lines[0]}}
|
|
|
|
args:
|
|
|
|
executable: cmd.exe
|
|
|
|
when: win_stat_user in profile_dir_out.stdout_lines[0]
|