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
pull/80336/head
Jordan Borean 2 years ago committed by GitHub
parent 8600a1b927
commit fb6b90fe42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -178,7 +178,8 @@ namespace Ansible.Basic
} }
string dateTime = DateTime.Now.ToFileTime().ToString(); 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); string newTmpdir = Path.Combine(baseDir, dirName);
#if CORECLR #if CORECLR
DirectoryInfo tmpdirInfo = Directory.CreateDirectory(newTmpdir); DirectoryInfo tmpdirInfo = Directory.CreateDirectory(newTmpdir);

Loading…
Cancel
Save