win32-file-stat 1.4.3 → 1.5.0

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: ee8c0c3a76c7fcc22794899ff2cb0e0f455ba6e0
4
- data.tar.gz: 73fbaca95c61912ef6e62f7baa2bf26c3a6f9f66
3
+ metadata.gz: 570cfbe24ce0b82de003f94d55e00b53dff39c77
4
+ data.tar.gz: 36cebc20ffc58f5ac96b8daad1558cd48a121f3c
5
5
  SHA512:
6
- metadata.gz: 7cd9985c5a62e7d71e99f586dfe2f18dc1f49fedc4c808db474fa2f5f0b790870612d1f114450de484e93bdeda2b34e1c1339efe2773cc4401a7f3ef6fe56680
7
- data.tar.gz: 0db9479f32582058da50eaff0afff77226f9fa51e7a520aeb2dd0b9e5f2ee63c260f9d3ae0cf1f96cb8bf9cf421b57d5857c44ffbcf0677ce3d8b4dc95e7990a
6
+ metadata.gz: 6d573af01f22041b8c4b89512865a74e25e93c87a9b3d4450af2e6143a5d405322e506bd26d4ebe12c40e0af64fc218ec481fdce4e87017ba6145727cbd4a813
7
+ data.tar.gz: 9208feadbeec27b4add065953b2bc35469bf41fa2bf417a606be7688acf71cd1b80bb4eeb76923e16aeab0ea114da2cc3dc73d2a9fea2af6fb9016860cd3ff72
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.5.0 - 10-Nov-2014
2
+ * Added the #streams method, which shows alt streams for the file.
3
+ * Use require_relative where appropriate.
4
+ * Removed reference to rubyforge_project in gemspec.
5
+
1
6
  == 1.4.3 - 8-May-2014
2
7
  * The #writable? method now ignores the readonly attribute if it's a directory.
3
8
  * Replaced File.exists? with File.exist? to avoid warnings in Ruby 2.1.x.
data/README CHANGED
@@ -17,6 +17,7 @@
17
17
  p stat.readonly?
18
18
  p stat.hidden?
19
19
  p stat.uid
20
+ p stat.streams
20
21
 
21
22
  == Differences between Ruby's File::Stat and this version:
22
23
  * The File::Stat#blksize method returns a meaningful value.
@@ -36,6 +37,7 @@
36
37
  * The File::Stat#grpowned? method now works properly.
37
38
  * The File::Stat#rdev method returns the volume serial number.
38
39
  * The inspect and pretty print output has been customized.
40
+ * The File::Stat#streams was added. Returns an array of alt streams.
39
41
 
40
42
  == Changes between this version and the previous versions.
41
43
  * The File::Stat#dev method has reverted to returning a drive number by
@@ -69,6 +71,12 @@
69
71
  has a builtin pretty_print method for File::Stat. If I didn't do this
70
72
  you would end up using the pretty_print in pp.rb, which would break.
71
73
 
74
+ == Contributions
75
+ Although this library is free, please consider having your company
76
+ setup a gittip if used by your company professionally.
77
+
78
+ http://www.gittip.com/djberg96/
79
+
72
80
  == Copyright
73
81
  (C) 2003-2014, Daniel J. Berger, All Rights Reserved.
74
82
 
@@ -1,7 +1,7 @@
1
- require File.join(File.dirname(__FILE__), 'windows', 'helper')
2
- require File.join(File.dirname(__FILE__), 'windows', 'constants')
3
- require File.join(File.dirname(__FILE__), 'windows', 'structs')
4
- require File.join(File.dirname(__FILE__), 'windows', 'functions')
1
+ require_relative 'windows/helper'
2
+ require_relative 'windows/constants'
3
+ require_relative 'windows/structs'
4
+ require_relative 'windows/functions'
5
5
  require 'pp'
6
6
 
7
7
  class File::Stat
@@ -54,8 +54,11 @@ class File::Stat
54
54
  # Nil on Windows
55
55
  attr_reader :dev_major, :dev_minor, :rdev_major, :rdev_minor
56
56
 
57
+ # Alternate streams
58
+ attr_reader :streams
59
+
57
60
  # The version of the win32-file-stat library
58
- WIN32_FILE_STAT_VERSION = '1.4.3'
61
+ WIN32_FILE_STAT_VERSION = '1.5.0'
59
62
 
60
63
  # Creates and returns a File::Stat object, which encapsulate common status
61
64
  # information for File objects on MS Windows sytems. The information is
@@ -86,6 +89,7 @@ class File::Stat
86
89
 
87
90
  if handle
88
91
  @filetype = get_filetype(handle)
92
+ @streams = get_streams(handle)
89
93
  @chardev = @filetype == FILE_TYPE_CHAR
90
94
  @regular = @filetype == FILE_TYPE_DISK
91
95
  @pipe = @filetype == FILE_TYPE_PIPE
@@ -506,8 +510,8 @@ class File::Stat
506
510
  members = %w[
507
511
  archive? atime blksize blockdev? blocks compressed? ctime dev
508
512
  encrypted? gid hidden? indexed? ino mode mtime rdev nlink normal?
509
- offline? readonly? reparse_point? size sparse? system? temporary?
510
- uid
513
+ offline? readonly? reparse_point? size sparse? system? streams
514
+ temporary? uid
511
515
  ]
512
516
 
513
517
  str = "#<#{self.class}"
@@ -533,7 +537,7 @@ class File::Stat
533
537
  members = %w[
534
538
  archive? atime blksize blockdev? blocks compressed? ctime dev
535
539
  encrypted? gid hidden? indexed? ino mode mtime rdev nlink normal?
536
- offline? readonly? reparse_point? size sparse? system? temporary?
540
+ offline? readonly? reparse_point? size sparse? streams system? temporary?
537
541
  uid
538
542
  ]
539
543
 
@@ -713,6 +717,29 @@ class File::Stat
713
717
  file_type
714
718
  end
715
719
 
720
+ def get_streams(handle)
721
+ io_status = IO_STATUS_BLOCK.new
722
+ ptr = FFI::MemoryPointer.new(:uchar, 1024 * 64)
723
+
724
+ NtQueryInformationFile(handle, io_status, ptr, ptr.size, FileStreamInformation)
725
+
726
+ if FFI.errno != 0
727
+ raise SystemCallError.new('NtQueryInformationFile', FFI.errno)
728
+ end
729
+
730
+ arr = []
731
+
732
+ while true
733
+ info = FILE_STREAM_INFORMATION.new(ptr)
734
+ break if info[:StreamNameLength] == 0
735
+ arr << info[:StreamName].to_ptr.read_bytes(info[:StreamNameLength]).delete(0.chr)
736
+ break if info[:NextEntryOffset] == 0
737
+ info = FILE_STREAM_INFORMATION.new(ptr += info[:NextEntryOffset])
738
+ end
739
+
740
+ arr
741
+ end
742
+
716
743
  # Return a sid of the file's owner.
717
744
  #
718
745
  def get_file_sid(file, info)
@@ -87,6 +87,8 @@ module Windows
87
87
 
88
88
  TokenUser = 1
89
89
  TokenGroups = 2
90
+
91
+ FileStreamInformation = 22
90
92
  end
91
93
  end
92
94
  end
@@ -16,6 +16,7 @@ module Windows
16
16
  typedef :pointer, :ptr
17
17
  typedef :buffer_in, :buf_in
18
18
  typedef :string, :str
19
+ typedef :long, :ntstatus
19
20
 
20
21
  ffi_convention :stdcall
21
22
 
@@ -52,6 +53,10 @@ module Windows
52
53
  attach_pfunc :BuildTrusteeWithSid, :BuildTrusteeWithSidW, [:ptr, :ptr], :void
53
54
  attach_pfunc :GetSecurityDescriptorDacl, [:ptr, :ptr, :ptr, :ptr], :bool
54
55
  attach_pfunc :GetEffectiveRightsFromAcl, :GetEffectiveRightsFromAclW, [:ptr, :ptr, :ptr], :dword
56
+
57
+ ffi_lib :ntdll
58
+
59
+ attach_pfunc :NtQueryInformationFile, [:handle, :pointer, :pointer, :ulong, :int], :ntstatus
55
60
  end
56
61
  end
57
62
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'constants')
1
+ require_relative 'constants'
2
2
 
3
3
  require 'ffi'
4
4
 
@@ -9,6 +9,31 @@ module Windows
9
9
 
10
10
  private
11
11
 
12
+ class LowHighLarge < FFI::Struct
13
+ layout(:LowPart, :ulong, :HighPart, :long)
14
+ end
15
+
16
+ class LARGE_INTEGER < FFI::Union
17
+ layout(:u, LowHighLarge, :QuadPart, :long_long)
18
+ end
19
+
20
+ class FILE_STREAM_INFORMATION < FFI::Struct
21
+ layout(
22
+ :NextEntryOffset, :ulong,
23
+ :StreamNameLength, :ulong,
24
+ :StreamSize, LARGE_INTEGER,
25
+ :StreamAllocateSize, LARGE_INTEGER,
26
+ :StreamName, [:uchar, 256]
27
+ )
28
+ end
29
+
30
+ class IO_STATUS_BLOCK < FFI::Struct
31
+ layout(
32
+ :union, Class.new(FFI::Union){ layout(:Status, :long, :Pointer, :pointer) },
33
+ :Information, :uintptr_t
34
+ )
35
+ end
36
+
12
37
  class LowHigh < FFI::Struct
13
38
  layout(:LowPart, :ulong, :HighPart, :ulong)
14
39
  end
@@ -54,7 +54,7 @@ class TC_Win32_File_Stat < Test::Unit::TestCase
54
54
  end
55
55
 
56
56
  test "version is set to expected value" do
57
- assert_equal('1.4.3', File::Stat::WIN32_FILE_STAT_VERSION)
57
+ assert_equal('1.5.0', File::Stat::WIN32_FILE_STAT_VERSION)
58
58
  end
59
59
 
60
60
  test "constructor does not modify argument" do
@@ -529,6 +529,15 @@ class TC_Win32_File_Stat < Test::Unit::TestCase
529
529
  assert_false(@stat.sticky?)
530
530
  end
531
531
 
532
+ test "streams basic functionality" do
533
+ assert_respond_to(@stat, :streams)
534
+ assert_kind_of(Array, @stat.streams)
535
+ end
536
+
537
+ test "streams returns expected value" do
538
+ assert_equal("::$DATA", @stat.streams[0])
539
+ end
540
+
532
541
  test "symlink? basic functionality" do
533
542
  assert_respond_to(@stat, :symlink?)
534
543
  assert_boolean(@stat.symlink?)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'win32-file-stat'
3
- spec.version = '1.4.3'
3
+ spec.version = '1.5.0'
4
4
  spec.authors = ['Daniel J. Berger', 'Park Heesob']
5
5
  spec.license = 'Artistic 2.0'
6
6
  spec.email = 'djberg96@gmail.com'
@@ -9,7 +9,6 @@ Gem::Specification.new do |spec|
9
9
  spec.test_file = 'test/test_file_stat.rb'
10
10
  spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
11
11
 
12
- spec.rubyforge_project = 'Win32Utils'
13
12
  spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
14
13
  spec.required_ruby_version = ">= 1.9.0"
15
14
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-file-stat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,62 +9,62 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-08 00:00:00.000000000 Z
12
+ date: 2014-11-10 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
  - !ruby/object:Gem::Dependency
43
43
  name: win32-security
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '>='
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - '>='
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - '>='
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  description: |2
@@ -102,17 +102,17 @@ require_paths:
102
102
  - lib
103
103
  required_ruby_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - '>='
105
+ - - ">="
106
106
  - !ruby/object:Gem::Version
107
107
  version: 1.9.0
108
108
  required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - '>='
110
+ - - ">="
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  requirements: []
114
- rubyforge_project: Win32Utils
115
- rubygems_version: 2.2.2
114
+ rubyforge_project:
115
+ rubygems_version: 2.4.2
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: A File::Stat class tailored to MS Windows