summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Borean <jborean93@gmail.com>2017-06-29 07:06:10 +1000
committerJordan <jborean93@gmail.com>2017-06-29 07:14:17 +1000
commitc0ff449ac8d1ed36546bab7586da6d885af5d5cd (patch)
treeaef6e9c26922099348b892072c2967e5f1e076da
parent184903c1d876b998b8f6e23e9e583074967f7e60 (diff)
downloadansible-c0ff449ac8d1ed36546bab7586da6d885af5d5cd.tar.gz
win_find: fix for empty nested directories (#26164)
(cherry picked from commit 98fc54f02d355a38027fc8445f5651829ecbf891)
-rw-r--r--lib/ansible/modules/windows/win_find.ps14
-rw-r--r--test/integration/targets/win_find/tasks/main.yml61
2 files changed, 39 insertions, 26 deletions
diff --git a/lib/ansible/modules/windows/win_find.ps1 b/lib/ansible/modules/windows/win_find.ps1
index b03e584a60..fc30b0f211 100644
--- a/lib/ansible/modules/windows/win_find.ps1
+++ b/lib/ansible/modules/windows/win_find.ps1
@@ -269,8 +269,8 @@ Function Get-FileStat($file) {
$file_stat.sharename = $share_info.Name
}
- #$dir_files_sum = Get-ChildItem $file.FullName -Recurse | Measure-Object -property length -sum
- $dir_files_sum = Get-ChildItem $file.FullName -Recurse
+ # only get the size of a directory if there are files (not directories) inside the folder
+ $dir_files_sum = Get-ChildItem $file.FullName -Recurse | Where-Object { -not $_.PSIsContainer }
if ($dir_files_sum -eq $null -or ($dir_files_sum.PSObject.Properties.name -contains 'length' -eq $false)) {
$file_stat.size = 0
diff --git a/test/integration/targets/win_find/tasks/main.yml b/test/integration/targets/win_find/tasks/main.yml
index 4c452f6e04..0064694df7 100644
--- a/test/integration/targets/win_find/tasks/main.yml
+++ b/test/integration/targets/win_find/tasks/main.yml
@@ -9,18 +9,20 @@
path: "{{item}}"
state: directory
with_items:
- - "{{win_find_dir}}\\nested"
- - "{{win_find_dir}}\\single"
- - "{{win_find_dir}}\\link-dest"
- - "{{win_find_dir}}\\link-dest\\sub-link"
- - "{{win_find_dir}}\\hard-link-dest"
- - "{{win_find_dir}}\\junction-link-dest"
- - "{{win_find_dir}}\\broken-link-dest"
- - "{{win_find_dir}}\\nested\\sub-nest"
- - "{{win_find_dir}}\\shared"
- - "{{win_find_dir}}\\shared\\folder"
- - "{{win_find_dir}}\\hidden"
- - "{{win_find_dir}}\\date"
+ - '{{win_find_dir}}\nested'
+ - '{{win_find_dir}}\single'
+ - '{{win_find_dir}}\link-dest'
+ - '{{win_find_dir}}\link-dest\sub-link'
+ - '{{win_find_dir}}\hard-link-dest'
+ - '{{win_find_dir}}\junction-link-dest'
+ - '{{win_find_dir}}\broken-link-dest'
+ - '{{win_find_dir}}\nested\sub-nest'
+ - '{{win_find_dir}}\shared'
+ - '{{win_find_dir}}\shared\folder'
+ - '{{win_find_dir}}\hidden'
+ - '{{win_find_dir}}\date'
+ - '{{win_find_dir}}\emptynested\nest\dir1'
+ - '{{win_find_dir}}\emptynested\nest\dir2'
- name: create empty test files
win_file:
@@ -497,20 +499,20 @@
- name: check directory count with recurse and follow is correct
assert:
that:
- - actual.examined == 33
- - actual.matched == 13
+ - actual.examined == 37
+ - actual.matched == 17
- actual.files[0].filename == 'broken-link'
- actual.files[0].islnk == True
- - actual.files[2].filename == 'junction-link'
- - actual.files[2].islnk == True
- - actual.files[2].lnk_source == win_find_dir + '\\junction-link-dest'
- - actual.files[7].filename == 'link'
- - actual.files[7].islnk == True
- - actual.files[7].lnk_source == win_find_dir + '\\link-dest'
- - actual.files[11].filename == 'folder'
- - actual.files[11].islnk == False
- - actual.files[11].isshared == True
- - actual.files[11].sharename == 'folder-share'
+ - actual.files[6].filename == 'junction-link'
+ - actual.files[6].islnk == True
+ - actual.files[6].lnk_source == win_find_dir + '\\junction-link-dest'
+ - actual.files[11].filename == 'link'
+ - actual.files[11].islnk == True
+ - actual.files[11].lnk_source == win_find_dir + '\\link-dest'
+ - actual.files[15].filename == 'folder'
+ - actual.files[15].islnk == False
+ - actual.files[15].isshared == True
+ - actual.files[15].sharename == 'folder-share'
- name: filter files by size without byte specified
win_find:
@@ -709,6 +711,17 @@
that:
- actual_no_checksum.files[0].checksum is undefined
+# https://github.com/ansible/ansible/issues/26158
+- name: get list of files in an empty nested directory
+ win_find:
+ paths: '{{win_find_dir}}\emptynested'
+ register: actual_empty_nested
+
+- name: assert get list of files in an empty nested directory
+ assert:
+ that:
+ - actual_empty_nested.matched == 0
+
- name: remove testing folder
win_file:
path: "{{win_find_dir}}"