tempfile 0.1.3 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +10 -4
- data/Gemfile +1 -0
- data/Rakefile +0 -7
- data/lib/tempfile.rb +59 -19
- data/tempfile.gemspec +10 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce57b45a244b1e39fa3cb162b28a3d0a858d59083441ff31cb0dc5237c9d029f
|
4
|
+
data.tar.gz: 85d0949db220dc68bd4cef4e0bd98acd5629ef2c61af33a0c69acec346098f1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25265f76b8e05707c0a20f0218a28f316f1439659c1c27a40a17b04f70bf01032d4c1449e55c688f1799ddb86420f365f16fa663400933d3daa0f83ee533989f
|
7
|
+
data.tar.gz: 324cffaebce2f03134f06bd2646fe79bd71c44ca11ef7f8f2a6d4cf680726f55c7405a5497943295f1a332e8ad6a7e42b0bc69ab48491d41976044c66674ab65
|
data/.github/workflows/test.yml
CHANGED
@@ -3,15 +3,21 @@ name: ubuntu
|
|
3
3
|
on: [push, pull_request]
|
4
4
|
|
5
5
|
jobs:
|
6
|
-
|
6
|
+
ruby-versions:
|
7
|
+
uses: ruby/actions/.github/workflows/ruby_versions.yml@master
|
8
|
+
with:
|
9
|
+
engine: cruby
|
10
|
+
min_version: 2.5
|
11
|
+
test:
|
12
|
+
needs: ruby-versions
|
7
13
|
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
14
|
strategy:
|
9
15
|
matrix:
|
10
|
-
ruby:
|
11
|
-
os: [ ubuntu-latest, macos-latest ]
|
16
|
+
ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
|
17
|
+
os: [ ubuntu-latest, macos-latest, windows-latest ]
|
12
18
|
runs-on: ${{ matrix.os }}
|
13
19
|
steps:
|
14
|
-
- uses: actions/checkout@
|
20
|
+
- uses: actions/checkout@v4
|
15
21
|
- name: Set up Ruby
|
16
22
|
uses: ruby/setup-ruby@v1
|
17
23
|
with:
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -7,11 +7,4 @@ Rake::TestTask.new(:test) do |t|
|
|
7
7
|
t.test_files = FileList["test/**/test_*.rb"]
|
8
8
|
end
|
9
9
|
|
10
|
-
task :sync_tool do
|
11
|
-
require 'fileutils'
|
12
|
-
FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
|
13
|
-
FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
|
14
|
-
FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
|
15
|
-
end
|
16
|
-
|
17
10
|
task :default => :test
|
data/lib/tempfile.rb
CHANGED
@@ -57,7 +57,7 @@ require 'tmpdir'
|
|
57
57
|
# Note that Tempfile.create returns a File instance instead of a Tempfile, which
|
58
58
|
# also avoids the overhead and complications of delegation.
|
59
59
|
#
|
60
|
-
# Tempfile.
|
60
|
+
# Tempfile.create('foo') do |file|
|
61
61
|
# # ...do something with file...
|
62
62
|
# end
|
63
63
|
#
|
@@ -88,6 +88,8 @@ require 'tmpdir'
|
|
88
88
|
# mutex.
|
89
89
|
class Tempfile < DelegateClass(File)
|
90
90
|
|
91
|
+
VERSION = "0.2.1"
|
92
|
+
|
91
93
|
# Creates a file in the underlying file system;
|
92
94
|
# returns a new \Tempfile object based on that file.
|
93
95
|
#
|
@@ -150,26 +152,50 @@ class Tempfile < DelegateClass(File)
|
|
150
152
|
|
151
153
|
@unlinked = false
|
152
154
|
@mode = mode|File::RDWR|File::CREAT|File::EXCL
|
155
|
+
@finalizer_obj = Object.new
|
156
|
+
tmpfile = nil
|
153
157
|
::Dir::Tmpname.create(basename, tmpdir, **options) do |tmpname, n, opts|
|
154
158
|
opts[:perm] = 0600
|
155
|
-
|
159
|
+
tmpfile = File.open(tmpname, @mode, **opts)
|
156
160
|
@opts = opts.freeze
|
157
161
|
end
|
158
|
-
ObjectSpace.define_finalizer(
|
162
|
+
ObjectSpace.define_finalizer(@finalizer_obj, Remover.new(tmpfile.path))
|
163
|
+
ObjectSpace.define_finalizer(self, Closer.new(tmpfile))
|
164
|
+
|
165
|
+
super(tmpfile)
|
166
|
+
end
|
167
|
+
|
168
|
+
def initialize_dup(other)
|
169
|
+
initialize_copy_iv(other)
|
170
|
+
super(other)
|
171
|
+
ObjectSpace.define_finalizer(self, Closer.new(__getobj__))
|
172
|
+
end
|
173
|
+
|
174
|
+
def initialize_clone(other)
|
175
|
+
initialize_copy_iv(other)
|
176
|
+
super(other)
|
177
|
+
ObjectSpace.define_finalizer(self, Closer.new(__getobj__))
|
178
|
+
end
|
159
179
|
|
160
|
-
|
180
|
+
private def initialize_copy_iv(other)
|
181
|
+
@unlinked = other.unlinked
|
182
|
+
@mode = other.mode
|
183
|
+
@opts = other.opts
|
184
|
+
@finalizer_obj = other.finalizer_obj
|
161
185
|
end
|
162
186
|
|
163
187
|
# Opens or reopens the file with mode "r+".
|
164
188
|
def open
|
165
189
|
_close
|
190
|
+
ObjectSpace.undefine_finalizer(self)
|
166
191
|
mode = @mode & ~(File::CREAT|File::EXCL)
|
167
|
-
|
168
|
-
|
192
|
+
__setobj__(File.open(__getobj__.path, mode, **@opts))
|
193
|
+
ObjectSpace.define_finalizer(self, Closer.new(__getobj__))
|
194
|
+
__getobj__
|
169
195
|
end
|
170
196
|
|
171
197
|
def _close # :nodoc:
|
172
|
-
|
198
|
+
__getobj__.close
|
173
199
|
end
|
174
200
|
protected :_close
|
175
201
|
|
@@ -226,13 +252,13 @@ class Tempfile < DelegateClass(File)
|
|
226
252
|
def unlink
|
227
253
|
return if @unlinked
|
228
254
|
begin
|
229
|
-
File.unlink(
|
255
|
+
File.unlink(__getobj__.path)
|
230
256
|
rescue Errno::ENOENT
|
231
257
|
rescue Errno::EACCES
|
232
258
|
# may not be able to unlink on Windows; just ignore
|
233
259
|
return
|
234
260
|
end
|
235
|
-
ObjectSpace.undefine_finalizer(
|
261
|
+
ObjectSpace.undefine_finalizer(@finalizer_obj)
|
236
262
|
@unlinked = true
|
237
263
|
end
|
238
264
|
alias delete unlink
|
@@ -240,43 +266,57 @@ class Tempfile < DelegateClass(File)
|
|
240
266
|
# Returns the full path name of the temporary file.
|
241
267
|
# This will be nil if #unlink has been called.
|
242
268
|
def path
|
243
|
-
@unlinked ? nil :
|
269
|
+
@unlinked ? nil : __getobj__.path
|
244
270
|
end
|
245
271
|
|
246
272
|
# Returns the size of the temporary file. As a side effect, the IO
|
247
273
|
# buffer is flushed before determining the size.
|
248
274
|
def size
|
249
|
-
if
|
250
|
-
|
275
|
+
if !__getobj__.closed?
|
276
|
+
__getobj__.size # File#size calls rb_io_flush_raw()
|
251
277
|
else
|
252
|
-
File.size(
|
278
|
+
File.size(__getobj__.path)
|
253
279
|
end
|
254
280
|
end
|
255
281
|
alias length size
|
256
282
|
|
257
283
|
# :stopdoc:
|
258
284
|
def inspect
|
259
|
-
if
|
285
|
+
if __getobj__.closed?
|
260
286
|
"#<#{self.class}:#{path} (closed)>"
|
261
287
|
else
|
262
288
|
"#<#{self.class}:#{path}>"
|
263
289
|
end
|
264
290
|
end
|
291
|
+
alias to_s inspect
|
265
292
|
|
266
|
-
|
293
|
+
protected
|
294
|
+
|
295
|
+
attr_reader :unlinked, :mode, :opts, :finalizer_obj
|
296
|
+
|
297
|
+
class Closer # :nodoc:
|
267
298
|
def initialize(tmpfile)
|
268
|
-
@pid = Process.pid
|
269
299
|
@tmpfile = tmpfile
|
270
300
|
end
|
271
301
|
|
302
|
+
def call(*args)
|
303
|
+
@tmpfile.close
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
class Remover # :nodoc:
|
308
|
+
def initialize(path)
|
309
|
+
@pid = Process.pid
|
310
|
+
@path = path
|
311
|
+
end
|
312
|
+
|
272
313
|
def call(*args)
|
273
314
|
return if @pid != Process.pid
|
274
315
|
|
275
|
-
$stderr.puts "removing #{@
|
316
|
+
$stderr.puts "removing #{@path}..." if $DEBUG
|
276
317
|
|
277
|
-
@tmpfile.close
|
278
318
|
begin
|
279
|
-
File.unlink(@
|
319
|
+
File.unlink(@path)
|
280
320
|
rescue Errno::ENOENT
|
281
321
|
end
|
282
322
|
|
data/tempfile.gemspec
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
+
name = File.basename(__FILE__, ".gemspec")
|
2
|
+
version = ["lib", Array.new(name.count("-")+1).join("/")].find do |dir|
|
3
|
+
break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
|
4
|
+
/^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
|
5
|
+
end rescue nil
|
6
|
+
end
|
7
|
+
|
1
8
|
Gem::Specification.new do |spec|
|
2
|
-
spec.name =
|
3
|
-
spec.version =
|
9
|
+
spec.name = name
|
10
|
+
spec.version = version
|
4
11
|
spec.authors = ["Yukihiro Matsumoto"]
|
5
12
|
spec.email = ["matz@ruby-lang.org"]
|
6
13
|
|
@@ -16,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
16
23
|
# Specify which files should be added to the gem when it is released.
|
17
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
25
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
-
`git ls-files -z 2
|
26
|
+
`git ls-files -z 2>#{IO::NULL}`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
27
|
end
|
21
28
|
spec.require_paths = ["lib"]
|
22
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tempfile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yukihiro Matsumoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A utility class for managing temporary files.
|
14
14
|
email:
|
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
|
-
rubygems_version: 3.
|
53
|
+
rubygems_version: 3.5.0.dev
|
54
54
|
signing_key:
|
55
55
|
specification_version: 4
|
56
56
|
summary: A utility class for managing temporary files.
|