vagrant/0002-Use-a-private-temporary-dir.patch

99 lines
3.1 KiB
Diff

From b2c6ef61dc339eae73640c357e6be6e1f8cf723a Mon Sep 17 00:00:00 2001
From: Antonio Terceiro <terceiro@debian.org>
Date: Wed, 22 Oct 2014 09:40:14 -0200
Subject: [PATCH 02/12] Use a private temporary dir
Without this vagrant will clutter $TMPDIR with dozens of even hundreds
of temporary files (~4 per vagrant invocation).
Signed-off-by: Johannes Kastl <kastl@b1-systems.de>
---
lib/vagrant/box.rb | 3 ++-
lib/vagrant/util.rb | 2 ++
lib/vagrant/util/tempfile.rb | 39 ++++++++++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 1 deletion(-)
create mode 100644 lib/vagrant/util/tempfile.rb
diff --git a/lib/vagrant/box.rb b/lib/vagrant/box.rb
index 41b63b292..b2d4c6a05 100644
--- a/lib/vagrant/box.rb
+++ b/lib/vagrant/box.rb
@@ -9,6 +9,7 @@ require "vagrant/util/downloader"
require "vagrant/util/platform"
require "vagrant/util/safe_chdir"
require "vagrant/util/subprocess"
+require "vagrant/util/tempfile"
module Vagrant
# Represents a "box," which is a package Vagrant environment that is used
@@ -124,7 +125,7 @@ module Vagrant
# @param [Hash] download_options Options to pass to the downloader.
# @return [BoxMetadata]
def load_metadata(download_options={})
- tf = Tempfile.new("vagrant-load-metadata")
+ tf = Util::Tempfile.new("vagrant-load-metadata")
tf.close
url = @metadata_url
diff --git a/lib/vagrant/util.rb b/lib/vagrant/util.rb
index f8be2baf0..5776a56dd 100644
--- a/lib/vagrant/util.rb
+++ b/lib/vagrant/util.rb
@@ -16,6 +16,8 @@ module Vagrant
autoload :SafeExec, 'vagrant/util/safe_exec'
autoload :SilenceWarnings, 'vagrant/util/silence_warnings'
autoload :StackedProcRunner, 'vagrant/util/stacked_proc_runner'
+ autoload :Tempfile, 'vagrant/util/tempfile'
+ autoload :TemplateRenderer, 'vagrant/util/template_renderer'
autoload :StringBlockEditor, 'vagrant/util/string_block_editor'
autoload :Subprocess, 'vagrant/util/subprocess'
autoload :TemplateRenderer, 'vagrant/util/template_renderer'
diff --git a/lib/vagrant/util/tempfile.rb b/lib/vagrant/util/tempfile.rb
new file mode 100644
index 000000000..0cbbb53ac
--- /dev/null
+++ b/lib/vagrant/util/tempfile.rb
@@ -0,0 +1,39 @@
+require 'fileutils'
+require 'tmpdir'
+
+module Vagrant
+ module Util
+ class Tempfile < ::Tempfile
+
+ def initialize(basename)
+ super(basename, private_tmpdir)
+ end
+
+ def private_tmpdir
+ self.class.private_tmpdir
+ end
+
+ def self.private_tmpdir
+ @private_tmpdir ||=
+ begin
+ user = Etc.getpwuid.name
+ pid = Process.pid
+ tmpdir = File.join(Dir.tmpdir, "vagrant-#{user}-#{pid}")
+ FileUtils.mkdir_p(tmpdir)
+ FileUtils.chmod(0700, tmpdir)
+ tmpdir
+ end
+ end
+
+ def self.mktmpdir(prefix_suffix)
+ Dir.mktmpdir(prefix_suffix, private_tmpdir)
+ end
+
+
+ end
+ end
+end
+
+at_exit do
+ FileUtils.rm_rf(Vagrant::Util::Tempfile.private_tmpdir)
+end
--
2.30.1