windows: fix for checking locked system files (#30665)

* fix for checking locked system files

* moved functions to share module util and created tests

* fixed windows-paths test based on win_stat changes
This commit is contained in:
Jordan Borean 2017-11-16 10:04:03 +10:00 committed by ansibot
commit e16e6313c7
12 changed files with 166 additions and 29 deletions

View file

@ -5,6 +5,7 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#Requires -Module Ansible.ModuleUtils.Legacy
#Requires -Module Ansible.ModuleUtils.FileUtil
$ErrorActionPreference = "Stop"
@ -118,7 +119,7 @@ if ($path -eq $null -and $port -eq $null -and $state -eq "drained") {
$complete = $false
while (((Get-Date) - $start_time).TotalSeconds -lt $timeout) {
$attempts += 1
if (Test-Path -Path $path) {
if (Test-FilePath -path $path) {
if ($search_regex -eq $null) {
$complete = $true
break
@ -149,7 +150,7 @@ if ($path -eq $null -and $port -eq $null -and $state -eq "drained") {
$complete = $false
while (((Get-Date) - $start_time).TotalSeconds -lt $timeout) {
$attempts += 1
if (Test-Path -Path $path) {
if (Test-FilePath -path $path) {
if ($search_regex -ne $null) {
$file_contents = Get-Content -Path $path -Raw
if ($file_contents -notmatch $search_regex) {