win32-file-attributes 1.0.2 → 1.0.3

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: 2d64c60789cb492bfacc0ecf1381b97be3affc3c
4
- data.tar.gz: e08e6072ea0776de56ce9a540f16b67c7aef7b73
3
+ metadata.gz: e979471f10493700b371adf06ef6ae4a78b25daa
4
+ data.tar.gz: d9d23da6540f250822ab25ee9ab8cf32e1a734a2
5
5
  SHA512:
6
- metadata.gz: fc5e4cf1840d0d34cee7f697179048c734d9ada03e641da8c65fc9f5fbc21df42a16a4a924744d22a0bbaae3cfa0ea0efb67aeb17ae6160204ee5381cbf1b037
7
- data.tar.gz: 2fbef9b336fdc7db8d837055716260ab724d153bea18b91deacbc0e37aa1ebab794ceffa09dfe2465b995ddf1290fd7addef1400648999f51f6cd28545aff4a7
6
+ metadata.gz: b09b0521108e59e35a98ed8357d7cf2df2f06db138c58cc3ca16efb29ffbcc952c4ed64abd06df76f709a2ef23ed37ea76c2e300a2b927a3eaf9713bd373ca69
7
+ data.tar.gz: 414fe460270f5702e118a7b6bda0e23abafb3a600d14bbc2202fa3439e929c6b48e2c21e24260243b108aa6466848cf9861490a50c28124a941dc472b7b29bfe
data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ = 1.0.3 - 8-Nov-2014
2
+ * Make FFI functions private.
3
+ * Removed reference to Rubyforge in gemspec.
4
+ * Use require_relative internally.
5
+ * Explicitly free some FFI memory pointers where appropriate.
6
+
1
7
  = 1.0.2 - 28-Apr-2014
2
8
  * The singleton methods now accept arguments that implement to_str or to_path.
3
9
 
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(__FILE__), 'windows', 'constants')
2
- require File.join(File.dirname(__FILE__), 'windows', 'structs')
3
- require File.join(File.dirname(__FILE__), 'windows', 'functions')
1
+ require_relative 'windows/constants'
2
+ require_relative 'windows/structs'
3
+ require_relative 'windows/functions'
4
4
 
5
5
  class File
6
6
  include Windows::File::Constants
@@ -10,7 +10,7 @@ class File
10
10
  extend Windows::File::Functions
11
11
 
12
12
  # The version of the win32-file library
13
- WIN32_FILE_ATTRIBUTE_VERSION = '1.0.2'
13
+ WIN32_FILE_ATTRIBUTE_VERSION = '1.0.3'
14
14
 
15
15
  ## ABBREVIATED ATTRIBUTE CONSTANTS
16
16
 
@@ -276,12 +276,6 @@ class File
276
276
  # that compression is the default for newly created files and subdirectories.
277
277
  #
278
278
  def compressed=(bool)
279
- in_buf = FFI::MemoryPointer.new(:ulong)
280
- bytes = FFI::MemoryPointer.new(:ulong)
281
-
282
- compression_value = bool ? COMPRESSION_FORMAT_DEFAULT : COMPRESSION_FORMAT_NONE
283
- in_buf.write_ulong(compression_value)
284
-
285
279
  # We can't use get_osfhandle here because we need specific attributes
286
280
  handle = CreateFileW(
287
281
  self.path.wincode,
@@ -297,6 +291,12 @@ class File
297
291
  raise SystemCallError.new("CreateFile", FFI.errno)
298
292
  end
299
293
 
294
+ in_buf = FFI::MemoryPointer.new(:ulong)
295
+ bytes = FFI::MemoryPointer.new(:ulong)
296
+
297
+ compression_value = bool ? COMPRESSION_FORMAT_DEFAULT : COMPRESSION_FORMAT_NONE
298
+ in_buf.write_ulong(compression_value)
299
+
300
300
  begin
301
301
  bool = DeviceIoControl(
302
302
  handle,
@@ -314,6 +314,8 @@ class File
314
314
  end
315
315
  ensure
316
316
  CloseHandle(handle)
317
+ in_buf.free
318
+ bytes.free
317
319
  end
318
320
 
319
321
  self
@@ -449,8 +451,6 @@ class File
449
451
  return
450
452
  end
451
453
 
452
- bytes = FFI::MemoryPointer.new(:ulong)
453
-
454
454
  handle = CreateFileW(
455
455
  self.path.wincode,
456
456
  FILE_READ_DATA | FILE_WRITE_DATA,
@@ -465,6 +465,8 @@ class File
465
465
  raise SystemCallError.new("CreateFile", FFI.errno)
466
466
  end
467
467
 
468
+ bytes = FFI::MemoryPointer.new(:ulong)
469
+
468
470
  begin
469
471
  bool = DeviceIoControl(
470
472
  handle,
@@ -482,6 +484,7 @@ class File
482
484
  end
483
485
  ensure
484
486
  CloseHandle(handle)
487
+ bytes.free
485
488
  end
486
489
 
487
490
  self
@@ -4,16 +4,25 @@ module Windows
4
4
  module File
5
5
  module Functions
6
6
  extend FFI::Library
7
+
8
+ private
9
+
10
+ # Wrapper method for attach_function + private
11
+ def self.attach_pfunc(*args)
12
+ attach_function(*args)
13
+ private args[0]
14
+ end
15
+
7
16
  typedef :ulong, :dword
8
17
  typedef :uintptr_t, :handle
9
18
 
10
19
  ffi_lib :kernel32
11
20
 
12
- attach_function :CloseHandle, [:handle], :bool
13
- attach_function :CreateFileW, [:buffer_in, :dword, :dword, :pointer, :dword, :dword, :handle], :handle
14
- attach_function :DeviceIoControl, [:handle, :dword, :pointer, :dword, :pointer, :dword, :pointer, :pointer], :bool
15
- attach_function :GetFileAttributesW, [:buffer_in], :dword
16
- attach_function :SetFileAttributesW, [:buffer_in, :dword], :bool
21
+ attach_pfunc :CloseHandle, [:handle], :bool
22
+ attach_pfunc :CreateFileW, [:buffer_in, :dword, :dword, :pointer, :dword, :dword, :handle], :handle
23
+ attach_pfunc :DeviceIoControl, [:handle, :dword, :pointer, :dword, :pointer, :dword, :pointer, :pointer], :bool
24
+ attach_pfunc :GetFileAttributesW, [:buffer_in], :dword
25
+ attach_pfunc :SetFileAttributesW, [:buffer_in, :dword], :bool
17
26
 
18
27
  def CTL_CODE(device, function, method, access)
19
28
  ((device) << 16) | ((access) << 14) | ((function) << 2) | (method)
@@ -31,9 +40,11 @@ module Windows
31
40
  end
32
41
 
33
42
  class String
34
- # Convenience method for converting strings to UTF-16LE for wide character
35
- # functions that require it.
36
- def wincode
37
- (self.tr(File::SEPARATOR, File::ALT_SEPARATOR) + 0.chr).encode('UTF-16LE')
43
+ unless instance_methods.include?(:wincode)
44
+ # Convenience method for converting strings to UTF-16LE for wide character
45
+ # functions that require it.
46
+ def wincode
47
+ (self.tr(File::SEPARATOR, File::ALT_SEPARATOR) + 0.chr).encode('UTF-16LE')
48
+ end
38
49
  end
39
50
  end
@@ -28,7 +28,7 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
28
28
  end
29
29
 
30
30
  test "version is set to expected value" do
31
- assert_equal('1.0.2', File::WIN32_FILE_ATTRIBUTE_VERSION)
31
+ assert_equal('1.0.3', File::WIN32_FILE_ATTRIBUTE_VERSION)
32
32
  end
33
33
 
34
34
  test "temporary? singleton method basic functionality" do
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'win32-file-attributes'
5
- spec.version = '1.0.2'
5
+ spec.version = '1.0.3'
6
6
  spec.authors = ['Daniel J. Berger', 'Park Heesob']
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
@@ -11,7 +11,6 @@ Gem::Specification.new do |spec|
11
11
  spec.test_files = Dir['test/test*']
12
12
  spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
13
 
14
- spec.rubyforge_project = 'win32utils'
15
14
  spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
16
15
 
17
16
  spec.add_dependency('ffi')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-file-attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,34 +9,34 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-29 00:00:00.000000000 Z
12
+ date: 2014-11-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: test-unit
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  description: |2
@@ -71,17 +71,17 @@ require_paths:
71
71
  - lib
72
72
  required_ruby_version: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - '>='
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - '>='
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  requirements: []
83
- rubyforge_project: win32utils
84
- rubygems_version: 2.2.2
83
+ rubyforge_project:
84
+ rubygems_version: 2.4.2
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: File attribute methods for the File class on MS Windows