win32-changenotify 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ module Windows
2
+ module Constants
3
+ FILE_ACTION_ADDED = 0x00000001
4
+ FILE_ACTION_REMOVED = 0x00000002
5
+ FILE_ACTION_MODIFIED = 0x00000003
6
+ FILE_ACTION_RENAMED_OLD_NAME = 0x00000004
7
+ FILE_ACTION_RENAMED_NEW_NAME = 0x00000005
8
+
9
+ FILE_NOTIFY_CHANGE_FILE_NAME = 1
10
+ FILE_NOTIFY_CHANGE_DIR_NAME = 2
11
+ FILE_NOTIFY_CHANGE_ATTRIBUTES = 4
12
+ FILE_NOTIFY_CHANGE_SIZE = 8
13
+ FILE_NOTIFY_CHANGE_LAST_WRITE = 16
14
+ FILE_NOTIFY_CHANGE_LAST_ACCESS = 32
15
+ FILE_NOTIFY_CHANGE_CREATION = 64
16
+ FILE_NOTIFY_CHANGE_SECURITY = 256
17
+
18
+ FILE_LIST_DIRECTORY = 1
19
+ FILE_SHARE_READ = 1
20
+ FILE_SHARE_WRITE = 2
21
+ FILE_SHARE_DELETE = 4
22
+ OPEN_EXISTING = 3
23
+ FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
24
+ FILE_FLAG_OVERLAPPED = 0x40000000
25
+
26
+ INVALID_HANDLE_VALUE = 0xFFFFFFFF
27
+ end
28
+ end
@@ -0,0 +1,60 @@
1
+ require 'ffi'
2
+
3
+ module Windows
4
+ module Functions
5
+ extend FFI::Library
6
+
7
+ # Make FFI functions private
8
+ module FFI::Library
9
+ def attach_pfunc(*args)
10
+ attach_function(*args)
11
+ private args[0]
12
+ end
13
+ end
14
+
15
+ ffi_lib :kernel32
16
+
17
+ typedef :uintptr_t, :handle
18
+ typedef :ulong, :dword
19
+ typedef :pointer, :ptr
20
+
21
+ attach_pfunc :ReadDirectoryChangesW,
22
+ [:handle, :ptr, :dword, :bool, :dword, :ptr, :ptr, :ptr],
23
+ :bool
24
+
25
+ attach_pfunc :CreateIoCompletionPort,
26
+ [:handle, :handle, :pointer, :dword],
27
+ :handle
28
+
29
+ attach_pfunc :GetQueuedCompletionStatus,
30
+ [:handle, :ptr, :ptr, :ptr, :dword],
31
+ :bool,
32
+ :nonblock => true
33
+
34
+ attach_pfunc :CreateFileA,
35
+ [:string, :dword, :dword, :ptr, :dword, :dword, :handle],
36
+ :handle
37
+
38
+ attach_pfunc :FormatMessage, :FormatMessageA,
39
+ [:ulong, :pointer, :ulong, :ulong, :pointer, :ulong, :pointer], :ulong
40
+
41
+
42
+ # Returns a nicer Windows error message
43
+ def win_error(function, err=FFI.errno)
44
+ flags = 0x00001000 | 0x00000200
45
+ buf = FFI::MemoryPointer.new(:char, 1024)
46
+
47
+ FormatMessage(flags, nil, err , 0x0409, buf, 1024, nil)
48
+
49
+ function + ': ' + buf.read_string.strip
50
+ end
51
+
52
+ # Shortcut for win_error with raise builtin
53
+ def raise_windows_error(function, err=FFI.errno)
54
+ raise SystemCallError.new(win_error(function, err), err)
55
+ end
56
+
57
+ module_function :win_error
58
+ module_function :raise_windows_error
59
+ end
60
+ end
@@ -0,0 +1,26 @@
1
+ require 'ffi'
2
+
3
+ module Windows
4
+ module Structs
5
+ extend FFI::Library
6
+
7
+ class OVERLAPPED < FFI::Struct
8
+ layout(
9
+ :Internal, :uintptr_t,
10
+ :InternalHigh, :uintptr_t,
11
+ :Offset, :ulong,
12
+ :OffsetHigh, :ulong,
13
+ :hEvent, :uintptr_t
14
+ )
15
+ end
16
+
17
+ class FILE_NOTIFY_INFORMATION < FFI::Struct
18
+ layout(
19
+ :NextEntryOffset, :ulong,
20
+ :Action, :ulong,
21
+ :FileNameLength, :ulong,
22
+ :FileName, [:uint8, 1024]
23
+ )
24
+ end
25
+ end
26
+ end
@@ -1,70 +1,93 @@
1
- #############################################################################
2
- # test_win32_changenotify.rb
3
- #
4
- # Test suite for the win32-changenotify package. You should run this
5
- # test via the 'rake test' task.
6
- #############################################################################
7
- require 'test/unit'
8
- require 'win32/changenotify'
9
- include Win32
10
-
11
- class TC_Win32_ChangeNotify < Test::Unit::TestCase
12
- def setup
13
- @filter = ChangeNotify::FILE_NAME | ChangeNotify::DIR_NAME
14
- @cn = ChangeNotify.new("c:\\", false, @filter)
15
- end
16
-
17
- def test_version
18
- assert_equal('0.5.1', ChangeNotify::VERSION)
19
- end
20
-
21
- def test_path
22
- assert_respond_to(@cn, :path)
23
- assert_equal("c:\\", @cn.path)
24
- end
25
-
26
- def test_recursive
27
- assert_respond_to(@cn, :recursive?)
28
- assert_equal(false, @cn.recursive?)
29
- end
30
-
31
- def test_filter
32
- assert_respond_to(@cn, :filter)
33
- assert_equal(@filter, @cn.filter)
34
- end
35
-
36
- # The errors here are expected because of the timeout.
37
- def test_wait
38
- assert_respond_to(@cn, :wait)
39
- assert_raises(ChangeNotify::Error){ @cn.wait(0.001) }
40
- assert_raises(ChangeNotify::Error){ @cn.wait(0.001){} }
41
- end
42
-
43
- def test_wait_any
44
- assert_respond_to(@cn, :wait_any)
45
- end
46
-
47
- def test_wait_all
48
- assert_respond_to(@cn, :wait_all)
49
- end
50
-
51
- def test_expected_errors
52
- assert_raises(TypeError){
53
- ChangeNotify.new(1, true, @filter)
54
- }
55
- assert_raises(TypeError){
56
- ChangeNotify.new("C:\\", 'foo', @filter)
57
- }
58
- assert_raises(TypeError){
59
- ChangeNotify.new("C:\\", false, "foo")
60
- }
61
- assert_raises(TypeError){
62
- ChangeNotify.new(1, true, @filter, 'bogus')
63
- }
64
- end
65
-
66
- def teardown
67
- @cn = nil
68
- @filter = nil
69
- end
70
- end
1
+ #############################################################################
2
+ # test_win32_changenotify.rb
3
+ #
4
+ # Test suite for the win32-changenotify package. You should run this
5
+ # test via the 'rake test' task.
6
+ #############################################################################
7
+ require 'test-unit'
8
+ require 'win32/changenotify'
9
+ include Win32
10
+
11
+ class TC_Win32_ChangeNotify < Test::Unit::TestCase
12
+ def setup
13
+ @filter = ChangeNotify::FILE_NAME | ChangeNotify::DIR_NAME
14
+ @cn = ChangeNotify.new("c:\\", false, @filter)
15
+ end
16
+
17
+ test "version constant is set to expected value" do
18
+ assert_equal('0.6.0', ChangeNotify::VERSION)
19
+ end
20
+
21
+ test "path basic functionality" do
22
+ assert_respond_to(@cn, :path)
23
+ assert_nothing_raised{ @cn.path }
24
+ assert_kind_of(String, @cn.path)
25
+ end
26
+
27
+ test "path returns expected value" do
28
+ assert_equal("c:\\", @cn.path)
29
+ end
30
+
31
+ test "recursive basic functionality" do
32
+ assert_respond_to(@cn, :recursive?)
33
+ assert_nothing_raised{ @cn.recursive? }
34
+ assert_boolean(@cn.recursive?)
35
+ end
36
+
37
+ test "recursive returns expected value" do
38
+ assert_equal(false, @cn.recursive?)
39
+ end
40
+
41
+ test "filter method basic functionality" do
42
+ assert_respond_to(@cn, :filter)
43
+ assert_nothing_raised{ @cn.filter }
44
+ assert_kind_of(Numeric, @cn.filter)
45
+ end
46
+
47
+ test "filter method returns expected value" do
48
+ assert_equal(@filter, @cn.filter)
49
+ end
50
+
51
+ test "wait basic functionality" do
52
+ assert_respond_to(@cn, :wait)
53
+ end
54
+
55
+ test "an error is raised if a timeout occurs" do
56
+ assert_raise(SystemCallError){ @cn.wait(0.001) }
57
+ assert_raise(SystemCallError){ @cn.wait(0.001){} }
58
+ end
59
+
60
+ test "inherits wait_any method from Ipc parent" do
61
+ assert_respond_to(@cn, :wait_any)
62
+ end
63
+
64
+ test "inherites wait_all method from Ipc parent" do
65
+ assert_respond_to(@cn, :wait_all)
66
+ end
67
+
68
+ test "constructor requires the first argument to be a string" do
69
+ assert_raises(TypeError){ ChangeNotify.new(1, true, @filter) }
70
+ end
71
+
72
+ test "constructor requires second argument to be a boolean" do
73
+ assert_raises(TypeError){ ChangeNotify.new("C:\\", 'foo', @filter) }
74
+ end
75
+
76
+ test "constructor requires third argument to be numeric" do
77
+ assert_raises(TypeError){ ChangeNotify.new("C:\\", false, "foo") }
78
+ end
79
+
80
+ test "constructor requires fourth argument to be a Win32::Event object" do
81
+ assert_raises(TypeError){ ChangeNotify.new(1, true, @filter, 'bogus') }
82
+ end
83
+
84
+ test "ffi functions are private" do
85
+ assert_not_respond_to(@cn, :ReadDirectoryChangesW)
86
+ assert_not_respond_to(ChangeNotify, :ReadDirectoryChangesW)
87
+ end
88
+
89
+ def teardown
90
+ @cn = nil
91
+ @filter = nil
92
+ end
93
+ end
@@ -1,28 +1,28 @@
1
- require 'rubygems'
2
-
3
- spec = Gem::Specification.new do |gem|
4
- gem.name = 'win32-changenotify'
5
- gem.version = '0.5.1'
6
- gem.author = 'Daniel J. Berger'
7
- gem.license = 'Artistic 2.0'
8
- gem.email = 'djberg96@gmail.com'
9
- gem.homepage = 'http://www.rubyforge.org/projects/win32utils'
10
- gem.platform = Gem::Platform::RUBY
11
- gem.summary = 'A way to monitor files and directories on MS Windows'
12
- gem.test_file = 'test/test_win32_changenotify.rb'
13
- gem.has_rdoc = true
14
- gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
15
-
16
- gem.rubyforge_project = 'win32utils'
17
- gem.extra_rdoc_files = ['MANIFEST', 'README', 'CHANGES']
18
-
19
- gem.add_dependency('windows-pr', '>= 1.0.6')
20
-
21
- gem.description = <<-EOF
22
- The win32-changenotify library provides an interface for monitoring
23
- changes in files or diretories on the MS Windows filesystem. It not only
24
- tells you when a change occurs, but the nature of the change as well.
25
- EOF
26
- end
27
-
28
- Gem::Builder.new(spec).build
1
+ require 'rubygems'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'win32-changenotify'
5
+ spec.version = '0.6.0'
6
+ spec.author = 'Daniel J. Berger'
7
+ spec.license = 'Artistic 2.0'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://github.com/djberg96/win32-changenotify'
10
+ spec.summary = 'A way to monitor files and directories on MS Windows'
11
+ spec.test_file = 'test/test_win32_changenotify.rb'
12
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
+
14
+ spec.rubyforge_project = 'win32utils'
15
+ spec.extra_rdoc_files = ['MANIFEST', 'README', 'CHANGES']
16
+
17
+ spec.add_dependency('ffi')
18
+ spec.add_dependency('win32-event')
19
+
20
+ spec.add_development_dependency('test-unit')
21
+ spec.add_development_dependency('rake')
22
+
23
+ spec.description = <<-EOF
24
+ The win32-changenotify library provides an interface for monitoring
25
+ changes in files or diretories on the MS Windows filesystem. It not only
26
+ tells you when a change occurs, but the nature of the change as well.
27
+ EOF
28
+ end
metadata CHANGED
@@ -1,73 +1,117 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: win32-changenotify
3
- version: !ruby/object:Gem::Version
4
- version: 0.5.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Daniel J. Berger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2009-08-21 00:00:00 -06:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: windows-pr
11
+ date: 2013-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
17
20
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.0.6
24
- version:
25
- description: " The win32-changenotify library provides an interface for monitoring\n changes in files or diretories on the MS Windows filesystem. It not only\n tells you when a change occurs, but the nature of the change as well.\n"
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: win32-event
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: |2
70
+ The win32-changenotify library provides an interface for monitoring
71
+ changes in files or diretories on the MS Windows filesystem. It not only
72
+ tells you when a change occurs, but the nature of the change as well.
26
73
  email: djberg96@gmail.com
27
74
  executables: []
28
-
29
75
  extensions: []
30
-
31
- extra_rdoc_files:
76
+ extra_rdoc_files:
32
77
  - MANIFEST
33
78
  - README
34
79
  - CHANGES
35
- files:
80
+ files:
36
81
  - CHANGES
37
82
  - examples/example_win32_changenotify.rb
83
+ - lib/win32/changenotify/constants.rb
84
+ - lib/win32/changenotify/functions.rb
85
+ - lib/win32/changenotify/structs.rb
38
86
  - lib/win32/changenotify.rb
39
87
  - MANIFEST
40
88
  - Rakefile
41
89
  - README
42
90
  - test/test_win32_changenotify.rb
43
91
  - win32-changenotify.gemspec
44
- has_rdoc: true
45
- homepage: http://www.rubyforge.org/projects/win32utils
46
- licenses:
92
+ homepage: http://github.com/djberg96/win32-changenotify
93
+ licenses:
47
94
  - Artistic 2.0
95
+ metadata: {}
48
96
  post_install_message:
49
97
  rdoc_options: []
50
-
51
- require_paths:
98
+ require_paths:
52
99
  - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: "0"
58
- version:
59
- required_rubygems_version: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- version:
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
65
110
  requirements: []
66
-
67
111
  rubyforge_project: win32utils
68
- rubygems_version: 1.3.5
112
+ rubygems_version: 2.0.7
69
113
  signing_key:
70
- specification_version: 3
114
+ specification_version: 4
71
115
  summary: A way to monitor files and directories on MS Windows
72
- test_files:
116
+ test_files:
73
117
  - test/test_win32_changenotify.rb