2018-11-17 21:31:54 +01:00
|
|
|
From 93fdc52bb756566271a2223058c6b09ab96b1343 Mon Sep 17 00:00:00 2001
|
2016-04-12 19:31:48 +02:00
|
|
|
From: Antonio Terceiro <terceiro@debian.org>
|
|
|
|
Date: Wed, 22 Oct 2014 09:40:14 -0200
|
2017-08-31 21:03:29 +02:00
|
|
|
Subject: [PATCH] Use a private temporary dir
|
2016-04-12 19:31:48 +02:00
|
|
|
|
|
|
|
Without this vagrant will clutter $TMPDIR with dozens of even hundreds
|
|
|
|
of temporary files (~4 per vagrant invocation).
|
2017-08-31 21:03:29 +02:00
|
|
|
|
|
|
|
Signed-off-by: Johannes Kastl <kastl@b1-systems.de>
|
2016-04-12 19:31:48 +02:00
|
|
|
---
|
|
|
|
lib/vagrant/box.rb | 3 ++-
|
2017-08-31 21:03:29 +02:00
|
|
|
lib/vagrant/util.rb | 2 ++
|
2018-11-17 21:30:13 +01:00
|
|
|
lib/vagrant/util/tempfile.rb | 39 ++++++++++++++++++++++++++++++++++++
|
2017-08-31 21:03:29 +02:00
|
|
|
3 files changed, 43 insertions(+), 1 deletion(-)
|
2016-04-12 19:31:48 +02:00
|
|
|
create mode 100644 lib/vagrant/util/tempfile.rb
|
|
|
|
|
2017-03-12 20:03:16 +01:00
|
|
|
diff --git a/lib/vagrant/box.rb b/lib/vagrant/box.rb
|
2017-08-31 21:03:29 +02:00
|
|
|
index cd839ee91..65eee8828 100644
|
2016-04-12 19:31:48 +02:00
|
|
|
--- 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
|
|
|
|
@@ -118,7 +119,7 @@ module Vagrant
|
|
|
|
# @param [Hash] download_options Options to pass to the downloader.
|
|
|
|
# @return [BoxMetadata]
|
|
|
|
def load_metadata(**download_options)
|
2017-03-12 20:03:16 +01:00
|
|
|
- tf = Tempfile.new("vagrant-load-metadata")
|
|
|
|
+ tf = Util::Tempfile.new("vagrant-load-metadata")
|
2016-04-12 19:31:48 +02:00
|
|
|
tf.close
|
|
|
|
|
|
|
|
url = @metadata_url
|
2017-03-12 20:03:16 +01:00
|
|
|
diff --git a/lib/vagrant/util.rb b/lib/vagrant/util.rb
|
2018-11-17 21:30:13 +01:00
|
|
|
index 32babe50d..217469e85 100644
|
2016-04-12 19:31:48 +02:00
|
|
|
--- a/lib/vagrant/util.rb
|
|
|
|
+++ b/lib/vagrant/util.rb
|
2018-11-17 21:30:13 +01:00
|
|
|
@@ -15,6 +15,8 @@ module Vagrant
|
2016-04-12 19:31:48 +02:00
|
|
|
autoload :SafeExec, 'vagrant/util/safe_exec'
|
2017-08-31 21:03:29 +02:00
|
|
|
autoload :SilenceWarnings, 'vagrant/util/silence_warnings'
|
2016-04-12 19:31:48 +02:00
|
|
|
autoload :StackedProcRunner, 'vagrant/util/stacked_proc_runner'
|
|
|
|
+ autoload :Tempfile, 'vagrant/util/tempfile'
|
2017-08-31 21:03:29 +02:00
|
|
|
+ autoload :TemplateRenderer, 'vagrant/util/template_renderer'
|
2017-03-12 20:03:16 +01:00
|
|
|
autoload :StringBlockEditor, 'vagrant/util/string_block_editor'
|
2016-04-12 19:31:48 +02:00
|
|
|
autoload :Subprocess, 'vagrant/util/subprocess'
|
2017-08-31 21:03:29 +02:00
|
|
|
autoload :TemplateRenderer, 'vagrant/util/template_renderer'
|
2017-03-12 20:03:16 +01:00
|
|
|
diff --git a/lib/vagrant/util/tempfile.rb b/lib/vagrant/util/tempfile.rb
|
|
|
|
new file mode 100644
|
2017-08-31 21:03:29 +02:00
|
|
|
index 000000000..0cbbb53ac
|
2016-04-12 19:31:48 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/lib/vagrant/util/tempfile.rb
|
2017-03-12 20:03:16 +01:00
|
|
|
@@ -0,0 +1,39 @@
|
2016-04-12 19:31:48 +02:00
|
|
|
+require 'fileutils'
|
2017-03-12 20:03:16 +01:00
|
|
|
+require 'tmpdir'
|
2016-04-12 19:31:48 +02:00
|
|
|
+
|
|
|
|
+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
|
|
|
|
+
|
2017-03-12 20:03:16 +01:00
|
|
|
+ def self.mktmpdir(prefix_suffix)
|
|
|
|
+ Dir.mktmpdir(prefix_suffix, private_tmpdir)
|
|
|
|
+ end
|
|
|
|
+
|
|
|
|
+
|
2016-04-12 19:31:48 +02:00
|
|
|
+ end
|
|
|
|
+ end
|
|
|
|
+end
|
|
|
|
+
|
|
|
|
+at_exit do
|
|
|
|
+ FileUtils.rm_rf(Vagrant::Util::Tempfile.private_tmpdir)
|
|
|
|
+end
|
2017-08-31 21:03:29 +02:00
|
|
|
--
|
2018-11-17 21:30:13 +01:00
|
|
|
2.19.1
|
2017-08-31 21:03:29 +02:00
|
|
|
|