Issue #3915
Updated by jortel@redhat.com over 6 years ago
h2. 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. <pre> cat = Artifact(file='/var/cache/pulp/abcd', sha256=TIGER) cat.save() </pre> 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. h2. 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. <pre> cat = Artifact(file='/var/lib/pulp/artifact/CA/T, sha256=CAT) cat.save() </pre> 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> <pre> dog = Artifact(file='/var/lib/pulp/artifact/CA/T, sha256=DOG) dog.save() # This could be Artifact.objects.bulk_create([dog]) with same result. </pre> 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 created in the DB with file=/var/lib/pulp/artifact/DO/G h2. Recommended: The _ArtifactFileField_ should not be deleting files. The Artifact(file=) should not permit _file=_ be inside the MEDIA_ROOT.