Skip to content

Commit

Permalink
Have downloads always end up under WORKING_DIRECTORY
Browse files Browse the repository at this point in the history
fixes: #5912
  • Loading branch information
gerrod3 committed Oct 15, 2024
1 parent dfa6dfb commit 5aa97ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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`.
8 changes: 7 additions & 1 deletion pulpcore/download/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tempfile
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 +128,12 @@ 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)
work_dir = str(settings.WORKING_DIRECTORY)
self._writer = tempfile.NamedTemporaryFile(
dir="." if work_dir in os.getcwd() 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

0 comments on commit 5aa97ce

Please sign in to comment.