win_stat: add explicit error message when file is in use (#27826)

* win_stat: add explicit error message when file is in use

* make the lock last a bit longer
pull/26819/head
Jordan Borean 7 years ago committed by GitHub
parent 3ceeb5124e
commit 107e177658

@ -168,11 +168,19 @@ If (Test-Path -Path $path)
$result.stat.size = $info.Length
If ($get_md5) {
$result.stat.md5 = Get-FileChecksum -path $path -algorithm "md5"
try {
$result.stat.md5 = Get-FileChecksum -path $path -algorithm "md5"
} catch {
Fail-Json -obj $result -message "failed to get MD5 hash of file, set get_md5 to False to ignore this error: $($_.Exception.Message)"
}
}
If ($get_checksum) {
$result.stat.checksum = Get-FileChecksum -path $path -algorithm $checksum_algorithm
try {
$result.stat.checksum = Get-FileChecksum -path $path -algorithm $checksum_algorithm
} catch {
Fail-Json -obj $result -message "failed to get hash of file, set get_checksum to False to ignore this error: $($_.Exception.Message)"
}
}
}
}

@ -537,7 +537,29 @@
- win_stat_no_args.msg
- not win_stat_no_args|changed
- name: ensure file that will be in use is deleted before test
win_file:
path: '{{win_stat_dir}}\in_use'
state: absent
- name: lock file in the background for next task
win_command: powershell.exe "$data = 'abcdefghijklmnopqrstuvwxyz' * 1024; $file = [System.IO.File]::Open('{{win_stat_dir}}\in_use', 'OpenOrCreate', 'ReadWrite', 'None'); $writer = New-Object IO.StreamWriter($file); $start = Get-Date; while (((Get-Date) - $start).TotalSeconds -lt 15) { $writer.WriteLine($data) }; $writer.Close(); $file.Close()"
async: 20
poll: 0
register: a
- name: fail to get stat of file in use
win_stat:
path: '{{win_stat_dir}}\in_use'
get_md5: False
register: fail_file_in_use
failed_when: "'failed to get hash of file' not in fail_file_in_use.msg"
- name: remove testing folder
win_file:
path: "{{win_output_dir}}\\win_stat"
state: absent
register: cleanup
retries: 3 # in case async task is still running, try 3 times
delay: 5
until: not cleanup|failed

Loading…
Cancel
Save