unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob 8d0012e8881542dd0ddb995de189b19f76599cee 4084 bytes (raw)
name: gnu/packages/patches/vagrant-Use-a-private-temporary-dir.patch 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 
From: Antonio Terceiro <terceiro@debian.org>
Date: Wed, 22 Oct 2014 09:40:14 -0200
Subject: Use a private temporary directory that is cleanup up on exit

This avoids vagrant from cluttering $TMPDIR with dozens of even hundreds
of temporary files (~4 per vagrant invocation).
---
 lib/vagrant/box.rb           |  3 ++-
 lib/vagrant/util.rb          |  1 +
 lib/vagrant/util/caps.rb     |  2 +-
 lib/vagrant/util/platform.rb |  2 +-
 lib/vagrant/util/tempfile.rb | 39 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 44 insertions(+), 3 deletions(-)
 create mode 100644 lib/vagrant/util/tempfile.rb

diff --git a/lib/vagrant/box.rb b/lib/vagrant/box.rb
index 90dc69d..4ee79b9 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
@@ -142,7 +143,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 4b3e0ff..36eb671 100644
--- a/lib/vagrant/util.rb
+++ b/lib/vagrant/util.rb
@@ -53,6 +53,7 @@ module Vagrant
     autoload :SilenceWarnings,           'vagrant/util/silence_warnings'
     autoload :SSH,                       'vagrant/util/ssh'
     autoload :StackedProcRunner,         'vagrant/util/stacked_proc_runner'
+    autoload :Tempfile,                  'vagrant/util/tempfile'
     autoload :StringBlockEditor,         'vagrant/util/string_block_editor'
     autoload :Subprocess,                'vagrant/util/subprocess'
     autoload :TemplateRenderer,          'vagrant/util/template_renderer'
diff --git a/lib/vagrant/util/caps.rb b/lib/vagrant/util/caps.rb
index 310add3..55afc49 100644
--- a/lib/vagrant/util/caps.rb
+++ b/lib/vagrant/util/caps.rb
@@ -28,7 +28,7 @@ module Vagrant
 
         def ensure_output_iso(file_destination)
           if file_destination.nil?
-            tmpfile = Tempfile.new(["vagrant", ".iso"])
+            tmpfile = Util::Tempfile.new(["vagrant", ".iso"])
             file_destination = Pathname.new(tmpfile.path)
             tmpfile.close
             tmpfile.unlink
diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb
index c8658e1..0421c70 100644
--- a/lib/vagrant/util/platform.rb
+++ b/lib/vagrant/util/platform.rb
@@ -356,7 +356,7 @@ module Vagrant
 
           if wsl?
             # Mark our filesystem with a temporary file having an unique name.
-            marker = Tempfile.new(Time.now.to_i.to_s)
+            marker = Util::Tempfile.new(Time.now.to_i.to_s)
             logger = Log4r::Logger.new("vagrant::util::platform::wsl")
 
             # Check for lxrun installation first
diff --git a/lib/vagrant/util/tempfile.rb b/lib/vagrant/util/tempfile.rb
new file mode 100644
index 0000000..0cbbb53
--- /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

debug log:

solving 8d0012e888 ...
found 8d0012e888 in https://yhetil.org/guix-patches/ce5dd68ceec0db51cd2dcf06b6f4b0db9e801b92.1691432343.git.h.goebel@crazy-compilers.com/

applying [1/1] https://yhetil.org/guix-patches/ce5dd68ceec0db51cd2dcf06b6f4b0db9e801b92.1691432343.git.h.goebel@crazy-compilers.com/
diff --git a/gnu/packages/patches/vagrant-Use-a-private-temporary-dir.patch b/gnu/packages/patches/vagrant-Use-a-private-temporary-dir.patch
new file mode 100644
index 0000000000..8d0012e888

1:31: trailing whitespace.
 
1:41: trailing whitespace.
 
1:60: trailing whitespace.
 
1:73: trailing whitespace.
 
1:79: trailing whitespace.
 
Checking patch gnu/packages/patches/vagrant-Use-a-private-temporary-dir.patch...
Applied patch gnu/packages/patches/vagrant-Use-a-private-temporary-dir.patch cleanly.
warning: 5 lines add whitespace errors.

index at:
100644 8d0012e8881542dd0ddb995de189b19f76599cee	gnu/packages/patches/vagrant-Use-a-private-temporary-dir.patch

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).