tmpdir 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tmpdir.rb +18 -10
  3. metadata +3 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1180516b6bd6658a8a32cfefe017af10eb41ed5fa78312d7dd27163b032f1632
4
- data.tar.gz: d7d4ebda12343e82d2fbfb1f750597692df607672bad6d3134637f94679a96b6
3
+ metadata.gz: 4eb38a5bf61de2e4ee459fbc8edfde50a1bb3a2bdd04c4afcdbb3fb763e1d3c6
4
+ data.tar.gz: acb48285b4eea792d1fbc72b4eaa1d07fd852d72d4108a3e92a60497525451b2
5
5
  SHA512:
6
- metadata.gz: 965aed93f89f7553bc5c780176119d397aa0b32a203b6f8913806a4e8925887cbe1f0cae96e073547cdf6f102a9c0b2d475fb323097ae9ec3e4e0bba63ba85ff
7
- data.tar.gz: a48a3973178e8047b1aa139660f2808811e739e6aef1825c316093c1da9c85b8248290a125e0e2f9cd381aca8d39caa250e02d190b23be40f555d3e97fb70086
6
+ metadata.gz: 98b1a5b86859465bba6c73a1046a42d25b4c1413f85c34d52f7482d6cc94fbfd14912c94458641d63a9c7488c2d39f22e84adf6785eb1fd8e9bb8fbad752fc46
7
+ data.tar.gz: 8c6c65aed1b0f7f41a1545f6fd53e8076bd638df3917aad75db0b6affc9c4b29fb64058b56365b0055fa4d7a32b2bf65e267be07bac4ea80919ca52d0d75be2d
data/lib/tmpdir.rb CHANGED
@@ -16,10 +16,6 @@ class Dir
16
16
  # Class variables are inaccessible from non-main Ractor.
17
17
  # And instance variables too, in Ruby 3.0.
18
18
 
19
- # System-wide temporary directory path
20
- SYSTMPDIR = (defined?(Etc.systmpdir) ? Etc.systmpdir.freeze : '/tmp')
21
- private_constant :SYSTMPDIR
22
-
23
19
  ##
24
20
  # Returns the operating system's temporary file path.
25
21
  #
@@ -27,7 +23,7 @@ class Dir
27
23
  # Dir.tmpdir # => "/tmp"
28
24
 
29
25
  def self.tmpdir
30
- ['TMPDIR', 'TMP', 'TEMP', ['system temporary path', SYSTMPDIR], ['/tmp']*2, ['.']*2].find do |name, dir|
26
+ Tmpname::TMPDIR_CANDIDATES.find do |name, dir|
31
27
  unless dir
32
28
  next if !(dir = ENV[name] rescue next) or dir.empty?
33
29
  end
@@ -77,7 +73,7 @@ class Dir
77
73
  # If a block is given,
78
74
  # it is yielded with the path of the directory.
79
75
  # The directory and its contents are removed
80
- # using FileUtils.remove_entry before Dir.mktmpdir returns.
76
+ # using FileUtils.remove_entry with force before Dir.mktmpdir returns.
81
77
  # The value of the block is returned.
82
78
  #
83
79
  # Dir.mktmpdir {|dir|
@@ -98,13 +94,13 @@ class Dir
98
94
  # FileUtils.remove_entry dir
99
95
  # end
100
96
  #
101
- def self.mktmpdir(prefix_suffix=nil, *rest, **options)
97
+ def self.mktmpdir(prefix_suffix=nil, *rest, **options, &block)
102
98
  base = nil
103
99
  path = Tmpname.create(prefix_suffix || "d", *rest, **options) {|path, _, _, d|
104
100
  base = d
105
101
  mkdir(path, 0700)
106
102
  }
107
- if block_given?
103
+ if block
108
104
  begin
109
105
  yield path.dup
110
106
  ensure
@@ -115,7 +111,7 @@ class Dir
115
111
  raise ArgumentError, "parent directory is world writable but not sticky: #{base}"
116
112
  end
117
113
  end
118
- FileUtils.remove_entry path
114
+ FileUtils.remove_entry path, true
119
115
  end
120
116
  else
121
117
  path
@@ -126,6 +122,18 @@ class Dir
126
122
  module Tmpname # :nodoc:
127
123
  module_function
128
124
 
125
+ # System-wide temporary directory path
126
+ systmpdir = (defined?(Etc.systmpdir) ? Etc.systmpdir.freeze : '/tmp')
127
+
128
+ # Temporary directory candidates consisting of environment variable
129
+ # names or description and path pairs.
130
+ TMPDIR_CANDIDATES = [
131
+ 'TMPDIR', 'TMP', 'TEMP',
132
+ ['system temporary path', systmpdir],
133
+ %w[/tmp /tmp],
134
+ %w[. .],
135
+ ].each(&:freeze).freeze
136
+
129
137
  def tmpdir
130
138
  Dir.tmpdir
131
139
  end
@@ -149,8 +157,8 @@ class Dir
149
157
 
150
158
  # Generates and yields random names to create a temporary name
151
159
  def create(basename, tmpdir=nil, max_try: nil, **opts)
152
- origdir = tmpdir
153
160
  if tmpdir
161
+ origdir = tmpdir = File.path(tmpdir)
154
162
  raise ArgumentError, "empty parent path" if tmpdir.empty?
155
163
  else
156
164
  tmpdir = tmpdir()
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tmpdir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-11-06 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: fileutils
@@ -46,7 +45,6 @@ licenses:
46
45
  metadata:
47
46
  homepage_uri: https://github.com/ruby/tmpdir
48
47
  source_code_uri: https://github.com/ruby/tmpdir
49
- post_install_message:
50
48
  rdoc_options: []
51
49
  require_paths:
52
50
  - lib
@@ -61,8 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
59
  - !ruby/object:Gem::Version
62
60
  version: '0'
63
61
  requirements: []
64
- rubygems_version: 3.5.11
65
- signing_key:
62
+ rubygems_version: 3.6.9
66
63
  specification_version: 4
67
64
  summary: Extends the Dir class to manage the OS temporary file path.
68
65
  test_files: []