2021-04-01 14:26:31 +02:00
|
|
|
From ff54f5982a2b7365871d4ed1516de1ab7be4ff11 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
|
2021-04-01 14:26:31 +02:00
|
|
|
Subject: [PATCH 2/9] 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
|
2020-12-04 10:16:29 +01:00
|
|
|
index 41b63b292..b2d4c6a05 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
|
2020-12-04 10:16:29 +01:00
|
|
|
@@ -124,7 +125,7 @@ module Vagrant
|
2016-04-12 19:31:48 +02:00
|
|
|
# @param [Hash] download_options Options to pass to the downloader.
|
|
|
|
# @return [BoxMetadata]
|
2020-09-08 08:55:10 +02:00
|
|
|
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
|
2021-04-01 14:26:31 +02:00
|
|
|
index b7f297169..95e7850a3 100644
|
2016-04-12 19:31:48 +02:00
|
|
|
--- a/lib/vagrant/util.rb
|
|
|
|
+++ b/lib/vagrant/util.rb
|
2021-04-01 14:26:31 +02:00
|
|
|
@@ -17,6 +17,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
|
|
|
--
|
2021-04-01 14:26:31 +02:00
|
|
|
2.30.2
|
2017-08-31 21:03:29 +02:00
|
|
|
|