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

Cleanup export temp attachment files #1326

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Commits on Jun 3, 2014

  1. Changed create_attachments_zipfile() to stop leaving behind zip files…

    … in the system tmp folder
    
    which never get cleaned up, and have it return a data stream of the zip file contents intead.
    
    Next up: fix the two places in the rest of the code which were calling this, and adapt them to
    use the data stream in lieu of the file name.
    Denis Papathanasiou committed Jun 3, 2014
    Configuration menu
    Copy the full SHA
    cff4bd2 View commit details
    Browse the repository at this point in the history
  2. Changed utils.export_tools.generate_attachment_zip_export(),

    the first caller of create_attachments_zipfile(), to treat the result
    as a data stream, and catch and record any IOErrors as failed Export
    objects in the database.
    
    The prior logic was disgusting: it created a zip file in /tmp, read it
    into memory to create a new file (a copy) elsewhere in the filesystem,
    and never bothered with the original file in /tmp.
    Denis Papathanasiou committed Jun 3, 2014
    Configuration menu
    Copy the full SHA
    fb032db View commit details
    Browse the repository at this point in the history
  3. Changed zip_export(), the second caller of create_attachments_zipfile…

    …(), to
    
    accept the result back as a stream, and used django's FileWrapper to respond
    to the http request immediately, rather than calling another to go read the
    temp file first (which, of course, never gets cleaned up).
    
    The response_with_mimetype_and_name() function in utils.export_tools.py is just
    a mess: it depends on reading all its responses from the file system, and
    mimetype assumption that all valid response types start with 'application/' is
    just flat wrong!
    Denis Papathanasiou committed Jun 3, 2014
    Configuration menu
    Copy the full SHA
    1c7a386 View commit details
    Browse the repository at this point in the history

Commits on Jun 5, 2014

  1. Corrected assertion in zip file export test to match the full content…

    … disposition
    
    string, which should include the filename (xform id string).
    Denis Papathanasiou committed Jun 5, 2014
    Configuration menu
    Copy the full SHA
    ada9b77 View commit details
    Browse the repository at this point in the history
  2. Changed create_attachments_zipfile() to return a handle to the tempor…

    …ary file-like
    
    object corresponding to the zipped file, rather than the entire data stream of the
    file contents, since it is safer for the functions which invoke it to handle it
    themselves.
    
    As with the previous revision, this function does *not* leave files in /tmp after
    the request is completed.
    Denis Papathanasiou committed Jun 5, 2014
    Configuration menu
    Copy the full SHA
    e401c56 View commit details
    Browse the repository at this point in the history
  3. Updated zip_export() to use the file-like object handle of the zip fi…

    …le, rather than
    
    the full data stream of the prior version.
    Denis Papathanasiou committed Jun 5, 2014
    Configuration menu
    Copy the full SHA
    660fb7e View commit details
    Browse the repository at this point in the history
  4. Updated generate_attachments_zip_export() to use the file-like object…

    … handle of the zip file,
    
    rather than the full data stream of the prior version.
    Denis Papathanasiou committed Jun 5, 2014
    Configuration menu
    Copy the full SHA
    e0a57fc View commit details
    Browse the repository at this point in the history