file-temp 1.7.0 → 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/{CHANGES.rdoc → CHANGES.md} +27 -17
- data/Gemfile +2 -0
- data/{MANIFEST.rdoc → MANIFEST.md} +3 -3
- data/{README.rdoc → README.md} +36 -25
- data/Rakefile +6 -3
- data/file-temp.gemspec +10 -9
- data/lib/file/java/temp.rb +8 -6
- data/lib/file/temp.rb +3 -1
- data/lib/file/unix/temp.rb +6 -3
- data/lib/file/windows/temp.rb +25 -21
- data/lib/file-temp.rb +2 -0
- data/spec/file_temp_spec.rb +83 -75
- data.tar.gz.sig +0 -0
- metadata +44 -24
- 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: eff786722d8fdd2d775c3bf89a93256c3e6cb52a73966d13aa5f5520c37c96ee
|
4
|
+
data.tar.gz: 57637cb99fbb42afa24779c95527faeedf0a0ff304fc0eba3de517912377459e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35e334372e93fec4e19687f353262910bc7b77e7ccde89d48f01c92f86c85e329efcc00363bc7689447b67230dce4b50047dc8390ab06586e99bdd5c9fef55a2
|
7
|
+
data.tar.gz: 7443857009f786d4c8d460a1e2d3924f5deb1d6074c5f5813c39a4138e40e8e88132a5ec36152718fba2484d234cdc9c40f73fb98a15694aafddda07e89480c0
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/{CHANGES.rdoc → CHANGES.md}
RENAMED
@@ -1,13 +1,23 @@
|
|
1
|
-
|
1
|
+
## 1.7.2 - 11-Jul-2023
|
2
|
+
* Fixed a bug in the Windows version where it would sometimes fail.
|
3
|
+
* Dropped JRuby from the test matrix for now because of a bug.
|
4
|
+
See https://github.com/jruby/jruby/issues/7847 for more details.
|
5
|
+
|
6
|
+
## 1.7.1 - 28-Dec-2020
|
7
|
+
* Updated file option kwarg handling so that it's compatible with Ruby 3.x.
|
8
|
+
* Switched from rdoc to markdown format since github isn't rendering rdoc properly.
|
9
|
+
* Fixed up one of the specs.
|
10
|
+
|
11
|
+
## 1.7.0 - 1-Jul-2020
|
2
12
|
* Replaced test-unit with rspec, and updated the tests.
|
3
13
|
* Updated ffi dependency to 1.1.x.
|
4
14
|
* Removed some archiving options from the Rakefile that I wasn't using.
|
5
15
|
|
6
|
-
|
16
|
+
## 1.6.0 - 9-May-2020
|
7
17
|
* Added an +options+ argument that is passed along as options to the the
|
8
18
|
underlying File.new constructor.
|
9
19
|
|
10
|
-
|
20
|
+
## 1.5.0 - 8-May-2020
|
11
21
|
* Switched to keyword arguments.
|
12
22
|
* Added the ability to specify a tmp directory.
|
13
23
|
* Updates to the JRuby version, removed some code that no longer worked, and
|
@@ -15,13 +25,13 @@
|
|
15
25
|
* Added a LICENSE file to the distro as part of the Apache-2.0 requirement.
|
16
26
|
* Added explicit .rdoc extensions to the README, CHANGES and MANIFEST files.
|
17
27
|
|
18
|
-
|
28
|
+
## 1.4.0 - 12-Oct-2019
|
19
29
|
* Changed license to Apache-2.0.
|
20
30
|
* VERSION constant now lives in a single place, and is frozen.
|
21
31
|
* Added metadata to the gemspec.
|
22
32
|
* Updated cert.
|
23
33
|
|
24
|
-
|
34
|
+
## 1.3.0 - 9-Apr-2016
|
25
35
|
* This gem is now signed.
|
26
36
|
* Added a file-temp.rb file for convenience.
|
27
37
|
* The gem tasks in the Rakefile now assume Rubygems 2.x.
|
@@ -31,7 +41,7 @@
|
|
31
41
|
are each in their own directory and have their own versions for ease
|
32
42
|
of maintenance.
|
33
43
|
|
34
|
-
|
44
|
+
## 1.2.1 - 17-Feb-2014
|
35
45
|
* There is now a completely separate implementation for JRuby that uses the
|
36
46
|
Java API instead of C. It uses a GUID to create the temporary file name
|
37
47
|
instead of the 'XXXXXX' template, but is otherwise identical in function.
|
@@ -44,53 +54,53 @@
|
|
44
54
|
* Use tmpnam_s on Windows instead of tmpnam.
|
45
55
|
* Use wide character functions on Windows.
|
46
56
|
|
47
|
-
|
57
|
+
## 1.2.0 - 10-Apr-2012
|
48
58
|
* Removed the old FileTemp alias for File::Temp. It was deprecated and
|
49
59
|
has now been officially removed.
|
50
60
|
* Some refactoring of the custom internal Windows functions.
|
51
61
|
* Nicer error handling if certain FFI functions fail.
|
52
62
|
* Made the FFI functions private.
|
53
63
|
|
54
|
-
|
64
|
+
## 1.1.5 - 17-Jul-2011
|
55
65
|
* Now stores file path information if the file is retained on the filesystem.
|
56
66
|
Thanks go to joerixaop for the patch.
|
57
67
|
* The TMPDIR fallback determination on Windows is no longer hard coded.
|
58
68
|
|
59
|
-
|
69
|
+
## 1.1.4 - 16-Sep-2010
|
60
70
|
* The File::Temp.temp_name method has been altered on Unix systems. It
|
61
71
|
no longer prefixes TMPDIR to the name since it was redundant and could
|
62
72
|
generate a bogus path.
|
63
73
|
* Set the license to Artistic 2.0.
|
64
74
|
* Set the test task as the default Rake task.
|
65
75
|
|
66
|
-
|
76
|
+
## 1.1.3 - 14-Sep-2010
|
67
77
|
* Fixed potential libc linker failure.
|
68
78
|
|
69
|
-
|
79
|
+
## 1.1.2 - 28-Apr-2010
|
70
80
|
* Explicitly link against libc for Unix versions.
|
71
81
|
* Refactored the Rakefile. An old install task was removed and the gem
|
72
82
|
related tasks were placed under the 'gem' namespace.
|
73
83
|
|
74
|
-
|
84
|
+
## 1.1.1 - 24-Oct-2009
|
75
85
|
* Removed the 'use' library as a dependency.
|
76
86
|
|
77
|
-
|
87
|
+
## 1.1.0 - 21-Oct-2009
|
78
88
|
* Now pure Ruby, using FFI.
|
79
89
|
* Fixed RF Bug #26757 - FILE pointer leak. Thanks go to Eric Wong for the spot.
|
80
90
|
* Renamed and refactored the test file slightly.
|
81
91
|
* Updated the gemspec.
|
82
92
|
|
83
|
-
|
93
|
+
## 1.0.0 - 12-Apr-2008
|
84
94
|
* Added security via umask().
|
85
95
|
* Version bump to 1.0.0.
|
86
96
|
|
87
|
-
|
97
|
+
## 0.1.2 - 6-Jun-2007
|
88
98
|
* Gemspec fix (forgot the temp.h file - oops).
|
89
99
|
* Added an extra test.
|
90
100
|
|
91
|
-
|
101
|
+
## 0.1.1 - 2-Jun-2007
|
92
102
|
* Core code and test case now work properly on MS Windows.
|
93
103
|
* Now uses MS VC++ 8 functions when available (tmpfile_s, _sopen_s).
|
94
104
|
|
95
|
-
|
105
|
+
## 0.1.0 - 1-Jun-2007
|
96
106
|
* Initial release.
|
data/Gemfile
ADDED
data/{README.rdoc → README.md}
RENAMED
@@ -1,29 +1,36 @@
|
|
1
|
-
|
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
|
+
|
3
|
+
## Description
|
2
4
|
The file-temp library is an alternate way to handle tempfile generation.
|
3
5
|
|
4
|
-
|
6
|
+
## Requirements
|
5
7
|
* ffi 1.1.0 or later
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
## Installation
|
10
|
+
`gem install file-temp`
|
11
|
+
|
12
|
+
## Adding the trusted cert
|
13
|
+
`gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/file-temp/main/certs/djberg96_pub.pem)`
|
9
14
|
|
10
|
-
|
11
|
-
|
15
|
+
## Synopsis
|
16
|
+
```ruby
|
17
|
+
require 'file/temp'
|
12
18
|
|
13
|
-
|
14
|
-
|
15
|
-
|
19
|
+
fh = File::Temp.new
|
20
|
+
fh.puts "hello"
|
21
|
+
fh.close # => Tempfile automatically deleted
|
16
22
|
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
fh = File::Temp.new(delete: false)
|
24
|
+
fh.puts "world"
|
25
|
+
fh.close # => Tempfile still on your filesystem
|
26
|
+
```
|
20
27
|
|
21
|
-
|
28
|
+
## Motivation
|
22
29
|
Unlike the tempfile library that ships with Ruby's standard library, this
|
23
|
-
library uses your system's native
|
30
|
+
library uses your system's native `tmpfile` or `mkstemp` functions.
|
24
31
|
|
25
32
|
This library is also more secure because it restricts file permission via
|
26
|
-
|
33
|
+
`umask` for files created with `mkstemp`.
|
27
34
|
|
28
35
|
Finally, this library subclasses the File class. This means you get almost
|
29
36
|
exactly the same interface as the File class. The only difference is the
|
@@ -34,33 +41,37 @@ the tempfile library, but that was a very long time ago, and my assumption
|
|
34
41
|
at this point is that it's no longer true. But, I still prefer this version
|
35
42
|
to the one in the Ruby standard library.
|
36
43
|
|
37
|
-
|
44
|
+
## JRuby
|
38
45
|
The implementation for JRuby uses the Java API, not the C API. The
|
39
46
|
temporary file name generated by Java is different than the C version,
|
40
47
|
since it uses a GUID instead of the 'XXXXXX' template, but the
|
41
48
|
interface is otherwise identical.
|
42
49
|
|
43
|
-
|
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
|
+
|
54
|
+
## MS Windows
|
44
55
|
You may need to use the mingw build in order to use this library.
|
45
56
|
|
46
|
-
Also, there was a bug with the
|
47
|
-
of MS Windows that may cause a failure. However, if you'
|
57
|
+
Also, there was a bug with the `GetTempFileName` function on certain versions
|
58
|
+
of MS Windows that may cause a failure. However, if you're patched up you
|
48
59
|
should not see it.
|
49
60
|
|
50
|
-
|
61
|
+
## License
|
51
62
|
Apache-2.0
|
52
63
|
|
53
|
-
|
54
|
-
(C) 2007-
|
64
|
+
## Copyright
|
65
|
+
(C) 2007-2023 Daniel J. Berger
|
55
66
|
All Rights Reserved
|
56
67
|
|
57
|
-
|
68
|
+
## Warranty
|
58
69
|
This library is provided "as is" and without any express or
|
59
70
|
implied warranties, including, without limitation, the implied
|
60
71
|
warranties of merchantability and fitness for a particular purpose.
|
61
72
|
|
62
|
-
|
73
|
+
## Author
|
63
74
|
Daniel J. Berger
|
64
75
|
|
65
|
-
|
76
|
+
## See also
|
66
77
|
tmpfile(), mkstemp(), tmpnam()
|
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 =
|
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
|
15
|
+
Gem::Package.build(spec)
|
15
16
|
end
|
16
17
|
|
17
18
|
desc 'Install the file-temp gem'
|
@@ -21,6 +22,8 @@ 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
28
|
RSpec::Core::RakeTask.new(:spec)
|
26
29
|
|
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.2'
|
6
6
|
spec.author = 'Daniel J. Berger'
|
7
7
|
spec.license = 'Apache-2.0'
|
8
8
|
spec.email = 'djberg96@gmail.com'
|
@@ -12,19 +12,20 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.files = Dir['**/*'].delete_if{ |item| item.include?('git') }
|
13
13
|
spec.cert_chain = Dir['certs/*']
|
14
14
|
|
15
|
-
spec.extra_rdoc_files = ['CHANGES.rdoc', 'README.rdoc', 'MANIFEST.rdoc']
|
16
|
-
|
17
15
|
spec.add_dependency('ffi', '~> 1.1')
|
18
16
|
spec.add_development_dependency('rspec', '~> 3.9')
|
17
|
+
spec.add_development_dependency('rubocop')
|
18
|
+
spec.add_development_dependency('rubocop-rspec')
|
19
19
|
spec.add_development_dependency('rake')
|
20
20
|
|
21
21
|
spec.metadata = {
|
22
|
-
'homepage_uri'
|
23
|
-
'bug_tracker_uri'
|
24
|
-
'changelog_uri'
|
25
|
-
'documentation_uri'
|
26
|
-
'source_code_uri'
|
27
|
-
'wiki_uri'
|
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'
|
28
29
|
}
|
29
30
|
|
30
31
|
spec.description = <<-EOF
|
data/lib/file/java/temp.rb
CHANGED
@@ -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[
|
8
|
+
TMPDIR = java.lang.System.getProperties['java.io.tmpdir']
|
7
9
|
|
8
10
|
# The name of the temporary file.
|
9
11
|
attr_reader :path
|
@@ -31,7 +33,7 @@ class File::Temp < File
|
|
31
33
|
# fh.puts 'hello world'
|
32
34
|
# fh.close
|
33
35
|
#
|
34
|
-
def initialize(delete: true, template: 'rb_file_temp_XXXXXX', directory: TMPDIR, options
|
36
|
+
def initialize(delete: true, template: 'rb_file_temp_XXXXXX', directory: TMPDIR, **options)
|
35
37
|
raise TypeError unless template.is_a?(String)
|
36
38
|
|
37
39
|
# Since Java uses a GUID extension to generate a unique file name
|
@@ -42,7 +44,7 @@ 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
|
47
|
+
rescue NativeException
|
46
48
|
raise SystemCallError.new(22), template # 22 is EINVAL
|
47
49
|
end
|
48
50
|
|
@@ -50,7 +52,7 @@ class File::Temp < File
|
|
50
52
|
options[:mode] ||= 'wb+'
|
51
53
|
|
52
54
|
path = @file.getName
|
53
|
-
super(path, options)
|
55
|
+
super(path, **options)
|
54
56
|
|
55
57
|
@path = path unless delete
|
56
58
|
end
|
@@ -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
data/lib/file/unix/temp.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
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
|
@@ -51,7 +54,7 @@ class File::Temp < File
|
|
51
54
|
# fh.puts 'hello world'
|
52
55
|
# fh.close
|
53
56
|
#
|
54
|
-
def initialize(delete: true, template: 'rb_file_temp_XXXXXX', directory: TMPDIR, options
|
57
|
+
def initialize(delete: true, template: 'rb_file_temp_XXXXXX', directory: TMPDIR, **options)
|
55
58
|
@fptr = nil
|
56
59
|
|
57
60
|
if delete
|
@@ -77,9 +80,9 @@ class File::Temp < File
|
|
77
80
|
options[:mode] ||= 'wb+'
|
78
81
|
|
79
82
|
if delete
|
80
|
-
super(fd, options)
|
83
|
+
super(fd, **options)
|
81
84
|
else
|
82
|
-
super(@path, options)
|
85
|
+
super(@path, **options)
|
83
86
|
end
|
84
87
|
end
|
85
88
|
|
data/lib/file/windows/temp.rb
CHANGED
@@ -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, [
|
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, [
|
18
|
-
attach_function :_open_osfhandle, [
|
19
|
-
attach_function :tmpnam_s, [
|
20
|
-
attach_function :mktemp_s, :_mktemp_s, [
|
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, [
|
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, [
|
31
|
-
attach_function :GetTempFileNameW, [
|
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
|
@@ -81,7 +85,7 @@ class File::Temp < File
|
|
81
85
|
# fh.puts 'hello world'
|
82
86
|
# fh.close
|
83
87
|
#
|
84
|
-
def initialize(delete: true, template: 'rb_file_temp_XXXXXX', directory: TMPDIR, options
|
88
|
+
def initialize(delete: true, template: 'rb_file_temp_XXXXXX', directory: TMPDIR, **options)
|
85
89
|
@fptr = nil
|
86
90
|
|
87
91
|
if delete
|
@@ -105,9 +109,9 @@ class File::Temp < File
|
|
105
109
|
options[:mode] ||= 'wb+'
|
106
110
|
|
107
111
|
if delete
|
108
|
-
super(fd, options)
|
112
|
+
super(fd, **options)
|
109
113
|
else
|
110
|
-
super(@path, options)
|
114
|
+
super(@path, **options)
|
111
115
|
end
|
112
116
|
end
|
113
117
|
|
@@ -134,7 +138,7 @@ class File::Temp < File
|
|
134
138
|
|
135
139
|
raise SystemCallError.new('tmpnam_s', errno) if errno != 0
|
136
140
|
|
137
|
-
directory + ptr.read_string
|
141
|
+
directory + (ptr.read_string << 'tmp')
|
138
142
|
end
|
139
143
|
|
140
144
|
private
|
@@ -153,13 +157,12 @@ class File::Temp < File
|
|
153
157
|
#
|
154
158
|
def get_temp_path
|
155
159
|
buf = 0.chr * 1024
|
156
|
-
buf.encode!(
|
160
|
+
buf.encode!('UTF-16LE')
|
157
161
|
|
158
|
-
|
159
|
-
|
160
|
-
end
|
162
|
+
rv = GetTempPathW(buf.size, buf)
|
163
|
+
raise SystemCallError, FFI.errno, 'GetTempPathW' if rv == 0
|
161
164
|
|
162
|
-
buf
|
165
|
+
buf[0, rv+2] # Characters plus null terminator
|
163
166
|
end
|
164
167
|
|
165
168
|
# The version of tmpfile() implemented by Microsoft is unacceptable.
|
@@ -171,15 +174,16 @@ class File::Temp < File
|
|
171
174
|
# project.
|
172
175
|
#
|
173
176
|
def tmpfile
|
174
|
-
file_name = get_temp_path
|
177
|
+
file_name = get_temp_path
|
178
|
+
|
175
179
|
buf = 0.chr * 1024
|
176
|
-
buf.encode!(
|
180
|
+
buf.encode!('UTF-16LE')
|
177
181
|
|
178
|
-
if GetTempFileNameW(file_name, 'rb_', 0, buf) == 0
|
182
|
+
if GetTempFileNameW(file_name, String.new('rb_', encoding: 'UTF-16LE'), 0, buf) == 0
|
179
183
|
raise SystemCallError, FFI.errno, 'GetTempFileNameW'
|
180
184
|
end
|
181
185
|
|
182
|
-
file_name = buf.strip
|
186
|
+
file_name = buf.strip + "\000\000".encode('UTF-16LE')
|
183
187
|
|
184
188
|
handle = CreateFileW(
|
185
189
|
file_name,
|
data/lib/file-temp.rb
CHANGED
data/spec/file_temp_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
######################################################################
|
2
4
|
# file_temp_spec.rb
|
3
5
|
#
|
@@ -17,143 +19,149 @@ RSpec.describe File::Temp do
|
|
17
19
|
@fh = nil
|
18
20
|
|
19
21
|
# Because Dir[] doesn't work right with backslashes
|
20
|
-
@dir = @dir.tr(
|
22
|
+
@dir = @dir.tr('\\', '/') if windows
|
21
23
|
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
after do
|
26
|
+
@dir = nil
|
27
|
+
@template = nil
|
28
|
+
@fh.close if @fh && !@fh.closed?
|
29
|
+
@fh = nil
|
30
|
+
|
31
|
+
Dir['temp_*'].each{ |f| File.delete(f) }
|
32
|
+
Dir['rb_file_temp_*'].each{ |f| File.delete(f) }
|
33
|
+
|
34
|
+
Dir.chdir(File::Temp::TMPDIR) do
|
35
|
+
Dir['temp_*'].each{ |f| File.delete(f) }
|
36
|
+
Dir['rb_file_temp_*'].each{ |f| File.delete(f) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'constants' do
|
41
|
+
example 'library version is set to expected value' do
|
42
|
+
expect(File::Temp::VERSION).to eq('1.7.2')
|
26
43
|
expect(File::Temp::VERSION).to be_frozen
|
27
44
|
end
|
28
45
|
|
29
|
-
example
|
30
|
-
expect(File::Temp::TMPDIR).to
|
46
|
+
example 'TMPDIR constant is defined' do
|
47
|
+
expect(File::Temp::TMPDIR).to be_a(String)
|
31
48
|
expect(File::Temp::TMPDIR.size).to be > 0
|
32
49
|
end
|
33
50
|
end
|
34
51
|
|
35
|
-
context
|
36
|
-
example
|
52
|
+
context 'threads' do
|
53
|
+
example 'library works as expected with multiple threads' do
|
37
54
|
threads = []
|
38
|
-
expect{ 100.times{ threads << Thread.new{
|
39
|
-
expect{ threads.each
|
55
|
+
expect{ 100.times{ threads << Thread.new{ described_class.new } } }.not_to raise_error
|
56
|
+
expect{ threads.each(&:join) }.not_to raise_error
|
40
57
|
end
|
41
58
|
end
|
42
59
|
|
43
|
-
context
|
44
|
-
example
|
60
|
+
context 'constructor' do
|
61
|
+
example 'constructor works as expected with default auto delete option' do
|
45
62
|
expect{
|
46
|
-
@fh =
|
47
|
-
@fh.print
|
63
|
+
@fh = described_class.new
|
64
|
+
@fh.print 'hello'
|
48
65
|
@fh.close
|
49
66
|
}.not_to raise_error
|
50
67
|
end
|
51
68
|
|
52
|
-
example
|
69
|
+
example 'constructor works as expected with false auto delete option' do
|
53
70
|
expect{
|
54
|
-
@fh =
|
55
|
-
@fh.print
|
71
|
+
@fh = described_class.new(:delete => false)
|
72
|
+
@fh.print 'hello'
|
56
73
|
@fh.close
|
57
74
|
}.not_to raise_error
|
58
75
|
end
|
59
76
|
|
60
|
-
example
|
61
|
-
expect{
|
77
|
+
example 'constructor accepts and uses an optional template as expected' do
|
78
|
+
expect{ described_class.new(:delete => false, :template => 'temp_foo_XXXXXX').close }.not_to raise_error
|
62
79
|
expect(Dir["#{@dir}/temp_foo*"].length).to be >= 1
|
63
80
|
end
|
64
81
|
|
65
|
-
example
|
82
|
+
example 'constructor with false auto delete and block works as expected' do
|
66
83
|
expect{
|
67
|
-
|
84
|
+
described_class.open(:delete => false, :template => 'temp_foo_XXXXXX'){ |fh| fh.puts 'hello' }
|
68
85
|
}.not_to raise_error
|
69
86
|
expect(Dir["#{@dir}/temp_foo*"].length).to be >= 1
|
70
87
|
end
|
71
88
|
|
72
|
-
example
|
89
|
+
example 'other arguments are treated as file option arguments' do
|
73
90
|
expect{
|
74
|
-
@fh =
|
75
|
-
:delete
|
76
|
-
:template
|
77
|
-
:directory
|
78
|
-
:
|
91
|
+
@fh = described_class.new(
|
92
|
+
:delete => true,
|
93
|
+
:template => 'temp_bar_XXXXX',
|
94
|
+
:directory => Dir.pwd,
|
95
|
+
:mode => 'xb'
|
79
96
|
)
|
80
|
-
}.to raise_error(ArgumentError)
|
97
|
+
}.to raise_error(ArgumentError, /invalid.*?(access)?.*?mode/) # Truffleruby missing the word 'access'
|
81
98
|
end
|
82
99
|
end
|
83
100
|
|
84
|
-
context
|
85
|
-
example
|
86
|
-
expect{ @fh =
|
101
|
+
context 'template' do
|
102
|
+
example 'template argument must be a string' do
|
103
|
+
expect{ @fh = described_class.new(:delete => false, :template => 1) }.to raise_error(TypeError)
|
87
104
|
end
|
88
105
|
|
89
|
-
example
|
90
|
-
skip
|
91
|
-
expect{
|
106
|
+
example 'an error is raised if a custom template is invalid' do
|
107
|
+
skip 'skipped on OSX' if osx
|
108
|
+
expect{ described_class.new(:delete => false, :template => 'xx') }.to raise_error(Errno::EINVAL)
|
92
109
|
end
|
93
110
|
end
|
94
111
|
|
95
|
-
context
|
96
|
-
example
|
97
|
-
expect(
|
98
|
-
expect{
|
99
|
-
expect(
|
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
|
119
|
+
example 'temp_name returns expected value' do
|
103
120
|
if windows
|
104
|
-
expect(
|
121
|
+
expect(File.extname(described_class.temp_name)).to match(/^.*?\d*?tmp/)
|
105
122
|
else
|
106
|
-
expect(
|
123
|
+
expect(File.extname(described_class.temp_name)).to eq('.tmp')
|
107
124
|
end
|
108
125
|
end
|
109
126
|
end
|
110
127
|
|
111
|
-
context
|
112
|
-
example
|
113
|
-
@fh =
|
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
|
118
|
-
@fh =
|
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
|
123
|
-
@fh =
|
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
|
129
|
-
|
130
|
-
methods =
|
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
|
-
|
152
|
-
|
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
|
-
|
155
|
-
|
156
|
-
|
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,11 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain:
|
11
11
|
- |
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
|
36
36
|
WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2023-07-11 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: ffi
|
@@ -65,6 +65,34 @@ dependencies:
|
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '3.9'
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: rubocop
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: rubocop-rspec
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
68
96
|
- !ruby/object:Gem::Dependency
|
69
97
|
name: rake
|
70
98
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,42 +114,34 @@ description: |2
|
|
86
114
|
email: djberg96@gmail.com
|
87
115
|
executables: []
|
88
116
|
extensions: []
|
89
|
-
extra_rdoc_files:
|
90
|
-
- CHANGES.rdoc
|
91
|
-
- README.rdoc
|
92
|
-
- MANIFEST.rdoc
|
117
|
+
extra_rdoc_files: []
|
93
118
|
files:
|
119
|
+
- CHANGES.md
|
120
|
+
- Gemfile
|
94
121
|
- LICENSE
|
95
|
-
-
|
96
|
-
-
|
97
|
-
- spec/file_temp_spec.rb
|
122
|
+
- MANIFEST.md
|
123
|
+
- README.md
|
98
124
|
- Rakefile
|
99
|
-
- certs
|
100
125
|
- certs/djberg96_pub.pem
|
101
|
-
-
|
126
|
+
- file-temp.gemspec
|
102
127
|
- lib/file-temp.rb
|
103
|
-
- lib/file
|
104
|
-
- lib/file/temp.rb
|
105
|
-
- lib/file/java
|
106
128
|
- lib/file/java/temp.rb
|
107
|
-
- lib/file/
|
129
|
+
- lib/file/temp.rb
|
108
130
|
- lib/file/unix/temp.rb
|
109
|
-
- lib/file/windows
|
110
131
|
- lib/file/windows/temp.rb
|
111
|
-
-
|
112
|
-
- MANIFEST.rdoc
|
113
|
-
- README.rdoc
|
132
|
+
- spec/file_temp_spec.rb
|
114
133
|
homepage: http://github.com/djberg96/file-temp
|
115
134
|
licenses:
|
116
135
|
- Apache-2.0
|
117
136
|
metadata:
|
118
137
|
homepage_uri: https://github.com/djberg96/file-temp
|
119
138
|
bug_tracker_uri: https://github.com/djberg96/file-temp/issues
|
120
|
-
changelog_uri: https://github.com/djberg96/file-temp/blob/
|
139
|
+
changelog_uri: https://github.com/djberg96/file-temp/blob/main/CHANGES.md
|
121
140
|
documentation_uri: https://github.com/djberg96/file-temp/wiki
|
122
141
|
source_code_uri: https://github.com/djberg96/file-temp
|
123
142
|
wiki_uri: https://github.com/djberg96/file-temp/wiki
|
124
|
-
|
143
|
+
rubygems_mfa_required: 'true'
|
144
|
+
post_install_message:
|
125
145
|
rdoc_options: []
|
126
146
|
require_paths:
|
127
147
|
- lib
|
@@ -136,8 +156,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
156
|
- !ruby/object:Gem::Version
|
137
157
|
version: '0'
|
138
158
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
140
|
-
signing_key:
|
159
|
+
rubygems_version: 3.3.26
|
160
|
+
signing_key:
|
141
161
|
specification_version: 4
|
142
162
|
summary: An alternative way to generate temp files
|
143
163
|
test_files:
|
metadata.gz.sig
CHANGED
Binary file
|