From fb6b90fe4255e9995706905e2a9cde205648c0d2 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Tue, 28 Mar 2023 12:25:10 +1000 Subject: [PATCH] Improve Ansible.Basic.cs tempdir uniqueness (#80328) * Improve Ansible.Basic.cs tempdir uniqueness The current tempdir naming scheme can result in the same name if the remote worker starts at the same time as another. By using the process id it should add enough uniqueness to avoid this situation. * Fix sanity issues * Fix up compile issue on older hosts --- changelogs/fragments/ansible-basic-tmpdir-uniqueness.yml | 2 ++ lib/ansible/module_utils/csharp/Ansible.Basic.cs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/ansible-basic-tmpdir-uniqueness.yml diff --git a/changelogs/fragments/ansible-basic-tmpdir-uniqueness.yml b/changelogs/fragments/ansible-basic-tmpdir-uniqueness.yml new file mode 100644 index 00000000000..02409495633 --- /dev/null +++ b/changelogs/fragments/ansible-basic-tmpdir-uniqueness.yml @@ -0,0 +1,2 @@ +bugfixes: +- Windows - Ensure the module temp directory contains more unique values to avoid conflicts with concurrent runs - https://github.com/ansible/ansible/issues/80294 diff --git a/lib/ansible/module_utils/csharp/Ansible.Basic.cs b/lib/ansible/module_utils/csharp/Ansible.Basic.cs index ed7b592c655..97f5f3e2d78 100644 --- a/lib/ansible/module_utils/csharp/Ansible.Basic.cs +++ b/lib/ansible/module_utils/csharp/Ansible.Basic.cs @@ -178,7 +178,8 @@ namespace Ansible.Basic } string dateTime = DateTime.Now.ToFileTime().ToString(); - string dirName = String.Format("ansible-moduletmp-{0}-{1}", dateTime, new Random().Next(0, int.MaxValue)); + string dirName = String.Format("ansible-moduletmp-{0}-{1}-{2}", dateTime, System.Diagnostics.Process.GetCurrentProcess().Id, + new Random().Next(0, int.MaxValue)); string newTmpdir = Path.Combine(baseDir, dirName); #if CORECLR DirectoryInfo tmpdirInfo = Directory.CreateDirectory(newTmpdir);