Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • C chouette-core
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 36
    • Merge requests 36
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Administrator
  • chouette-core
  • Merge requests
  • !306

Merged
Created Feb 12, 2018 by Administrator@rootMaintainer

WorkbenchImportWorker: Use temp files for entry group subdir Zips

  • Overview 2
  • Commits 4
  • Changes 1

Created by: teddywing

Instead of creating our own files for these subdirectory Zip files, use temp files.

There are two advantages to doing this:

  1. We can customise the location they get saved to. This means we can use Rails.root as a default, but specify a custom location in a Rails config variable.
  2. The files will be automatically deleted on every garbage collection.

In actuality, #2 above was already handled by the eg_file.unlink line, and #1 could be easily added to the existing code.

Using a Tempfile, though, makes the fact that these are temporary files more explicit.

The reason why we want to be able to customise the location of these tempfiles is that in our production environment set up by Puppet, the #{Rails.root}/tmp/imports directory isn't writable by the application, which causes this code to error. We thus want a way to change the path in different environments.

We keep the eg_file.unlink call here because we want the temporary file to be deleted as soon as possible. The Ruby documentation even recommends it (https://ruby-doc.org/stdlib-2.5.0/libdoc/tempfile/rdoc/Tempfile.html#class-Tempfile-label-Explicit+close):

it's good practice to do so: not explicitly deleting unused Tempfiles can potentially leave behind large amounts of tempfiles on the filesystem until they're garbage collected.

I got rid of the #upload_entry_group_tmpfile method in this change, moving its contents to #upload_entry_group_stream. This was easy enough to do since it was only called in that one place. The reason I did this is because it took an open File object as an argument and closed the file at the end of the method. That's a major side effect. I don't think the method should be closing a file it doesn't own. After moving this work to #upload_entry_group_stream, we can close and unlink the file in the same place where it was created.

Refs #4315

Assignee
Assign to
Reviewer
Request review from
None
Milestone
None
Assign milestone
Time tracking
Source branch: 4315-WorkbenchImportWorker--use-tempfiles-to-store-split-zip