file-temp 1.7.2 → 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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGES.md +4 -0
- data/README.md +1 -1
- data/Rakefile +9 -1
- data/file-temp.gemspec +4 -2
- data/lib/file/java/temp.rb +1 -1
- data/lib/file/temp.rb +1 -1
- data/lib/file/unix/temp.rb +24 -16
- data/lib/file/windows/temp.rb +8 -0
- data/spec/file_temp_spec.rb +3 -3
- data.tar.gz.sig +0 -0
- metadata +5 -6
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 04ece0eed9e9cc0e3ee18ef8637623714efe6bc817abdfc8583f933042e05029
|
|
4
|
+
data.tar.gz: 67155b0989bf977750f52abde8b57411f49c0dce07cae2a51d616298d4bf85e5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 249c699561ea25f3b427f7fc117c69d9ea848055e78063f87b99718786e4ad483f32c5e356dd836879a747b0d724c6dc2239f3c334d0ab0c71be7243bc7b823a
|
|
7
|
+
data.tar.gz: bf5db324f1069cfeed9a2930cf585edb3d2263c7634c9999c53c026f0ae09961055b03d51561cb5e9d045d4ed017dc2a528374c859f198492de8a1e604a9a0ca
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/CHANGES.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
## 1.7.3 - 23-Dec-2025
|
|
2
|
+
* Internal refactoring, replace mktemp with mkstemp.
|
|
3
|
+
* Internal refactoring, replace tmpnam with Ruby's SecureRandom.
|
|
4
|
+
|
|
1
5
|
## 1.7.2 - 11-Jul-2023
|
|
2
6
|
* Fixed a bug in the Windows version where it would sometimes fail.
|
|
3
7
|
* Dropped JRuby from the test matrix for now because of a bug.
|
data/README.md
CHANGED
data/Rakefile
CHANGED
|
@@ -25,6 +25,14 @@ end
|
|
|
25
25
|
RuboCop::RakeTask.new
|
|
26
26
|
|
|
27
27
|
desc 'Run the test suite for the file-temp library'
|
|
28
|
-
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
|
|
29
37
|
|
|
30
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.
|
|
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'
|
|
@@ -25,7 +25,9 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
'documentation_uri' => 'https://github.com/djberg96/file-temp/wiki',
|
|
26
26
|
'source_code_uri' => 'https://github.com/djberg96/file-temp',
|
|
27
27
|
'wiki_uri' => 'https://github.com/djberg96/file-temp/wiki',
|
|
28
|
-
'rubygems_mfa_required' => 'true'
|
|
28
|
+
'rubygems_mfa_required' => 'true',
|
|
29
|
+
'github_repo' => 'https://github.com/djberg96/file-temp',
|
|
30
|
+
'funding_uri' => 'https://github.com/sponsors/djberg96'
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
spec.description = <<-EOF
|
data/lib/file/java/temp.rb
CHANGED
data/lib/file/temp.rb
CHANGED
data/lib/file/unix/temp.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'ffi'
|
|
4
4
|
require 'tmpdir'
|
|
5
|
+
require 'securerandom'
|
|
5
6
|
|
|
6
7
|
# The File::Temp class encapsulates temporary files. It is a subclass of File.
|
|
7
8
|
class File::Temp < File
|
|
@@ -16,11 +17,10 @@ class File::Temp < File
|
|
|
16
17
|
attach_function :_fileno, :fileno, [:pointer], :int
|
|
17
18
|
attach_function :strerror, [:int], :string
|
|
18
19
|
attach_function :tmpfile, [], :pointer
|
|
19
|
-
attach_function :
|
|
20
|
-
attach_function :mktemp, [:pointer], :string
|
|
20
|
+
attach_function :mkstemp, [:pointer], :int
|
|
21
21
|
|
|
22
|
-
private_class_method :
|
|
23
|
-
private_class_method :
|
|
22
|
+
private_class_method :mkstemp, :strerror, :tmpfile
|
|
23
|
+
private_class_method :fclose, :_fileno
|
|
24
24
|
|
|
25
25
|
public
|
|
26
26
|
|
|
@@ -42,7 +42,7 @@ class File::Temp < File
|
|
|
42
42
|
#
|
|
43
43
|
# If the +delete+ option is set to false, then the file is not deleted. In
|
|
44
44
|
# addition, you can supply a string +template+ that the system replaces with
|
|
45
|
-
# a unique filename. This template should end with
|
|
45
|
+
# a unique filename. This template should end with 6 'X' characters.
|
|
46
46
|
# The default template is 'rb_file_temp_XXXXXX'. In this case the temporary
|
|
47
47
|
# file lives in the directory where it was created.
|
|
48
48
|
#
|
|
@@ -56,22 +56,32 @@ class File::Temp < File
|
|
|
56
56
|
#
|
|
57
57
|
def initialize(delete: true, template: 'rb_file_temp_XXXXXX', directory: TMPDIR, **options)
|
|
58
58
|
@fptr = nil
|
|
59
|
+
temp_path = nil
|
|
59
60
|
|
|
60
61
|
if delete
|
|
61
62
|
@fptr = tmpfile()
|
|
62
63
|
raise SystemCallError.new('tmpfile', FFI.errno) if @fptr.null?
|
|
63
64
|
fd = _fileno(@fptr)
|
|
64
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
|
+
|
|
65
74
|
begin
|
|
66
75
|
omask = File.umask(077)
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
full_template = File.join(directory, template)
|
|
77
|
+
ptr = FFI::MemoryPointer.from_string(full_template)
|
|
78
|
+
fd = mkstemp(ptr)
|
|
69
79
|
|
|
70
|
-
if
|
|
71
|
-
raise SystemCallError.new('
|
|
80
|
+
if fd < 0
|
|
81
|
+
raise SystemCallError.new('mkstemp', FFI.errno)
|
|
72
82
|
end
|
|
73
83
|
|
|
74
|
-
|
|
84
|
+
temp_path = ptr.read_string
|
|
75
85
|
ensure
|
|
76
86
|
File.umask(omask)
|
|
77
87
|
end
|
|
@@ -79,11 +89,9 @@ class File::Temp < File
|
|
|
79
89
|
|
|
80
90
|
options[:mode] ||= 'wb+'
|
|
81
91
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
super(@path, **options)
|
|
86
|
-
end
|
|
92
|
+
super(fd, **options)
|
|
93
|
+
|
|
94
|
+
@path = temp_path
|
|
87
95
|
end
|
|
88
96
|
|
|
89
97
|
# The close method was overridden to ensure the internal file pointer that we
|
|
@@ -104,6 +112,6 @@ class File::Temp < File
|
|
|
104
112
|
# Note that a file is not actually generated on the filesystem.
|
|
105
113
|
#
|
|
106
114
|
def self.temp_name
|
|
107
|
-
|
|
115
|
+
File.join(TMPDIR, "tmp.#{SecureRandom.hex(8)}.tmp")
|
|
108
116
|
end
|
|
109
117
|
end
|
data/lib/file/windows/temp.rb
CHANGED
|
@@ -92,6 +92,14 @@ class File::Temp < File
|
|
|
92
92
|
@fptr = tmpfile()
|
|
93
93
|
fd = _fileno(@fptr)
|
|
94
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
|
+
|
|
95
103
|
begin
|
|
96
104
|
omask = File.umask(077)
|
|
97
105
|
ptr = FFI::MemoryPointer.from_string(template)
|
data/spec/file_temp_spec.rb
CHANGED
|
@@ -12,6 +12,7 @@ require 'file/temp'
|
|
|
12
12
|
RSpec.describe File::Temp do
|
|
13
13
|
let(:windows) { File::ALT_SEPARATOR }
|
|
14
14
|
let(:osx) { RbConfig::CONFIG['host_os'] =~ /darwin/i }
|
|
15
|
+
let(:bsd) { RbConfig::CONFIG['host_os'] =~ /freebsd|dragonfly/i }
|
|
15
16
|
|
|
16
17
|
before do
|
|
17
18
|
@dir = File::Temp::TMPDIR
|
|
@@ -39,7 +40,7 @@ RSpec.describe File::Temp do
|
|
|
39
40
|
|
|
40
41
|
context 'constants' do
|
|
41
42
|
example 'library version is set to expected value' do
|
|
42
|
-
expect(File::Temp::VERSION).to eq('1.7.
|
|
43
|
+
expect(File::Temp::VERSION).to eq('1.7.3')
|
|
43
44
|
expect(File::Temp::VERSION).to be_frozen
|
|
44
45
|
end
|
|
45
46
|
|
|
@@ -104,8 +105,7 @@ RSpec.describe File::Temp do
|
|
|
104
105
|
end
|
|
105
106
|
|
|
106
107
|
example 'an error is raised if a custom template is invalid' do
|
|
107
|
-
|
|
108
|
-
expect{ described_class.new(:delete => false, :template => 'xx') }.to raise_error(Errno::EINVAL)
|
|
108
|
+
expect{ described_class.new(:delete => false, :template => 'xx') }.to raise_error(ArgumentError, /template must end with 6/)
|
|
109
109
|
end
|
|
110
110
|
end
|
|
111
111
|
|
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.
|
|
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
|
|
@@ -141,7 +140,8 @@ metadata:
|
|
|
141
140
|
source_code_uri: https://github.com/djberg96/file-temp
|
|
142
141
|
wiki_uri: https://github.com/djberg96/file-temp/wiki
|
|
143
142
|
rubygems_mfa_required: 'true'
|
|
144
|
-
|
|
143
|
+
github_repo: https://github.com/djberg96/file-temp
|
|
144
|
+
funding_uri: https://github.com/sponsors/djberg96
|
|
145
145
|
rdoc_options: []
|
|
146
146
|
require_paths:
|
|
147
147
|
- lib
|
|
@@ -156,8 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
156
156
|
- !ruby/object:Gem::Version
|
|
157
157
|
version: '0'
|
|
158
158
|
requirements: []
|
|
159
|
-
rubygems_version: 3.
|
|
160
|
-
signing_key:
|
|
159
|
+
rubygems_version: 3.7.2
|
|
161
160
|
specification_version: 4
|
|
162
161
|
summary: An alternative way to generate temp files
|
|
163
162
|
test_files:
|
metadata.gz.sig
CHANGED
|
Binary file
|