win32-dir 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ba7a9adc26183f9771184c4faad59d88fbc5bd22
4
+ data.tar.gz: 62e1d08549b6806816874e5299600394f9ebf5e3
5
+ SHA512:
6
+ metadata.gz: 7e388fc8eff13cf9cf188e82bdab4a7d4ee6164910daaa61889baebd69bc0269d0973a1d6d8bff4b993d33975071ffc73d358dbfd54e125a366e9bd5bf1ba7bd
7
+ data.tar.gz: b2fcfbe2d31741398df8cb55220f8256af771247dbb4bcaf7564e3c0bdbeceba50f4578e71cb46a0aced31380456ba3281bb9c4dfb7a66f814c797d9630cc371
data/CHANGES CHANGED
@@ -1,3 +1,11 @@
1
+ == 0.4.3 - 24-Jul-2013
2
+ * Changed the Dir.read_junction and CSIDL constant strings so that they
3
+ use the default external encoding instead of UTF-16LE. This means that
4
+ they will now work with methods like File.join. Thanks go to Josh Cooper
5
+ for the patches.
6
+ * Some changes for internal handling of making FFI functions private.
7
+ * Updated gem:create task for rubygems 2.
8
+
1
9
  == 0.4.2 - 8-Apr-2013
2
10
  * Fixed the HANDLE function prototypes in the underlying FFI code and added
3
11
  some custom typedefs for convenience. This affects 64 bit Ruby code.
data/Rakefile CHANGED
@@ -6,10 +6,16 @@ CLEAN.include('**/*.gem', '**/*.log')
6
6
 
7
7
  namespace 'gem' do
8
8
  desc "Create the win32-dir gem"
9
- task :build => [:clean] do
9
+ task :create => [:clean] do
10
10
  Dir["*.gem"].each{ |f| File.delete(f) }
11
11
  spec = eval(IO.read('win32-dir.gemspec'))
12
- Gem::Builder.new(spec).build
12
+
13
+ if Gem::VERSION.to_f < 2.0
14
+ Gem::Builder.new(spec).build
15
+ else
16
+ require 'rubygems/package'
17
+ Gem::Package.build(spec)
18
+ end
13
19
  end
14
20
 
15
21
  desc "Install the win32-dir gem"
@@ -7,6 +7,14 @@ end
7
7
  require 'ffi'
8
8
 
9
9
  module Dir::Functions
10
+ module FFI::Library
11
+ # Wrapper method for attach_function + private
12
+ def attach_pfunc(*args)
13
+ attach_function(*args)
14
+ private args[0]
15
+ end
16
+ end
17
+
10
18
  extend FFI::Library
11
19
 
12
20
  typedef :ulong, :dword
@@ -16,27 +24,27 @@ module Dir::Functions
16
24
 
17
25
  ffi_lib :shell32
18
26
 
19
- attach_function :SHGetFolderPathW, [:hwnd, :int, :handle, :dword, :buffer_out], :dword
20
- attach_function :SHGetFolderLocation, [:hwnd, :int, :handle, :dword, :ptr], :dword
21
- attach_function :SHGetFileInfo, [:dword, :dword, :ptr, :uint, :uint], :dword
27
+ attach_pfunc :SHGetFolderPathW, [:hwnd, :int, :handle, :dword, :buffer_out], :dword
28
+ attach_pfunc :SHGetFolderLocation, [:hwnd, :int, :handle, :dword, :ptr], :dword
29
+ attach_pfunc :SHGetFileInfo, [:dword, :dword, :ptr, :uint, :uint], :dword
22
30
 
23
31
  ffi_lib :shlwapi
24
32
 
25
- attach_function :PathIsDirectoryEmptyW, [:buffer_in], :bool
33
+ attach_pfunc :PathIsDirectoryEmptyW, [:buffer_in], :bool
26
34
 
27
35
  ffi_lib :kernel32
28
36
 
29
- attach_function :CloseHandle, [:handle], :bool
30
- attach_function :CreateDirectoryW, [:buffer_in, :ptr], :bool
31
- attach_function :CreateFileW, [:buffer_in, :dword, :dword, :ptr, :dword, :dword, :handle], :handle
32
- attach_function :DeviceIoControl, [:handle, :dword, :ptr, :dword, :ptr, :dword, :ptr, :ptr], :bool
33
- attach_function :GetCurrentDirectoryW, [:dword, :buffer_out], :dword
34
- attach_function :GetFileAttributesW, [:buffer_in], :dword
35
- attach_function :GetLastError, [], :dword
36
- attach_function :GetShortPathNameW, [:buffer_in, :buffer_out, :dword], :dword
37
- attach_function :GetLongPathNameW, [:buffer_in, :buffer_out, :dword], :dword
38
- attach_function :GetFullPathNameW, [:buffer_in, :dword, :buffer_out, :ptr], :dword
39
- attach_function :RemoveDirectoryW, [:buffer_in], :bool
37
+ attach_pfunc :CloseHandle, [:handle], :bool
38
+ attach_pfunc :CreateDirectoryW, [:buffer_in, :ptr], :bool
39
+ attach_pfunc :CreateFileW, [:buffer_in, :dword, :dword, :ptr, :dword, :dword, :handle], :handle
40
+ attach_pfunc :DeviceIoControl, [:handle, :dword, :ptr, :dword, :ptr, :dword, :ptr, :ptr], :bool
41
+ attach_pfunc :GetCurrentDirectoryW, [:dword, :buffer_out], :dword
42
+ attach_pfunc :GetFileAttributesW, [:buffer_in], :dword
43
+ attach_pfunc :GetLastError, [], :dword
44
+ attach_pfunc :GetShortPathNameW, [:buffer_in, :buffer_out, :dword], :dword
45
+ attach_pfunc :GetLongPathNameW, [:buffer_in, :buffer_out, :dword], :dword
46
+ attach_pfunc :GetFullPathNameW, [:buffer_in, :dword, :buffer_out, :ptr], :dword
47
+ attach_pfunc :RemoveDirectoryW, [:buffer_in], :bool
40
48
  end
41
49
 
42
50
  class String
data/lib/win32/dir.rb CHANGED
@@ -7,26 +7,8 @@ class Dir
7
7
  include Dir::Constants
8
8
  extend Dir::Functions
9
9
 
10
- private_class_method(
11
- :SHGetFolderPathW,
12
- :SHGetFolderLocation,
13
- :SHGetFileInfo,
14
- :PathIsDirectoryEmptyW,
15
- :CloseHandle,
16
- :CreateDirectoryW,
17
- :CreateFileW,
18
- :DeviceIoControl,
19
- :GetCurrentDirectoryW,
20
- :GetFileAttributesW,
21
- :GetLastError,
22
- :GetShortPathNameW,
23
- :GetLongPathNameW,
24
- :GetFullPathNameW,
25
- :RemoveDirectoryW
26
- )
27
-
28
10
  # The version of the win32-dir library.
29
- VERSION = '0.4.2'
11
+ VERSION = '0.4.3'
30
12
 
31
13
  # CSIDL constants
32
14
  csidl = Hash[
@@ -110,7 +92,7 @@ class Dir
110
92
  end
111
93
  end
112
94
 
113
- Dir.const_set(key, path) if path
95
+ Dir.const_set(key, path.encode(Encoding.default_external)) if path
114
96
  }
115
97
 
116
98
  # Set Dir::MYDOCUMENTS to the same as Dir::PERSONAL if undefined
@@ -287,10 +269,6 @@ class Dir
287
269
  # Raises +ENOENT+ if given path does not exist, returns +false+
288
270
  # if it is not a junction.
289
271
  #
290
- # Note that regardless of the encoding of the string passed in,
291
- # +read_junction()+ will always return a result as UTF-16LE, as it's
292
- # actually written in the reparse point.
293
- #
294
272
  # Example:
295
273
  #
296
274
  # Dir.mkdir('C:/from')
@@ -368,7 +346,7 @@ class Dir
368
346
  jname = jname.bytes.to_a.pack('C*')
369
347
  jname = jname.force_encoding("UTF-16LE")
370
348
  raise "Junction name came back as #{jname}" unless jname[0..3] == "\\??\\".encode("UTF-16LE")
371
- return jname[4..-1].gsub("\\".encode("UTF-16LE"), "/".encode("UTF-16LE"))
349
+ File.expand_path(jname[4..-1].encode(Encoding.default_external))
372
350
  end
373
351
 
374
352
  # Returns whether or not +path+ is empty. Returns false if +path+ is not
@@ -25,7 +25,7 @@ class TC_Win32_Dir < Test::Unit::TestCase
25
25
  end
26
26
 
27
27
  test "version number is set to expected value" do
28
- assert_equal('0.4.2', Dir::VERSION)
28
+ assert_equal('0.4.3', Dir::VERSION)
29
29
  end
30
30
 
31
31
  test 'glob handles backslashes' do
@@ -72,13 +72,19 @@ class TC_Win32_Dir < Test::Unit::TestCase
72
72
  test "read_junction works as expected with ascii characters" do
73
73
  assert_nothing_raised{ Dir.create_junction(@ascii_to, @@from) }
74
74
  assert_true(File.exists?(@ascii_to))
75
- assert_equal(Dir.read_junction(@ascii_to), @@from.bytes.to_a.pack('C*').encode("UTF-16LE"))
75
+ assert_equal(Dir.read_junction(@ascii_to), @@from)
76
76
  end
77
77
 
78
78
  test "read_junction works as expected with unicode characters" do
79
79
  assert_nothing_raised{ Dir.create_junction(@unicode_to, @@from) }
80
80
  assert_true(File.exists?(@unicode_to))
81
- assert_equal(Dir.read_junction(@unicode_to), @@from.bytes.to_a.pack('C*').encode("UTF-16LE"))
81
+ assert_equal(Dir.read_junction(@unicode_to), @@from)
82
+ end
83
+
84
+ test "read_junction with unicode characters is joinable" do
85
+ assert_nothing_raised{ Dir.create_junction(@unicode_to, @@from) }
86
+ assert_true(File.exists?(@unicode_to))
87
+ assert_nothing_raised{ File.join(Dir.read_junction(@unicode_to), 'foo') }
82
88
  end
83
89
 
84
90
  test "junction? method returns boolean value" do
@@ -380,6 +386,11 @@ class TC_Win32_Dir < Test::Unit::TestCase
380
386
  assert_kind_of(String, Dir::WINDOWS)
381
387
  end
382
388
 
389
+ test "constants are ascii_compatible?" do
390
+ assert_true(Dir::COMMON_APPDATA.encoding.ascii_compatible?)
391
+ assert_nothing_raised{ File.join(Dir::COMMON_APPDATA, 'foo') }
392
+ end
393
+
383
394
  test "ffi functions are private" do
384
395
  assert_not_respond_to(Dir, :SHGetFolderPathW)
385
396
  end
data/win32-dir.gemspec CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'win32-dir'
5
- spec.version = '0.4.2'
5
+ spec.version = '0.4.3'
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,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-dir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
5
- prerelease:
4
+ version: 0.4.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Daniel J. Berger
@@ -10,45 +9,42 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-04-08 00:00:00.000000000 Z
12
+ date: 2013-07-24 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: ffi
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: 1.0.0
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: 1.0.0
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: test-unit
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
34
  version: 2.4.0
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - '>='
45
40
  - !ruby/object:Gem::Version
46
41
  version: 2.4.0
47
- description: ! " The win32-dir library provides extra methods and constants for
48
- the\n builtin Dir class. The constants provide a convenient way to identify\n
49
- \ certain directories across all versions of Windows. Some methods have\n been
50
- added, such as the ability to create junctions. Others have been\n modified to
51
- provide a more consistent result for MS Windows.\n"
42
+ description: |2
43
+ The win32-dir library provides extra methods and constants for the
44
+ builtin Dir class. The constants provide a convenient way to identify
45
+ certain directories across all versions of Windows. Some methods have
46
+ been added, such as the ability to create junctions. Others have been
47
+ modified to provide a more consistent result for MS Windows.
52
48
  email: djberg96@gmail.com
53
49
  executables: []
54
50
  extensions: []
@@ -71,27 +67,26 @@ files:
71
67
  homepage: http://github.com/djberg96/win32-dir
72
68
  licenses:
73
69
  - Artistic 2.0
70
+ metadata: {}
74
71
  post_install_message:
75
72
  rdoc_options: []
76
73
  require_paths:
77
74
  - lib
78
75
  required_ruby_version: !ruby/object:Gem::Requirement
79
- none: false
80
76
  requirements:
81
- - - ! '>='
77
+ - - '>='
82
78
  - !ruby/object:Gem::Version
83
79
  version: 1.9.2
84
80
  required_rubygems_version: !ruby/object:Gem::Requirement
85
- none: false
86
81
  requirements:
87
- - - ! '>='
82
+ - - '>='
88
83
  - !ruby/object:Gem::Version
89
84
  version: '0'
90
85
  requirements: []
91
86
  rubyforge_project: win32utils
92
- rubygems_version: 1.8.24
87
+ rubygems_version: 2.0.3
93
88
  signing_key:
94
- specification_version: 3
89
+ specification_version: 4
95
90
  summary: Extra constants and methods for the Dir class on Windows.
96
91
  test_files:
97
92
  - test/test_win32_dir.rb