file-temp 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ = 1.1.5 - 17-Jul-2011
2
+ * Now stores file path information if the file is retained on the filesystem.
3
+ Thanks go to joerixaop for the patch.
4
+ * The TMPDIR fallback determination on Windows is no longer hard coded.
5
+
1
6
  = 1.1.4 - 16-Sep-2010
2
7
  * The File::Temp.temp_name method has been altered on Unix systems. It
3
8
  no longer prefixes TMPDIR to the name since it was redundant and could
data/Rakefile CHANGED
@@ -1,14 +1,9 @@
1
1
  require 'rake'
2
+ require 'rake/clean'
2
3
  require 'rake/testtask'
3
4
 
4
- desc 'Remove all gem and archive files from the project'
5
- task :clean do
6
- Dir['*.gem'].each{ |f| File.delete(f) }
7
- Dir['*.tar'].each{ |f| File.delete(f) }
8
- Dir['*.zip'].each{ |f| File.delete(f) }
9
- Dir['*.gz'].each{ |f| File.delete(f) }
10
- Dir['*.bz2'].each{ |f| File.delete(f) }
11
- end
5
+ CLEAN.include('**/*.tar', '**/*.zip', '**/*.gz', '**/*.bz2')
6
+ CLEAN.include('**/*.rbc', '**/*.gem')
12
7
 
13
8
  namespace 'gem' do
14
9
  desc 'Create the file-temp gem'
@@ -2,14 +2,13 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'file-temp'
5
- spec.version = '1.1.4'
5
+ spec.version = '1.1.5'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
9
9
  spec.homepage = 'http://www.rubyforge.org/projects/shards'
10
10
  spec.summary = 'An alternative way to generate temp files'
11
11
  spec.test_file = 'test/test_file_temp.rb'
12
- spec.has_rdoc = true
13
12
  spec.files = Dir['**/*'].delete_if{ |item| item.include?('git') }
14
13
 
15
14
  spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
@@ -17,7 +16,7 @@ Gem::Specification.new do |spec|
17
16
  spec.required_ruby_version = '>= 1.8.6'
18
17
 
19
18
  spec.add_dependency('ffi', '>= 0.5.0')
20
- spec.add_development_dependency('test-unit', '>= 2.0.3')
19
+ spec.add_development_dependency('test-unit', '>= 2.2.0')
21
20
 
22
21
  spec.description = <<-EOF
23
22
  The file-temp library provides an alternative approach to generating
@@ -9,7 +9,7 @@ class File::Temp < File
9
9
  private
10
10
 
11
11
  # True if operating system is MS Windows
12
- WINDOWS = Config::CONFIG['host_os'] =~ /mswin|win32|dos|cygwin|mingw/i
12
+ WINDOWS = Config::CONFIG['host_os'] =~ /mswin|win32|dos|cygwin|mingw|windows/i
13
13
 
14
14
  if WINDOWS
15
15
  ffi_lib 'msvcrt'
@@ -59,17 +59,19 @@ class File::Temp < File
59
59
  # :startdoc:
60
60
 
61
61
  # The version of the file-temp library.
62
- VERSION = '1.1.4'
62
+ VERSION = '1.1.5'
63
63
 
64
64
  if WINDOWS
65
65
  # The temporary directory used on MS Windows.
66
- TMPDIR = ENV['TEMP'] || ENV['TMP'] || ENV['USERPROFILE'] || "C:\\Windows\\Temp"
66
+ TMPDIR = ENV['TEMP'] || ENV['TMP'] || ENV['USERPROFILE'] || get_temp_path()
67
67
  else
68
68
  # The temporary directory used on Unix.
69
69
  TMPDIR = ENV['TEMP'] || ENV['TMP'] || ENV['TMPDIR'] || '/tmp'
70
70
  end
71
71
 
72
- public
72
+ # The name of the file. This is only retained if the first argument to the
73
+ # constructor is false.
74
+ attr_reader :path
73
75
 
74
76
  # Creates a new, anonymous, temporary file in your File::Temp::TMPDIR
75
77
  # directory
@@ -87,7 +89,7 @@ class File::Temp < File
87
89
  # The +template+ argument is ignored if the +delete+ argument is true.
88
90
  #
89
91
  # Example:
90
- #
92
+ #
91
93
  # fh = File::Temp.new(true, 'rb_file_temp_XXXXXX') => file
92
94
  # fh.puts 'hello world'
93
95
  # fh.close
@@ -106,7 +108,10 @@ class File::Temp < File
106
108
  else
107
109
  omask = umask(077)
108
110
  end
109
- fd = mkstemp(File.join(TMPDIR, template))
111
+
112
+ @path = File.join(TMPDIR, template)
113
+ fd = mkstemp(@path)
114
+
110
115
  raise SystemCallError, 'mkstemp()' if fd < 0
111
116
  ensure
112
117
  WINDOWS ? _umask(omask) : umask(omask)
@@ -140,22 +145,26 @@ class File::Temp < File
140
145
  private
141
146
 
142
147
  if WINDOWS
148
+ def get_temp_path
149
+ buf = 1.chr * 1024
150
+
151
+ if GetTempPathA(buf.length, buf) == 0
152
+ raise SystemCallError, 'GetTempPath()'
153
+ end
154
+
155
+ buf[ /^[^\0]*/ ].chop # remove trailing slash
156
+ end
157
+
143
158
  # The version of tmpfile() implemented by Microsoft is unacceptable.
144
- # It attempts to write to C:\ (root) instead of a temporary directory.
159
+ # It attempts to write to C:\ (root) instead of a temporary directory.
145
160
  # This is not only bad behavior, it won't work on Windows 7 and later
146
161
  # without admin rights due to security restrictions.
147
- #
162
+ #
148
163
  # This is a custom implementation based on some code from the Cairo
149
164
  # project.
150
165
  #
151
166
  def tmpfile
152
- buf = 1.chr * 1024
153
-
154
- if GetTempPathA(buf.length, buf) == 0
155
- raise SystemCallError, 'GetTempPath()'
156
- end
157
-
158
- file_name = buf[ /^[^\0]*/ ].chop # remove trailing slash
167
+ file_name = get_temp_path()
159
168
  buf = 1.chr * 1024
160
169
 
161
170
  if GetTempFileNameA(file_name, 'rb_', 0, buf) == 0
@@ -204,9 +213,9 @@ class File::Temp < File
204
213
  pmode = S_IREAD | S_IWRITE
205
214
 
206
215
  fd = _open(template, flags, pmode)
207
-
216
+
208
217
  raise SystemCallError, 'mkstemp()' if fd < 0
209
-
218
+
210
219
  fd
211
220
  end
212
221
  end
@@ -11,18 +11,20 @@ require 'test/unit'
11
11
  require 'file/temp'
12
12
  require 'rbconfig'
13
13
 
14
- class TC_File_Temp < Test::Unit::TestCase
14
+ class TC_File_Temp < Test::Unit::TestCase
15
+ WINDOWS = Config::CONFIG['host_os'] =~ /mswin|win32|msdos|cygwin|mingw|windows/i
16
+
15
17
  def setup
16
18
  @dir = File::Temp::TMPDIR
17
19
  @template = 'file-temp-test-XXXXX'
18
20
  @fh = nil
19
21
 
20
22
  # Because Dir[] doesn't work right with backslashes
21
- @dir = @dir.tr("\\", "/") if Config::CONFIG['host_os'] =~ /mswin|win32|msdos|cygwin|mingw/i
23
+ @dir = @dir.tr("\\", "/") if WINDOWS
22
24
  end
23
25
 
24
26
  def test_file_temp_version
25
- assert_equal('1.1.4', File::Temp::VERSION)
27
+ assert_equal('1.1.5', File::Temp::VERSION)
26
28
  end
27
29
 
28
30
  def test_file_temp_threaded
@@ -74,6 +76,21 @@ class TC_File_Temp < Test::Unit::TestCase
74
76
  assert_equal('.tmp', File.extname(File::Temp.temp_name))
75
77
  end
76
78
 
79
+ def test_file_temp_path_basic_functionality
80
+ temp = File::Temp.new
81
+ assert_respond_to(temp, :path)
82
+ end
83
+
84
+ def test_file_temp_path_is_nil_if_delete_option_is_true
85
+ temp = File::Temp.new
86
+ assert_nil(temp.path)
87
+ end
88
+
89
+ def test_file_temp_path_is_not_nil_if_delete_option_is_false
90
+ temp = File::Temp.new(false)
91
+ assert_not_nil(temp.path)
92
+ end
93
+
77
94
  def teardown
78
95
  @dir = nil
79
96
  @template = nil
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file-temp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
4
+ hash: 25
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 4
10
- version: 1.1.4
9
+ - 5
10
+ version: 1.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel J. Berger
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-16 00:00:00 -06:00
19
- default_executable:
18
+ date: 2011-07-17 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: ffi
@@ -42,12 +41,12 @@ dependencies:
42
41
  requirements:
43
42
  - - ">="
44
43
  - !ruby/object:Gem::Version
45
- hash: 9
44
+ hash: 7
46
45
  segments:
47
46
  - 2
47
+ - 2
48
48
  - 0
49
- - 3
50
- version: 2.0.3
49
+ version: 2.2.0
51
50
  type: :development
52
51
  version_requirements: *id002
53
52
  description: " The file-temp library provides an alternative approach to generating\n temporary files. Features included improved security, a superior\n interface, and better support for MS Windows.\n"
@@ -68,7 +67,6 @@ files:
68
67
  - Rakefile
69
68
  - README
70
69
  - test/test_file_temp.rb
71
- has_rdoc: true
72
70
  homepage: http://www.rubyforge.org/projects/shards
73
71
  licenses:
74
72
  - Artistic 2.0
@@ -100,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
98
  requirements: []
101
99
 
102
100
  rubyforge_project: shards
103
- rubygems_version: 1.3.7
101
+ rubygems_version: 1.8.3
104
102
  signing_key:
105
103
  specification_version: 3
106
104
  summary: An alternative way to generate temp files