Project

Profile

Help

Issue #3915

closed

The ArtifactFileField is deleting source files.

Added by jortel@redhat.com over 5 years ago. Updated over 4 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Category:
-
Sprint/Milestone:
Start date:
Due date:
Estimated time:
Severity:
3. High
Version:
Platform Release:
OS:
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
Sprint:
Sprint 43
Quarter:

Description

Problem

The ArtifactFileField uses TemporaryDownloadedFile is based on TemporaryUploadedFile which has the unexpected behavior of deleting the source file. When used with a file downloaded to the task temporary directory, the delete is undesirable because it's not safe to assume the plugin is finished with the file.

cat = Artifact(file='/var/cache/pulp/abcd', sha256=TIGER)
cat.save()

As a result, /var/lib/pulp/artifact/TI/GER is created and (tiger) Artifact.file=/var/lib/pulp/artifact/TI/GER is inserted in the DB but /var/cache/pulp/abcd got deleted and I'm not done with it yet.

Bigger Problem

This is especially bad in cases where Artifact.file is set to a path within the MEDIA_ROOT/artifact as is recommended to be done for bulk create.

Consider a simple mistake made by a plugin writer.

cat = Artifact(file='/var/lib/pulp/artifact/CA/T, sha256=CAT)
cat.save()

As a result, /var/lib/pulp/artifact/CA/T is created and (cat) Artifact.file=/var/lib/pulp/artifact/CA/T is inserted in the DB.

Then, oops, created the dog artifact with file=<same as cat>

dog = Artifact(file='/var/lib/pulp/artifact/CA/T, sha256=DOG)
dog.save()  # This could be Artifact.objects.bulk_create([dog]) with same result.

The result is:

1. /var/lib/pulp/artifact/DO/G is created with content of: /var/lib/pulp/artifact/CA/T
2. /var/lib/pulp/artifact/CA/T is deleted and now the cat artifact is broken.
3. The (dog) artifact is inserted in the DB with file=/var/lib/pulp/artifact/DO/G

Recommended:

The ArtifactFileField should not be deleting files.
The Artifact(file=) should not permit file= be inside the MEDIA_ROOT.

Also available in: Atom PDF