[PATCH v2 3/4] bootlinux: handle empty kernel source directory gracefully
Daniel Gomez <[email protected]> Mon, 01 Dec 2025 20:14:40 +0100
| Newsgroups | dev.linux.lists.kdevops |
|---|---|
| Message-ID | <20251201-custom-linux-9p-tree-and-mount-point-v2-3-c720a83cab91@samsung.com> |
From: Daniel Gomez <[email protected]> When the kernel source directory exists but is empty, treat it the same as a non-existent directory and proceed with git clone. Previously an empty directory would trigger the kernel tree validation which would fail because none of the required markers exist. This situation can occur when a previous clone was interrupted or when a user creates the directory manually before running kdevops. Rather than requiring users to manually remove empty directories, detect this case using ansible.builtin.find to check for any files and skip validation when the directory is empty. The empty directory detection tasks include clone and checkout tags so they execute when running with --tags clone, ensuring kernel_dir_is_empty is set before the git clone task evaluates its condition. Generated-by: Claude AI Signed-off-by: Daniel Gomez <[email protected]> --- playbooks/roles/bootlinux/tasks/build/9p.yml | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/playbooks/roles/bootlinux/tasks/build/9p.yml b/playbooks/roles/bootlinux/tasks/build/9p.yml index 0f24185f..532498c9 100644 --- a/playbooks/roles/bootlinux/tasks/build/9p.yml +++ b/playbooks/roles/bootlinux/tasks/build/9p.yml @@ -38,6 +38,25 @@ delegate_to: localhost tags: ["clone", "checkout"] +- name: Check if kernel source directory is empty + ansible.builtin.find: + paths: "{{ bootlinux_9p_host_path }}" + file_type: any + hidden: true + register: kernel_dir_contents + when: + - kernel_dir_stat.stat.exists + run_once: true + delegate_to: localhost + tags: ["clone", "checkout"] + +- name: Set fact for empty directory detection + ansible.builtin.set_fact: + kernel_dir_is_empty: "{{ kernel_dir_stat.stat.exists and (kernel_dir_contents.matched | default(0)) == 0 }}" + run_once: true + delegate_to: localhost + tags: ["clone", "checkout"] + - name: Check for required kernel tree markers ansible.builtin.stat: path: "{{ bootlinux_9p_host_path }}/{{ item }}" @@ -51,6 +70,7 @@ - kernel when: - kernel_dir_stat.stat.exists + - not kernel_dir_is_empty run_once: true delegate_to: localhost tags: ["clone", "checkout"] @@ -71,6 +91,7 @@ success_msg: "Validated {{ bootlinux_9p_host_path }} is a kernel tree" when: - kernel_dir_stat.stat.exists + - not kernel_dir_is_empty run_once: true delegate_to: localhost tags: ["clone", "checkout"] @@ -81,6 +102,7 @@ register: kernel_git_stat when: - kernel_dir_stat.stat.exists + - not kernel_dir_is_empty run_once: true delegate_to: localhost tags: ["clone", "checkout"] @@ -97,7 +119,7 @@ register: git_clone_result until: not git_clone_result.failed when: - - not kernel_dir_stat.stat.exists + - not kernel_dir_stat.stat.exists or kernel_dir_is_empty run_once: true delegate_to: localhost tags: ["clone"] @@ -111,6 +133,7 @@ changed_when: "'Switched to' in git_checkout.stderr or 'Already on' in git_checkout.stdout" when: - kernel_dir_stat.stat.exists + - not kernel_dir_is_empty - kernel_git_stat.stat.exists run_once: true delegate_to: localhost -- 2.52.0