Skip to content

Commit 3390893

Browse files
committed
utils: handle FileExistsError
* In open_fifo_write, use existing FIFO file path if already exists Fixes: #407 Signed-off-by: Abhijeet Kasurde <Akasurde@redhat.com>
1 parent f95972b commit 3390893

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/ansible_runner/utils/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,11 @@ def open_fifo_write(path: str, data: str | bytes) -> None:
417417
This blocks the thread until an external process (such as ssh-agent)
418418
reads data from the pipe.
419419
'''
420-
os.mkfifo(path, stat.S_IRUSR | stat.S_IWUSR)
420+
try:
421+
os.mkfifo(path, stat.S_IRUSR | stat.S_IWUSR)
422+
except FileExistsError:
423+
# Use existing path
424+
pass
421425
# If the data is a string instead of bytes, convert it before writing the fifo
422426
if isinstance(data, str):
423427
data = data.encode()

test/unit/utils/test_fifo_pipe.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,18 @@ def test_fifo_write_string(tmp_path):
2525
assert results == data
2626
finally:
2727
remove(path)
28+
29+
30+
def test_fifo_write_string_with_existing_file(tmp_path):
31+
path = tmp_path / "string_test"
32+
data = "string"
33+
# Create a fifo
34+
open_fifo_write(path, data)
35+
try:
36+
# Use an existing fifo path
37+
open_fifo_write(path, data)
38+
with open(path, 'r') as f:
39+
results = f.read()
40+
assert results == data * 2
41+
finally:
42+
remove(path)

0 commit comments

Comments
 (0)