Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have downloads always end up under WORKING_DIRECTORY #5913

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/plugin_api/5912.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Downloaders now always ensure the download ends up under `WORKING_DIRECTORY`.
10 changes: 9 additions & 1 deletion pulpcore/download/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import logging
import os
import tempfile
from pathlib import Path
from urllib.parse import urlsplit

from django.conf import settings
from pulpcore.app import pulp_hashlib
from pulpcore.app.models import Artifact
from pulpcore.exceptions import (
Expand Down Expand Up @@ -127,7 +129,13 @@ def _ensure_writer_has_open_file(self):
# write the file to the current working directory with a random prefix and the
# desired suffix. we always want the random prefix as it is possible to download
# the same filename from two different URLs, and the files may not be the same.
self._writer = tempfile.NamedTemporaryFile(dir=".", suffix=suffix, delete=False)
# Ensure CWD is in Pulp's working directory to prevent permission error on download
work_dir = str(settings.WORKING_DIRECTORY)
self._writer = tempfile.NamedTemporaryFile(
dir="." if Path.cwd().is_relative_to(work_dir) else work_dir,
suffix=suffix,
delete=False,
)
self.path = self._writer.name
self._digests = {n: pulp_hashlib.new(n) for n in Artifact.DIGEST_FIELDS}
self._size = 0
Expand Down