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 authored and mdellweg committed Oct 22, 2024
1 parent 76c3f00 commit e926a69
Show file tree
Hide file tree
Showing 2 changed files with 10 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`.
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

0 comments on commit e926a69

Please sign in to comment.