file-temp 1.7.1 → 1.7.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f7a532c6a985ef7afd93f064e38ff3fb81228d642707fa06156f23b1a2d33c6
4
- data.tar.gz: 5de639ab3cc6644fb385d35b364f8aa4c6c8afbd989706875a8e6f90193eaa18
3
+ metadata.gz: 04ece0eed9e9cc0e3ee18ef8637623714efe6bc817abdfc8583f933042e05029
4
+ data.tar.gz: 67155b0989bf977750f52abde8b57411f49c0dce07cae2a51d616298d4bf85e5
5
5
  SHA512:
6
- metadata.gz: 7e77feff9b86f7e33c233037e5c5342fac28a7bd3e5b18296cfae915e8a9e39b0d73a4a9dc87ac3ce096869b9bad401c98041bd2cb847a04d4c1b74f98a5b884
7
- data.tar.gz: 285fe4b48491c6468e7f0a3646d3a9da2b9d55e9386b5f6ee232882bb611311c3122ffa34ac98162e3f847f618c20fae57254c8135d368cc58aeb7d76761dd8e
6
+ metadata.gz: 249c699561ea25f3b427f7fc117c69d9ea848055e78063f87b99718786e4ad483f32c5e356dd836879a747b0d724c6dc2239f3c334d0ab0c71be7243bc7b823a
7
+ data.tar.gz: bf5db324f1069cfeed9a2930cf585edb3d2263c7634c9999c53c026f0ae09961055b03d51561cb5e9d045d4ed017dc2a528374c859f198492de8a1e604a9a0ca
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 1.7.3 - 23-Dec-2025
2
+ * Internal refactoring, replace mktemp with mkstemp.
3
+ * Internal refactoring, replace tmpnam with Ruby's SecureRandom.
4
+
5
+ ## 1.7.2 - 11-Jul-2023
6
+ * Fixed a bug in the Windows version where it would sometimes fail.
7
+ * Dropped JRuby from the test matrix for now because of a bug.
8
+ See https://github.com/jruby/jruby/issues/7847 for more details.
9
+
1
10
  ## 1.7.1 - 28-Dec-2020
2
11
  * Updated file option kwarg handling so that it's compatible with Ruby 3.x.
3
12
  * Switched from rdoc to markdown format since github isn't rendering rdoc properly.
data/Gemfile CHANGED
@@ -1,7 +1,2 @@
1
- source 'https://rubygems.org' do
2
- gem 'rake'
3
- gem 'ffi', '~> 1.1'
4
- group 'test' do
5
- gem 'rspec', '~> 3.9'
6
- end
7
- end
1
+ source 'https://rubygems.org'
2
+ gemspec
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Ruby](https://github.com/djberg96/file-temp/actions/workflows/ruby.yml/badge.svg)](https://github.com/djberg96/file-temp/actions/workflows/ruby.yml)
2
+
1
3
  ## Description
2
4
  The file-temp library is an alternate way to handle tempfile generation.
3
5
 
@@ -7,8 +9,11 @@ The file-temp library is an alternate way to handle tempfile generation.
7
9
  ## Installation
8
10
  `gem install file-temp`
9
11
 
12
+ ## Adding the trusted cert
13
+ `gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/file-temp/main/certs/djberg96_pub.pem)`
14
+
10
15
  ## Synopsis
11
- ```
16
+ ```ruby
12
17
  require 'file/temp'
13
18
 
14
19
  fh = File::Temp.new
@@ -42,18 +47,22 @@ temporary file name generated by Java is different than the C version,
42
47
  since it uses a GUID instead of the 'XXXXXX' template, but the
43
48
  interface is otherwise identical.
44
49
 
50
+ As of version 1.7.2 there is a known issue with using File::Temp.open
51
+ vs File::Temp.new. See https://github.com/jruby/jruby/issues/7847 for
52
+ more details.
53
+
45
54
  ## MS Windows
46
55
  You may need to use the mingw build in order to use this library.
47
56
 
48
57
  Also, there was a bug with the `GetTempFileName` function on certain versions
49
- of MS Windows that may cause a failure. However, if you'r patched up you
58
+ of MS Windows that may cause a failure. However, if you're patched up you
50
59
  should not see it.
51
60
 
52
61
  ## License
53
62
  Apache-2.0
54
63
 
55
64
  ## Copyright
56
- (C) 2007-2020 Daniel J. Berger
65
+ (C) 2007-2025 Daniel J. Berger
57
66
  All Rights Reserved
58
67
 
59
68
  ## Warranty
data/Rakefile CHANGED
@@ -1,17 +1,18 @@
1
1
  require 'rake'
2
2
  require 'rake/clean'
3
3
  require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
4
5
 
5
6
  CLEAN.include('**/*.tar', '**/*.zip', '**/*.gz', '**/*.bz2')
6
- CLEAN.include('**/*.rbc', '**/*.gem', '**/*.tmp')
7
+ CLEAN.include('**/*.rbc', '**/*.gem', '**/*.tmp', '**/*.lock')
7
8
 
8
9
  namespace 'gem' do
9
10
  desc 'Create the file-temp gem'
10
11
  task :create => [:clean] do
11
12
  require 'rubygems/package'
12
- spec = eval(IO.read('file-temp.gemspec'))
13
+ spec = Gem::Specification.load('file-temp.gemspec')
13
14
  spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
14
- Gem::Package.build(spec, true)
15
+ Gem::Package.build(spec)
15
16
  end
16
17
 
17
18
  desc 'Install the file-temp gem'
@@ -21,7 +22,17 @@ namespace 'gem' do
21
22
  end
22
23
  end
23
24
 
25
+ RuboCop::RakeTask.new
26
+
24
27
  desc 'Run the test suite for the file-temp library'
25
- RSpec::Core::RakeTask.new(:spec)
28
+ RSpec::Core::RakeTask.new(:spec) do |t|
29
+ t.verbose = false
30
+ t.rspec_opts = '-f documentation -w'
31
+ end
32
+
33
+ # Clean up afterwards
34
+ Rake::Task[:spec].enhance do
35
+ Rake::Task[:clean].invoke
36
+ end
26
37
 
27
38
  task :default => :spec
data/file-temp.gemspec CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'file-temp'
5
- spec.version = '1.7.1'
5
+ spec.version = '1.7.3'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.license = 'Apache-2.0'
8
8
  spec.email = 'djberg96@gmail.com'
@@ -14,15 +14,20 @@ Gem::Specification.new do |spec|
14
14
 
15
15
  spec.add_dependency('ffi', '~> 1.1')
16
16
  spec.add_development_dependency('rspec', '~> 3.9')
17
+ spec.add_development_dependency('rubocop')
18
+ spec.add_development_dependency('rubocop-rspec')
17
19
  spec.add_development_dependency('rake')
18
20
 
19
21
  spec.metadata = {
20
- 'homepage_uri' => 'https://github.com/djberg96/file-temp',
21
- 'bug_tracker_uri' => 'https://github.com/djberg96/file-temp/issues',
22
- 'changelog_uri' => 'https://github.com/djberg96/file-temp/blob/master/CHANGES.md',
23
- 'documentation_uri' => 'https://github.com/djberg96/file-temp/wiki',
24
- 'source_code_uri' => 'https://github.com/djberg96/file-temp',
25
- 'wiki_uri' => 'https://github.com/djberg96/file-temp/wiki'
22
+ 'homepage_uri' => 'https://github.com/djberg96/file-temp',
23
+ 'bug_tracker_uri' => 'https://github.com/djberg96/file-temp/issues',
24
+ 'changelog_uri' => 'https://github.com/djberg96/file-temp/blob/main/CHANGES.md',
25
+ 'documentation_uri' => 'https://github.com/djberg96/file-temp/wiki',
26
+ 'source_code_uri' => 'https://github.com/djberg96/file-temp',
27
+ 'wiki_uri' => 'https://github.com/djberg96/file-temp/wiki',
28
+ 'rubygems_mfa_required' => 'true',
29
+ 'github_repo' => 'https://github.com/djberg96/file-temp',
30
+ 'funding_uri' => 'https://github.com/sponsors/djberg96'
26
31
  }
27
32
 
28
33
  spec.description = <<-EOF
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'java'
2
- import java.lang.System
3
4
 
5
+ # The File::Temp class encapsulates temporary files. It is a subclass of File.
4
6
  class File::Temp < File
5
7
  # The temporary directory used on MS Windows or Unix.
6
- TMPDIR = java.lang.System.getProperties["java.io.tmpdir"]
8
+ TMPDIR = java.lang.System.getProperties['java.io.tmpdir']
7
9
 
8
10
  # The name of the temporary file.
9
11
  attr_reader :path
@@ -42,14 +44,14 @@ class File::Temp < File
42
44
  # to Errno::EINVAL.
43
45
  begin
44
46
  @file = java.io.File.createTempFile(template, nil, java.io.File.new(directory))
45
- rescue NativeException => err
47
+ rescue NativeException
46
48
  raise SystemCallError.new(22), template # 22 is EINVAL
47
49
  end
48
50
 
49
51
  @file.deleteOnExit if delete
50
52
  options[:mode] ||= 'wb+'
51
53
 
52
- path = @file.getName
54
+ path = @file.getAbsolutePath
53
55
  super(path, **options)
54
56
 
55
57
  @path = path unless delete
@@ -69,6 +71,6 @@ class File::Temp < File
69
71
  #
70
72
  def close
71
73
  super
72
- @file.finalize
74
+ @file.finalize if @file.respond_to?(:finalize)
73
75
  end
74
76
  end
data/lib/file/temp.rb CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class File::Temp < File
2
4
  # The version of the file-temp library
3
- VERSION = '1.7.1'.freeze
5
+ VERSION = '1.7.3'
4
6
  end
5
7
 
6
8
  if RUBY_PLATFORM == 'java'
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ffi'
2
4
  require 'tmpdir'
5
+ require 'securerandom'
3
6
 
7
+ # The File::Temp class encapsulates temporary files. It is a subclass of File.
4
8
  class File::Temp < File
5
9
  extend FFI::Library
6
10
  ffi_lib FFI::Library::LIBC
@@ -13,11 +17,10 @@ class File::Temp < File
13
17
  attach_function :_fileno, :fileno, [:pointer], :int
14
18
  attach_function :strerror, [:int], :string
15
19
  attach_function :tmpfile, [], :pointer
16
- attach_function :tmpnam, [:pointer], :string
17
- attach_function :mktemp, [:pointer], :string
20
+ attach_function :mkstemp, [:pointer], :int
18
21
 
19
- private_class_method :mktemp, :strerror, :tmpfile
20
- private_class_method :tmpnam, :fclose, :_fileno
22
+ private_class_method :mkstemp, :strerror, :tmpfile
23
+ private_class_method :fclose, :_fileno
21
24
 
22
25
  public
23
26
 
@@ -39,7 +42,7 @@ class File::Temp < File
39
42
  #
40
43
  # If the +delete+ option is set to false, then the file is not deleted. In
41
44
  # addition, you can supply a string +template+ that the system replaces with
42
- # a unique filename. This template should end with 3 to 6 'X' characters.
45
+ # a unique filename. This template should end with 6 'X' characters.
43
46
  # The default template is 'rb_file_temp_XXXXXX'. In this case the temporary
44
47
  # file lives in the directory where it was created.
45
48
  #
@@ -53,22 +56,32 @@ class File::Temp < File
53
56
  #
54
57
  def initialize(delete: true, template: 'rb_file_temp_XXXXXX', directory: TMPDIR, **options)
55
58
  @fptr = nil
59
+ temp_path = nil
56
60
 
57
61
  if delete
58
62
  @fptr = tmpfile()
59
63
  raise SystemCallError.new('tmpfile', FFI.errno) if @fptr.null?
60
64
  fd = _fileno(@fptr)
61
65
  else
66
+ unless template.is_a?(String)
67
+ raise TypeError, "template must be a String"
68
+ end
69
+
70
+ unless template.end_with?('XXXXXX')
71
+ raise ArgumentError, "template must end with 6 'X' characters"
72
+ end
73
+
62
74
  begin
63
75
  omask = File.umask(077)
64
- ptr = FFI::MemoryPointer.from_string(template)
65
- str = mktemp(ptr)
76
+ full_template = File.join(directory, template)
77
+ ptr = FFI::MemoryPointer.from_string(full_template)
78
+ fd = mkstemp(ptr)
66
79
 
67
- if str.nil? || str.empty?
68
- raise SystemCallError.new('mktemp', FFI.errno)
80
+ if fd < 0
81
+ raise SystemCallError.new('mkstemp', FFI.errno)
69
82
  end
70
83
 
71
- @path = File.join(directory, ptr.read_string)
84
+ temp_path = ptr.read_string
72
85
  ensure
73
86
  File.umask(omask)
74
87
  end
@@ -76,11 +89,9 @@ class File::Temp < File
76
89
 
77
90
  options[:mode] ||= 'wb+'
78
91
 
79
- if delete
80
- super(fd, **options)
81
- else
82
- super(@path, **options)
83
- end
92
+ super(fd, **options)
93
+
94
+ @path = temp_path
84
95
  end
85
96
 
86
97
  # The close method was overridden to ensure the internal file pointer that we
@@ -101,6 +112,6 @@ class File::Temp < File
101
112
  # Note that a file is not actually generated on the filesystem.
102
113
  #
103
114
  def self.temp_name
104
- tmpnam(nil) << '.tmp'
115
+ File.join(TMPDIR, "tmp.#{SecureRandom.hex(8)}.tmp")
105
116
  end
106
117
  end
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ffi'
2
4
  require 'tmpdir'
3
5
 
6
+ # The File::Temp class encapsulates temporary files. It is a subclass of File.
4
7
  class File::Temp < File
5
8
  extend FFI::Library
6
9
  ffi_lib FFI::Library::LIBC
10
+ ffi_convention :stdcall
7
11
 
8
12
  # :stopdoc:
9
13
 
@@ -11,13 +15,13 @@ class File::Temp < File
11
15
 
12
16
  attach_function :_close, [:int], :int
13
17
  attach_function :fclose, [:pointer], :int
14
- attach_function :_fdopen, [:int, :string], :pointer
18
+ attach_function :_fdopen, %i[int string], :pointer
15
19
  attach_function :_fileno, [:pointer], :int
16
20
  attach_function :_get_errno, [:pointer], :int
17
- attach_function :_open, [:string, :int, :int], :int
18
- attach_function :_open_osfhandle, [:long, :int], :int
19
- attach_function :tmpnam_s, [:pointer, :size_t], :int
20
- attach_function :mktemp_s, :_mktemp_s, [:pointer, :size_t], :int
21
+ attach_function :_open, %i[string int int], :int
22
+ attach_function :_open_osfhandle, %i[long int], :int
23
+ attach_function :tmpnam_s, %i[pointer size_t], :int
24
+ attach_function :mktemp_s, :_mktemp_s, %i[pointer size_t], :int
21
25
 
22
26
  private_class_method :_close, :fclose, :_fdopen, :_fileno, :_get_errno
23
27
  private_class_method :_open, :_open_osfhandle, :mktemp_s, :tmpnam_s
@@ -25,10 +29,10 @@ class File::Temp < File
25
29
  ffi_lib :kernel32
26
30
 
27
31
  attach_function :CloseHandle, [:long], :bool
28
- attach_function :CreateFileW, [:buffer_in, :ulong, :ulong, :pointer, :ulong, :ulong, :ulong], :long
32
+ attach_function :CreateFileW, %i[buffer_in ulong ulong pointer ulong ulong ulong], :long
29
33
  attach_function :DeleteFileW, [:string], :bool
30
- attach_function :GetTempPathW, [:ulong, :buffer_out], :ulong
31
- attach_function :GetTempFileNameW, [:buffer_in, :string, :uint, :buffer_out], :uint
34
+ attach_function :GetTempPathW, %i[ulong buffer_out], :ulong
35
+ attach_function :GetTempFileNameW, %i[buffer_in string uint buffer_out], :uint
32
36
 
33
37
  private_class_method :_close, :_fdopen, :_open, :_open_osfhandle
34
38
  private_class_method :CloseHandle, :CreateFileW, :DeleteFileW
@@ -88,6 +92,14 @@ class File::Temp < File
88
92
  @fptr = tmpfile()
89
93
  fd = _fileno(@fptr)
90
94
  else
95
+ unless template.is_a?(String)
96
+ raise TypeError, "template must be a String"
97
+ end
98
+
99
+ unless template.end_with?('XXXXXX')
100
+ raise ArgumentError, "template must end with 6 'X' characters"
101
+ end
102
+
91
103
  begin
92
104
  omask = File.umask(077)
93
105
  ptr = FFI::MemoryPointer.from_string(template)
@@ -134,7 +146,7 @@ class File::Temp < File
134
146
 
135
147
  raise SystemCallError.new('tmpnam_s', errno) if errno != 0
136
148
 
137
- directory + ptr.read_string + 'tmp'
149
+ directory + (ptr.read_string << 'tmp')
138
150
  end
139
151
 
140
152
  private
@@ -153,13 +165,12 @@ class File::Temp < File
153
165
  #
154
166
  def get_temp_path
155
167
  buf = 0.chr * 1024
156
- buf.encode!("UTF-16LE")
168
+ buf.encode!('UTF-16LE')
157
169
 
158
- if GetTempPathW(buf.size, buf) == 0
159
- raise SystemCallError, FFI.errno, 'GetTempPathW'
160
- end
170
+ rv = GetTempPathW(buf.size, buf)
171
+ raise SystemCallError, FFI.errno, 'GetTempPathW' if rv == 0
161
172
 
162
- buf.strip.chop # remove trailing slash
173
+ buf[0, rv+2] # Characters plus null terminator
163
174
  end
164
175
 
165
176
  # The version of tmpfile() implemented by Microsoft is unacceptable.
@@ -171,15 +182,16 @@ class File::Temp < File
171
182
  # project.
172
183
  #
173
184
  def tmpfile
174
- file_name = get_temp_path()
185
+ file_name = get_temp_path
186
+
175
187
  buf = 0.chr * 1024
176
- buf.encode!("UTF-16LE")
188
+ buf.encode!('UTF-16LE')
177
189
 
178
- if GetTempFileNameW(file_name, 'rb_', 0, buf) == 0
190
+ if GetTempFileNameW(file_name, String.new('rb_', encoding: 'UTF-16LE'), 0, buf) == 0
179
191
  raise SystemCallError, FFI.errno, 'GetTempFileNameW'
180
192
  end
181
193
 
182
- file_name = buf.strip
194
+ file_name = buf.strip + "\000\000".encode('UTF-16LE')
183
195
 
184
196
  handle = CreateFileW(
185
197
  file_name,
data/lib/file-temp.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'file/temp'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ######################################################################
2
4
  # file_temp_spec.rb
3
5
  #
@@ -10,6 +12,7 @@ require 'file/temp'
10
12
  RSpec.describe File::Temp do
11
13
  let(:windows) { File::ALT_SEPARATOR }
12
14
  let(:osx) { RbConfig::CONFIG['host_os'] =~ /darwin/i }
15
+ let(:bsd) { RbConfig::CONFIG['host_os'] =~ /freebsd|dragonfly/i }
13
16
 
14
17
  before do
15
18
  @dir = File::Temp::TMPDIR
@@ -17,143 +20,148 @@ RSpec.describe File::Temp do
17
20
  @fh = nil
18
21
 
19
22
  # Because Dir[] doesn't work right with backslashes
20
- @dir = @dir.tr("\\", "/") if windows
23
+ @dir = @dir.tr('\\', '/') if windows
21
24
  end
22
25
 
23
- context "constants" do
24
- example "library version is set to expected value" do
25
- expect( File::Temp::VERSION).to eq('1.7.1')
26
+ after do
27
+ @dir = nil
28
+ @template = nil
29
+ @fh.close if @fh && !@fh.closed?
30
+ @fh = nil
31
+
32
+ Dir['temp_*'].each{ |f| File.delete(f) }
33
+ Dir['rb_file_temp_*'].each{ |f| File.delete(f) }
34
+
35
+ Dir.chdir(File::Temp::TMPDIR) do
36
+ Dir['temp_*'].each{ |f| File.delete(f) }
37
+ Dir['rb_file_temp_*'].each{ |f| File.delete(f) }
38
+ end
39
+ end
40
+
41
+ context 'constants' do
42
+ example 'library version is set to expected value' do
43
+ expect(File::Temp::VERSION).to eq('1.7.3')
26
44
  expect(File::Temp::VERSION).to be_frozen
27
45
  end
28
46
 
29
- example "TMPDIR constant is defined" do
30
- expect(File::Temp::TMPDIR).to be_kind_of(String)
47
+ example 'TMPDIR constant is defined' do
48
+ expect(File::Temp::TMPDIR).to be_a(String)
31
49
  expect(File::Temp::TMPDIR.size).to be > 0
32
50
  end
33
51
  end
34
52
 
35
- context "threads" do
36
- example "library works as expected with multiple threads" do
53
+ context 'threads' do
54
+ example 'library works as expected with multiple threads' do
37
55
  threads = []
38
- expect{ 100.times{ threads << Thread.new{ File::Temp.new }}}.not_to raise_error
39
- expect{ threads.each{ |t| t.join }.not_to raise_error }
56
+ expect{ 100.times{ threads << Thread.new{ described_class.new } } }.not_to raise_error
57
+ expect{ threads.each(&:join) }.not_to raise_error
40
58
  end
41
59
  end
42
60
 
43
- context "constructor" do
44
- example "constructor works as expected with default auto delete option" do
61
+ context 'constructor' do
62
+ example 'constructor works as expected with default auto delete option' do
45
63
  expect{
46
- @fh = File::Temp.new
47
- @fh.print "hello"
64
+ @fh = described_class.new
65
+ @fh.print 'hello'
48
66
  @fh.close
49
67
  }.not_to raise_error
50
68
  end
51
69
 
52
- example "constructor works as expected with false auto delete option" do
70
+ example 'constructor works as expected with false auto delete option' do
53
71
  expect{
54
- @fh = File::Temp.new(:delete => false)
55
- @fh.print "hello"
72
+ @fh = described_class.new(:delete => false)
73
+ @fh.print 'hello'
56
74
  @fh.close
57
75
  }.not_to raise_error
58
76
  end
59
77
 
60
- example "constructor accepts and uses an optional template as expected" do
61
- expect{ File::Temp.new(:delete => false, :template => 'temp_foo_XXXXXX').close }.not_to raise_error
78
+ example 'constructor accepts and uses an optional template as expected' do
79
+ expect{ described_class.new(:delete => false, :template => 'temp_foo_XXXXXX').close }.not_to raise_error
62
80
  expect(Dir["#{@dir}/temp_foo*"].length).to be >= 1
63
81
  end
64
82
 
65
- example "constructor with false auto delete and block works as expected" do
83
+ example 'constructor with false auto delete and block works as expected' do
66
84
  expect{
67
- File::Temp.open(:delete => false, :template => 'temp_foo_XXXXXX'){ |fh| fh.puts "hello" }
85
+ described_class.open(:delete => false, :template => 'temp_foo_XXXXXX'){ |fh| fh.puts 'hello' }
68
86
  }.not_to raise_error
69
87
  expect(Dir["#{@dir}/temp_foo*"].length).to be >= 1
70
88
  end
71
89
 
72
- example "other arguments are treated as file option arguments" do
90
+ example 'other arguments are treated as file option arguments' do
73
91
  expect{
74
- @fh = File::Temp.new(
92
+ @fh = described_class.new(
75
93
  :delete => true,
76
94
  :template => 'temp_bar_XXXXX',
77
95
  :directory => Dir.pwd,
78
96
  :mode => 'xb'
79
97
  )
80
- }.to raise_error(ArgumentError, /invalid access mode/)
98
+ }.to raise_error(ArgumentError, /invalid.*?(access)?.*?mode/) # Truffleruby missing the word 'access'
81
99
  end
82
100
  end
83
101
 
84
- context "template" do
85
- example "template argument must be a string" do
86
- expect{ @fh = File::Temp.new(:delete => false, :template => 1) }.to raise_error(TypeError)
102
+ context 'template' do
103
+ example 'template argument must be a string' do
104
+ expect{ @fh = described_class.new(:delete => false, :template => 1) }.to raise_error(TypeError)
87
105
  end
88
106
 
89
- example "an error is raised if a custom template is invalid" do
90
- skip "skipped on OSX" if osx
91
- expect{ File::Temp.new(:delete => false, :template => 'xx') }.to raise_error(Errno::EINVAL)
107
+ example 'an error is raised if a custom template is invalid' do
108
+ expect{ described_class.new(:delete => false, :template => 'xx') }.to raise_error(ArgumentError, /template must end with 6/)
92
109
  end
93
110
  end
94
111
 
95
- context "temp_name" do
96
- example "temp_name basic functionality" do
97
- expect(File::Temp).to respond_to(:temp_name)
98
- expect{ File::Temp.temp_name }.not_to raise_error
99
- expect(File::Temp.temp_name).to be_kind_of(String)
112
+ context 'temp_name' do
113
+ example 'temp_name basic functionality' do
114
+ expect(described_class).to respond_to(:temp_name)
115
+ expect{ described_class.temp_name }.not_to raise_error
116
+ expect(described_class.temp_name).to be_a(String)
100
117
  end
101
118
 
102
- example "temp_name returns expected value" do
119
+ example 'temp_name returns expected value' do
103
120
  if windows
104
- expect( File.extname(File::Temp.temp_name)).to match(/^.*?\d*?tmp/)
121
+ expect(File.extname(described_class.temp_name)).to match(/^.*?\d*?tmp/)
105
122
  else
106
- expect( File.extname(File::Temp.temp_name)).to eq('.tmp')
123
+ expect(File.extname(described_class.temp_name)).to eq('.tmp')
107
124
  end
108
125
  end
109
126
  end
110
127
 
111
- context "path" do
112
- example "temp path basic functionality" do
113
- @fh = File::Temp.new
128
+ context 'path' do
129
+ example 'temp path basic functionality' do
130
+ @fh = described_class.new
114
131
  expect(@fh).to respond_to(:path)
115
132
  end
116
133
 
117
- example "temp path is nil if delete option is true" do
118
- @fh = File::Temp.new
134
+ example 'temp path is nil if delete option is true' do
135
+ @fh = described_class.new
119
136
  expect(@fh.path).to be_nil
120
137
  end
121
138
 
122
- example "temp path is not nil if delete option is false" do
123
- @fh = File::Temp.new(delete: false)
139
+ example 'temp path is not nil if delete option is false' do
140
+ @fh = described_class.new(delete: false)
124
141
  expect(@fh.path).not_to be_nil
125
142
  end
126
143
  end
127
144
 
128
- context "ffi" do
129
- example "ffi functions are private" do
130
- methods = File::Temp.methods(false).map(&:to_s)
131
- expect(methods).not_to include('_fileno')
132
- expect(methods).not_to include('mkstemp')
133
- expect(methods).not_to include('_umask')
134
- expect(methods).not_to include('fclose')
135
- expect(methods).not_to include('strerror')
136
- expect(methods).not_to include('tmpnam')
137
- expect(methods).not_to include('CloseHandle')
138
- expect(methods).not_to include('CreateFileA')
139
- expect(methods).not_to include('DeleteFileA')
140
- expect(methods).not_to include('GetTempPathA')
141
- expect(methods).not_to include('GetTempFileNameA')
145
+ context 'ffi' do
146
+ before do
147
+ @methods = described_class.methods(false).map(&:to_s)
142
148
  end
143
- end
144
-
145
- after do
146
- @dir = nil
147
- @template = nil
148
- @fh.close if @fh && !@fh.closed?
149
- @fh = nil
150
149
 
151
- Dir["temp_*"].each{ |f| File.delete(f) }
152
- Dir["rb_file_temp_*"].each{ |f| File.delete(f) }
150
+ example 'ffi unix functions are private', :unix do
151
+ expect(@methods).not_to include('_fileno')
152
+ expect(@methods).not_to include('mkstemp')
153
+ expect(@methods).not_to include('_umask')
154
+ expect(@methods).not_to include('fclose')
155
+ expect(@methods).not_to include('strerror')
156
+ expect(@methods).not_to include('tmpnam')
157
+ end
153
158
 
154
- Dir.chdir(File::Temp::TMPDIR) do
155
- Dir["temp_*"].each{ |f| File.delete(f) }
156
- Dir["rb_file_temp_*"].each{ |f| File.delete(f) }
159
+ example 'ffi windows functions are private', :windows do
160
+ expect(@methods).not_to include('CloseHandle')
161
+ expect(@methods).not_to include('CreateFileA')
162
+ expect(@methods).not_to include('DeleteFileA')
163
+ expect(@methods).not_to include('GetTempPathA')
164
+ expect(@methods).not_to include('GetTempFileNameA')
157
165
  end
158
166
  end
159
167
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file-temp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain:
11
10
  - |
@@ -35,7 +34,7 @@ cert_chain:
35
34
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
35
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
36
  -----END CERTIFICATE-----
38
- date:
37
+ date: 1980-01-02 00:00:00.000000000 Z
39
38
  dependencies:
40
39
  - !ruby/object:Gem::Dependency
41
40
  name: ffi
@@ -65,6 +64,34 @@ dependencies:
65
64
  - - "~>"
66
65
  - !ruby/object:Gem::Version
67
66
  version: '3.9'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rubocop
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rubocop-rspec
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
68
95
  - !ruby/object:Gem::Dependency
69
96
  name: rake
70
97
  requirement: !ruby/object:Gem::Requirement
@@ -88,38 +115,33 @@ executables: []
88
115
  extensions: []
89
116
  extra_rdoc_files: []
90
117
  files:
118
+ - CHANGES.md
119
+ - Gemfile
91
120
  - LICENSE
92
- - file-temp.gemspec
93
- - spec
94
- - spec/file_temp_spec.rb
121
+ - MANIFEST.md
95
122
  - README.md
96
123
  - Rakefile
97
- - MANIFEST.md
98
- - certs
99
124
  - certs/djberg96_pub.pem
100
- - lib
125
+ - file-temp.gemspec
101
126
  - lib/file-temp.rb
102
- - lib/file
103
- - lib/file/temp.rb
104
- - lib/file/java
105
127
  - lib/file/java/temp.rb
106
- - lib/file/unix
128
+ - lib/file/temp.rb
107
129
  - lib/file/unix/temp.rb
108
- - lib/file/windows
109
130
  - lib/file/windows/temp.rb
110
- - Gemfile
111
- - CHANGES.md
131
+ - spec/file_temp_spec.rb
112
132
  homepage: http://github.com/djberg96/file-temp
113
133
  licenses:
114
134
  - Apache-2.0
115
135
  metadata:
116
136
  homepage_uri: https://github.com/djberg96/file-temp
117
137
  bug_tracker_uri: https://github.com/djberg96/file-temp/issues
118
- changelog_uri: https://github.com/djberg96/file-temp/blob/master/CHANGES.md
138
+ changelog_uri: https://github.com/djberg96/file-temp/blob/main/CHANGES.md
119
139
  documentation_uri: https://github.com/djberg96/file-temp/wiki
120
140
  source_code_uri: https://github.com/djberg96/file-temp
121
141
  wiki_uri: https://github.com/djberg96/file-temp/wiki
122
- post_install_message:
142
+ rubygems_mfa_required: 'true'
143
+ github_repo: https://github.com/djberg96/file-temp
144
+ funding_uri: https://github.com/sponsors/djberg96
123
145
  rdoc_options: []
124
146
  require_paths:
125
147
  - lib
@@ -134,8 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
156
  - !ruby/object:Gem::Version
135
157
  version: '0'
136
158
  requirements: []
137
- rubygems_version: 3.0.3
138
- signing_key:
159
+ rubygems_version: 3.7.2
139
160
  specification_version: 4
140
161
  summary: An alternative way to generate temp files
141
162
  test_files:
metadata.gz.sig CHANGED
Binary file