win32-file 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe733f3c66c36ad77e79b95f169dbfbea6d495d0
4
- data.tar.gz: fc11dce1680290901e70b7423e63a361cf5e0118
3
+ metadata.gz: 047468a1a793c4485f3e336084cbdab03ec973ee
4
+ data.tar.gz: f2cab49afe63c66b94995e83c0dcf7374ba52efa
5
5
  SHA512:
6
- metadata.gz: 062129c39980b67de8373c48dcdbd612d6001fd7afd49e74c19bdf06f3779a8ea1d5658da4c3fb5b931a04dcfa00447b2de64711d76fee31aea250fbb1f41919
7
- data.tar.gz: 0035f29a6657abf5535498e77a38acdf106133f922134ec164c14dad5b3b5f9d2e7550cff363ac5a2e470e93b501822e589d6d2c1718715ef902c8ea2fe52fff
6
+ metadata.gz: eae986e7739d2fc6307f2ded1c1349ae1e0590248f01c98456f368215f93ba4499c358bc80986f3f80e2e83f0e62693f81565e795af1b9f71880ae965c751218
7
+ data.tar.gz: 04634af88ef4466e08e8506e3c661d3afabb7fe31cf42c34f22b7ef121b9d3b07c565ba1964e079448300f5c6fecc0231de5649a5500b362c75709b8bfd76e42
data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.7.1 - 28-Apr-2014
2
+ * Modified all custom singleton methods to accept arguments that define either
3
+ to_str or to_path to be in line with MRI's behavior.
4
+ * Some internal changes for the long_path and short_path methods.
5
+ * Added some path tests.
6
+
1
7
  == 0.7.0 - 16-Dec-2013
2
8
  * Now requires Ruby 1.9 or later.
3
9
  * Converted to use FFI instead of win32-api. Now works with JRuby, too.
data/README CHANGED
@@ -22,7 +22,7 @@
22
22
  * File.short_path
23
23
 
24
24
  == Singleton Methods Redefined
25
- * File.basename # UNC path issues in MRI
25
+ * File.basename # UNC path issues, root path differences.
26
26
  * File.blksize # Not implemented in MRI
27
27
  * File.blockdev? # Not implemented in MRI
28
28
  * File.chardev? # Not implemented in MRI
@@ -55,15 +55,11 @@
55
55
 
56
56
  https://github.com/djberg96/win32-file/issues
57
57
 
58
- Or the Win32Utils project page at:
59
-
60
- http://www.rubyforge.org/projects/win32utils.
61
-
62
58
  == License
63
59
  Artistic 2.0
64
60
 
65
61
  == Copyright
66
- (C) 2003-2013, Daniel J. Berger, All Rights Reserved
62
+ (C) 2003-2014, Daniel J. Berger, All Rights Reserved
67
63
 
68
64
  == Warranty
69
65
  This package is provided "as is" and without any express or
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(__FILE__), 'file', 'constants')
2
- require File.join(File.dirname(__FILE__), 'file', 'structs')
3
- require File.join(File.dirname(__FILE__), 'file', 'functions')
1
+ require_relative 'file/constants'
2
+ require_relative 'file/structs'
3
+ require_relative 'file/functions'
4
4
  require 'win32/file/stat'
5
5
 
6
6
  class File
@@ -9,7 +9,7 @@ class File
9
9
  extend Windows::File::Functions
10
10
 
11
11
  # The version of the win32-file library
12
- WIN32_FILE_VERSION = '0.7.0'
12
+ WIN32_FILE_VERSION = '0.7.1'
13
13
 
14
14
  class << self
15
15
  alias_method :join_orig, :join
@@ -36,7 +36,8 @@ class File
36
36
  #
37
37
  # This was reimplemented because the current version does not handle UNC
38
38
  # paths properly, i.e. it should not return anything less than the root.
39
- # In most other respects it is identical to the current implementation.
39
+ # In most other respects it is identical to the current implementation,
40
+ # except that it does not strip the drive letter on a root path.
40
41
  #
41
42
  # Unlike MRI, this version will convert all forward slashes to
42
43
  # backslashes automatically.
@@ -48,8 +49,8 @@ class File
48
49
  # File.basename("\\\\foo\\bar") -> "\\\\foo\\bar"
49
50
  #
50
51
  def self.basename(file, suffix = nil)
51
- raise TypeError unless file.is_a?(String)
52
- raise TypeError unless suffix.is_a?(String) if suffix
52
+ file = string_check(file)
53
+ suffix = string_check(suffix) if suffix
53
54
 
54
55
  return file if file.empty? # Return an empty path as-is.
55
56
 
@@ -99,7 +100,7 @@ class File
99
100
  # File.dirname("\\\\foo\\bar") -> "\\\\foo\\bar"
100
101
  #
101
102
  def self.dirname(file)
102
- raise TypeError unless file.is_a?(String)
103
+ file = string_check(file)
103
104
 
104
105
  # Short circuit for empty paths
105
106
  return '.' if file.empty?
@@ -160,6 +161,7 @@ class File
160
161
  # the current version does not handle UNC paths properly.
161
162
  #
162
163
  def self.split(file)
164
+ file = string_check(file)
163
165
  array = []
164
166
 
165
167
  if file.empty? || PathIsRootW(file.wincode)
@@ -180,28 +182,32 @@ class File
180
182
  # name in 8.3 format.
181
183
  #
182
184
  def self.long_path(file)
183
- buffer = 0.chr * 1024
184
- wfile = file.wincode
185
+ buffer = FFI::Buffer.new(:wint_t, 1024, true)
186
+ wfile = string_check(file).wincode
185
187
 
186
- if GetLongPathNameW(wfile, buffer, buffer.size/2) == 0
188
+ length = GetLongPathNameW(wfile, buffer, buffer.size)
189
+
190
+ if length == 0 || length > buffer.size / 2
187
191
  raise SystemCallError.new('GetLongPathName', FFI.errno)
188
192
  end
189
193
 
190
- buffer.wstrip
194
+ buffer.read_bytes(length * 2).wstrip
191
195
  end
192
196
 
193
197
  # Returns +path+ in 8.3 format. For example, 'c:\documentation.doc'
194
198
  # would be returned as 'c:\docume~1.doc'.
195
199
  #
196
200
  def self.short_path(file)
197
- buffer = 0.chr * 1024
198
- wfile = file.wincode
201
+ buffer = FFI::Buffer.new(:wint_t, 1024, true)
202
+ wfile = string_check(file).wincode
203
+
204
+ length = GetShortPathNameW(wfile, buffer, buffer.size)
199
205
 
200
- if GetShortPathNameW(wfile, buffer, buffer.size/2) == 0
206
+ if length == 0 || length > buffer.size / 2
201
207
  raise SystemCallError.new('GetShortPathName', FFI.errno)
202
208
  end
203
209
 
204
- buffer.wstrip
210
+ buffer.read_bytes(length * 2).wstrip
205
211
  end
206
212
 
207
213
  # Creates a symbolic link called +new_name+ for the file or directory
@@ -211,8 +217,8 @@ class File
211
217
  # returns nil as per MRI.
212
218
  #
213
219
  def self.symlink(target, link)
214
- raise TypeError unless target.is_a?(String)
215
- raise TypeError unless link.is_a?(String)
220
+ target = string_check(target)
221
+ link = string_check(link)
216
222
 
217
223
  flags = File.directory?(target) ? 1 : 0
218
224
 
@@ -230,8 +236,9 @@ class File
230
236
  #
231
237
  def self.symlink?(file)
232
238
  return false unless File.exists?(file)
239
+
233
240
  bool = false
234
- wfile = file.wincode
241
+ wfile = string_check(file).wincode
235
242
 
236
243
  attrib = GetFileAttributesW(wfile)
237
244
 
@@ -269,6 +276,8 @@ class File
269
276
  # On Windows we only modify the realpath method if the file is a symlink.
270
277
  #
271
278
  def self.realdirpath(file, relative_to = nil)
279
+ file = string_check(file)
280
+
272
281
  if symlink?(file)
273
282
  if relative_to
274
283
  File.join(relative_to, File.basename(readlink(file)))
@@ -287,6 +296,9 @@ class File
287
296
  # On Windows we only modify the realpath method if the file is a symlink.
288
297
  #
289
298
  def self.realpath(file, relative_to = nil)
299
+ file = string_check(file)
300
+ relative_to = string_check(relative_to) if relative_to
301
+
290
302
  if symlink?(file)
291
303
  if relative_to
292
304
  result = File.join(relative_to, File.basename(readlink(file)))
@@ -306,6 +318,8 @@ class File
306
318
  # Returns the path of the of the symbolic link referred to by +file+.
307
319
  #
308
320
  def self.readlink(file)
321
+ file = string_check(file)
322
+
309
323
  if exists?(file) && !symlink?(file)
310
324
  raise SystemCallError.new(22) # EINVAL, match the spec
311
325
  end
@@ -480,10 +494,17 @@ class File
480
494
  def stat
481
495
  File::Stat.new(self.path)
482
496
  end
483
- end
484
497
 
485
- if $0 == __FILE__
486
- p File.dirname("C:/Users/djberge/test.txt////")
487
- p File.basename("C:/Users/djberge/test.txt")
488
- p File.basename("C:/Users/djberge/test.txt", ".txt")
498
+ # Private singleton methods
499
+ class << self
500
+ private
501
+
502
+ # Simulate Ruby's string checking
503
+ def string_check(arg)
504
+ return arg if arg.is_a?(String)
505
+ return arg.send(:to_str) if arg.respond_to?(:to_str, true) # MRI allows private to_str
506
+ return arg.to_path if arg.respond_to?(:to_path)
507
+ raise TypeError
508
+ end
509
+ end
489
510
  end
@@ -1,16 +1,16 @@
1
- ########################################################################
2
- # Miscellaneous tests for win32-file that didn't fit anywhere else.
3
- ########################################################################
4
- require 'win32/file'
5
- require 'test-unit'
6
-
7
- class TC_Win32_File_Misc < Test::Unit::TestCase
8
- test "version constant is set to expected value" do
9
- assert_equal('0.7.0', File::WIN32_FILE_VERSION)
10
- end
11
-
12
- test "ffi functions are private" do
13
- assert_not_respond_to(File, :CloseHandle)
14
- assert_not_respond_to(File, :CreateFileW)
15
- end
16
- end
1
+ ########################################################################
2
+ # Miscellaneous tests for win32-file that didn't fit anywhere else.
3
+ ########################################################################
4
+ require 'win32/file'
5
+ require 'test-unit'
6
+
7
+ class TC_Win32_File_Misc < Test::Unit::TestCase
8
+ test "version constant is set to expected value" do
9
+ assert_equal('0.7.1', File::WIN32_FILE_VERSION)
10
+ end
11
+
12
+ test "ffi functions are private" do
13
+ assert_not_respond_to(File, :CloseHandle)
14
+ assert_not_respond_to(File, :CreateFileW)
15
+ end
16
+ end
@@ -6,6 +6,7 @@
6
6
  #############################################################################
7
7
  require 'test-unit'
8
8
  require 'win32/file'
9
+ require 'pathname'
9
10
 
10
11
  class TC_Win32_File_Path < Test::Unit::TestCase
11
12
  def self.startup
@@ -97,6 +98,11 @@ class TC_Win32_File_Path < Test::Unit::TestCase
97
98
  assert_equal("foo.txt", File.basename("foo.txt\\\\\\"))
98
99
  end
99
100
 
101
+ test "basename method handles arguments that honor to_str or to_path" do
102
+ assert_equal("foo.txt", File.basename(Pathname.new("C:/blah/blah/foo.txt")))
103
+ assert_equal("foo", File.basename(Pathname.new("C:/blah/blah/foo.txt"), Pathname.new(".*")))
104
+ end
105
+
100
106
  test "dirname basic functionality" do
101
107
  assert_respond_to(File, :dirname)
102
108
  assert_nothing_raised{ File.dirname("C:\\foo") }
@@ -158,11 +164,15 @@ class TC_Win32_File_Path < Test::Unit::TestCase
158
164
  assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar\\baz\\"))
159
165
  end
160
166
 
161
- test "argument to dirname must be a string" do
167
+ test "argument to dirname must be a stringy object" do
162
168
  assert_raises(TypeError){ File.dirname(nil) }
163
169
  assert_raises(TypeError){ File.dirname(['foo', 'bar']) }
164
170
  end
165
171
 
172
+ test "dirname method handles arguments that honor to_str or to_path" do
173
+ assert_equal("C:\\blah\\blah", File.dirname(Pathname.new("C:/blah/blah/foo.txt")))
174
+ end
175
+
166
176
  test "split method basic functionality" do
167
177
  assert_respond_to(File, :split)
168
178
  assert_nothing_raised{ File.split("C:\\foo\\bar") }
@@ -203,6 +213,15 @@ class TC_Win32_File_Path < Test::Unit::TestCase
203
213
  assert_equal("C:\\foo\\bar", path)
204
214
  end
205
215
 
216
+ test "split method accepts stringy arguments" do
217
+ assert_equal(["C:\\foo", "bar"], File.split(Pathname.new("C:/foo/bar")))
218
+ end
219
+
220
+ test "split requires a stringy argument or a TypeError is raised" do
221
+ assert_raise(TypeError){ File.split(nil) }
222
+ assert_raise(TypeError){ File.split([]) }
223
+ end
224
+
206
225
  test "File.long_path basic functionality" do
207
226
  assert_respond_to(File, :long_path)
208
227
  assert_nothing_raised{ File.long_path(@short_file) }
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'win32-file'
5
- spec.version = '0.7.0'
5
+ spec.version = '0.7.1'
6
6
  spec.authors = ['Daniel J. Berger', 'Park Heesob']
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-file
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-16 00:00:00.000000000 Z
12
+ date: 2014-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -96,13 +96,13 @@ extra_rdoc_files:
96
96
  - MANIFEST
97
97
  files:
98
98
  - CHANGES
99
+ - MANIFEST
100
+ - README
101
+ - Rakefile
102
+ - lib/win32/file.rb
99
103
  - lib/win32/file/constants.rb
100
104
  - lib/win32/file/functions.rb
101
105
  - lib/win32/file/structs.rb
102
- - lib/win32/file.rb
103
- - MANIFEST
104
- - Rakefile
105
- - README
106
106
  - test/test_win32_file_link.rb
107
107
  - test/test_win32_file_misc.rb
108
108
  - test/test_win32_file_path.rb
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  requirements: []
130
130
  rubyforge_project: win32utils
131
- rubygems_version: 2.0.3
131
+ rubygems_version: 2.2.2
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: Extra or redefined methods for the File class on Windows.