Skip to content

quadlet: prevent duplicate systemd units from subdirectories#28135

Open
Veector40 wants to merge 1 commit intocontainers:mainfrom
Veector40:fix-quadlet-subdir
Open

quadlet: prevent duplicate systemd units from subdirectories#28135
Veector40 wants to merge 1 commit intocontainers:mainfrom
Veector40:fix-quadlet-subdir

Conversation

@Veector40
Copy link
Contributor

When running podman quadlet install, the installer did not check for existing quadlets with the same name in subdirectories of the install path. This could lead to duplicate quadlet files and conflicting systemd units.

This patch adds a WalkDir check to identify if a quadlet file already exists in any subdirectory of the target install directory. If it does:

  • Without --replace, it refuses to overwrite and throws an error.
  • With --replace, it cleans up the duplicate from the subdirectory before writing the new file to the expected install directory.

Added a system BATS test to ensure quadlet installation correctly detects, fails, or replaces nested duplicates.

Fixes: #28118

Checklist

Ensure you have completed the following checklist for your pull request to be reviewed:

  • Certify you wrote the patch or otherwise have the right to pass it on...
  • Referenced issues using Fixes: #00000 in commit message (if applicable)
  • Tests have been added/updated (or no tests are needed)
  • Documentation has been updated (or no documentation changes are needed)
  • All commits pass make validatepr (format/lint checks)
  • Release note entered in the section below (or None if no user-facing changes)

Does this PR introduce a user-facing change?

Fixed a bug in `podman quadlet install` where existing quadlets with the same name in subdirectories were ignored, resulting in duplicate systemd units. The command will now throw an error if a nested duplicate is found, or properly clean it up if the `--replace` flag is used.

When running `podman quadlet install`, the installer did not check
for existing quadlets with the same name in subdirectories of the
install path. This could lead to duplicate quadlet files and
conflicting systemd units.

This patch adds a WalkDir check to identify if a quadlet file already
exists in any subdirectory of the target install directory. If it does:
- Without `--replace`, it refuses to overwrite and throws an error.
- With `--replace`, it cleans up the duplicate from the subdirectory
  before writing the new file to the expected install directory.

Added a system BATS test to ensure quadlet installation correctly
detects, fails, or replaces nested duplicates.

Fixes: containers#28118

Signed-off-by: Victor Koycheff <victorkoycheff@gmail.com>
@jankaluza
Copy link
Member

Note that this will conflict with #27980. Just something to be aware of.

@jankaluza
Copy link
Member

What if there are already two duplicates before you start the podman install --replace. I think the current code only replaces the first duplicate and it will still won't work, will it?

I'm also not completely persuaded that removing files with the same name from the more or less random subdirectories is a good idea. I'm afraid we could remove some file by a mistake. Maybe it could be better to simply detect this situation and say human intervention is needed?

Anyway, let's wait what does other think. Do not change your code yet, let's wait for another review :-).

@jankaluza
Copy link
Member

The test failure in APIv2 needs to be fixed.

@Veector40
Copy link
Contributor Author

Thank you for the clarification.

I’ve updated the logic to correctly handle the directory paths, and I’ve verified that both the existing API tests and the new BATS cases are passing locally now.

I don't want to jump the gun, so I’m going to hold off on pushing or touching anything else until I get your guidance on how to proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

podman quadlet rm -r is leading to issue when existing file is in a sub directory

2 participants