win32-file 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.6.7 - 23-Nov-2011
2
+ * Fixed an encoding problem with File.set_permissions for Ruby 1.9.x.
3
+ * Fixed a bug in File.basename where an error could be caused by trailing
4
+ slashes. Thanks go to paz for the spot and patch.
5
+ * Updated the clean task in the Rakefile.
6
+
1
7
  == 0.6.6 - 3-Sep-2010
2
8
  * Fixed a bug in the custom File.dirname where trailing slashes were
3
9
  affecting the result. Trailing slashes are now ignored.
data/Rakefile CHANGED
@@ -1,14 +1,10 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
+ require 'rake/clean'
3
4
  require 'rbconfig'
4
5
  include Config
5
6
 
6
- desc 'Clean any text files that may have been left over from tests'
7
- task :clean do
8
- Dir['test/*'].each{ |file|
9
- rm file if File.extname(file) == '.txt'
10
- }
11
- end
7
+ CLEAN.include("**/*.txt", "**/*.gem", "**/*.rbc")
12
8
 
13
9
  namespace 'gem' do
14
10
  desc 'Create the win32-file gem'
data/lib/win32/file.rb CHANGED
@@ -19,7 +19,7 @@ class File
19
19
  extend Windows::Handle
20
20
 
21
21
  # The version of the win32-file library
22
- WIN32_FILE_VERSION = '0.6.6'
22
+ WIN32_FILE_VERSION = '0.6.7'
23
23
 
24
24
  # Abbreviated attribute constants for convenience
25
25
 
@@ -176,8 +176,9 @@ class File
176
176
  all_ace = 0.chr * ALLOW_ACE_LENGTH
177
177
  all_ace_ptr = memset(all_ace, 0, 0) # address of all_ace
178
178
 
179
+
179
180
  # all_ace_ptr->Header.AceType = ACCESS_ALLOWED_ACE_TYPE
180
- all_ace[0] = 0
181
+ all_ace[0] = 0.chr
181
182
 
182
183
  perms.each{ |account, mask|
183
184
  next if mask.nil?
@@ -225,7 +226,10 @@ class File
225
226
  end
226
227
 
227
228
  # all_ace_ptr->Header.AceFlags = INHERIT_ONLY_ACE|OBJECT_INHERIT_ACE
228
- all_ace[1] = INHERIT_ONLY_ACE | OBJECT_INHERIT_ACE
229
+ all_ace[1] = (INHERIT_ONLY_ACE | OBJECT_INHERIT_ACE).chr
230
+
231
+ # WHY DO I NEED THIS RUBY CORE TEAM? WHY?!?!?!?!?!?
232
+ all_ace.force_encoding('ASCII-8BIT') if RUBY_VERSION.to_f >= 1.9
229
233
 
230
234
  2.times{
231
235
  if account_rights != 0
@@ -245,10 +249,10 @@ class File
245
249
  end
246
250
 
247
251
  # all_ace_ptr->Header.AceFlags = CONTAINER_INHERIT_ACE
248
- all_ace[1] = CONTAINER_INHERIT_ACE
252
+ all_ace[1] = CONTAINER_INHERIT_ACE.chr
249
253
  else
250
254
  # all_ace_ptr->Header.AceFlags = 0
251
- all_ace[1] = 0
255
+ all_ace[1] = 0.chr
252
256
  end
253
257
 
254
258
  account_rights = REST_RIGHTS_MASK & mask
@@ -483,7 +487,7 @@ class File
483
487
  end
484
488
 
485
489
  file = wide_to_multi(file)
486
- file.chop! while file[-1].chr == "\\" # Trim trailing slashes
490
+ file.sub!(/\\+\z/, '') # Trim trailing slashes
487
491
 
488
492
  file
489
493
  end
@@ -26,7 +26,7 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
26
26
  end
27
27
 
28
28
  def test_version
29
- assert_equal('0.6.6', File::WIN32_FILE_VERSION)
29
+ assert_equal('0.6.7', File::WIN32_FILE_VERSION)
30
30
  end
31
31
 
32
32
  def test_is_directory
@@ -1,246 +1,256 @@
1
- #############################################################################
2
- # test_win32_file_path.rb
3
- #
4
- # Test case for the path related methods of win32-file. You should run this
5
- # test via the 'rake test' or 'rake test_path' task.
6
- #############################################################################
7
- require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
11
- require 'win32/file'
12
-
13
- class TC_Win32_File_Path < Test::Unit::TestCase
14
- def self.startup
15
- Dir.chdir(File.dirname(File.expand_path(File.basename(__FILE__))))
16
- @@file = File.join(Dir.pwd, 'path_test.txt')
17
- File.open(@@file, 'w'){ |fh| fh.puts "This is a path test." }
18
- end
19
-
20
- def setup
21
- @long_file = File.join(Dir.pwd, 'path_test.txt')
22
- @short_file = File.join(Dir.pwd, 'PATH_T~1.TXT')
23
- end
24
-
25
- test "basename method basic functionality" do
26
- assert_respond_to(File, :basename)
27
- assert_nothing_raised{ File.basename("C:\\foo") }
28
- assert_kind_of(String, File.basename("C:\\foo"))
29
- end
30
-
31
- test "basename method handles standard paths" do
32
- assert_equal("baz.txt", File.basename("C:\\foo\\bar\\baz.txt"))
33
- assert_equal("baz", File.basename("C:\\foo\\bar\\baz.txt", ".txt"))
34
- assert_equal("baz.txt", File.basename("C:\\foo\\bar\\baz.txt", ".zip"))
35
- assert_equal("bar", File.basename("C:\\foo\\bar"))
36
- assert_equal("bar", File.basename("C:\\foo\\bar\\"))
37
- assert_equal("foo", File.basename("C:\\foo"))
38
- assert_equal("C:\\", File.basename("C:\\"))
39
- end
40
-
41
- test "basename method handles unc paths" do
42
- assert_equal("baz.txt", File.basename("\\\\foo\\bar\\baz.txt"))
43
- assert_equal("baz", File.basename("\\\\foo\\bar\\baz"))
44
- assert_equal("\\\\foo", File.basename("\\\\foo"))
45
- assert_equal("\\\\foo\\bar", File.basename("\\\\foo\\bar"))
46
- end
47
-
48
- test "basename method handles forward slashes in standard unix paths" do
49
- assert_equal("bar", File.basename("/foo/bar"))
50
- assert_equal("bar.txt", File.basename("/foo/bar.txt"))
51
- assert_equal("bar.txt", File.basename("bar.txt"))
52
- assert_equal("bar", File.basename("/bar"))
53
- assert_equal("bar", File.basename("/bar/"))
54
- assert_equal("baz", File.basename("//foo/bar/baz"))
55
- end
56
-
57
- test "basename method handles forward slashes in unc unix paths" do
58
- assert_equal("\\\\foo", File.basename("//foo"))
59
- assert_equal("\\\\foo\\bar", File.basename("//foo/bar"))
60
- end
61
-
62
- test "basename method handles forward slashes in windows paths" do
63
- assert_equal("bar", File.basename("C:/foo/bar"))
64
- assert_equal("bar", File.basename("C:/foo/bar/"))
65
- assert_equal("foo", File.basename("C:/foo"))
66
- assert_equal("C:\\", File.basename("C:/"))
67
- assert_equal("bar", File.basename("C:/foo/bar//"))
68
- end
69
-
70
- test "basename handles edge cases as expected" do
71
- assert_equal("", File.basename(""))
72
- assert_equal(".", File.basename("."))
73
- assert_equal("..", File.basename(".."))
74
- assert_equal("foo", File.basename("//foo/"))
75
- end
76
-
77
- test "basename handles path names with suffixes" do
78
- assert_equal("bar", File.basename("bar.txt", ".txt"))
79
- assert_equal("bar", File.basename("/foo/bar.txt", ".txt"))
80
- assert_equal("bar.txt", File.basename("bar.txt", ".exe"))
81
- assert_equal("bar.txt", File.basename("bar.txt.exe", ".exe"))
82
- assert_equal("bar.txt.exe", File.basename("bar.txt.exe", ".txt"))
83
- assert_equal("bar", File.basename("bar.txt", ".*"))
84
- assert_equal("bar.txt", File.basename("bar.txt.exe", ".*"))
85
- end
86
-
87
- test "basename method does not modify its argument" do
88
- path = "C:\\foo\\bar"
89
- assert_nothing_raised{ File.basename(path) }
90
- assert_equal("C:\\foo\\bar", path)
91
- end
92
-
93
- test "dirname basic functionality" do
94
- assert_respond_to(File, :dirname)
95
- assert_nothing_raised{ File.dirname("C:\\foo") }
96
- assert_kind_of(String, File.dirname("C:\\foo"))
97
- end
98
-
99
- test "dirname handles standard windows paths as expected" do
100
- assert_equal("C:\\foo", File.dirname("C:\\foo\\bar.txt"))
101
- assert_equal("C:\\foo", File.dirname("C:\\foo\\bar"))
102
- assert_equal("C:\\", File.dirname("C:\\foo"))
103
- assert_equal("C:\\", File.dirname("C:\\"))
104
- assert_equal(".", File.dirname("foo"))
105
- end
106
-
107
- test "dirname handles unc windows paths as expected" do
108
- assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar\\baz"))
109
- assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar"))
110
- assert_equal("\\\\foo", File.dirname("\\\\foo"))
111
- assert_equal("\\\\", File.dirname("\\\\"))
112
- end
113
-
114
- test "dirname handles forward slashes in standard windows path names" do
115
- assert_equal("C:\\foo", File.dirname("C:/foo/bar.txt"))
116
- assert_equal("C:\\foo", File.dirname("C:/foo/bar"))
117
- assert_equal("C:\\", File.dirname("C:/foo"))
118
- assert_equal("C:\\", File.dirname("C:/"))
119
- end
120
-
121
- test "dirname handles forward slashes in unc windows path names" do
122
- assert_equal("\\\\foo\\bar", File.dirname("//foo/bar/baz"))
123
- assert_equal("\\\\foo\\bar", File.dirname("//foo/bar"))
124
- assert_equal("\\\\foo", File.dirname("//foo"))
125
- assert_equal("\\\\", File.dirname("//"))
126
- end
127
-
128
- test "dirname handles forward slashes in relative path names" do
129
- assert_equal(".", File.dirname("./foo"))
130
- assert_equal(".\\foo", File.dirname("./foo/bar"))
131
- end
132
-
133
- test "dirname handles various edge cases as expected" do
134
- assert_equal(".", File.dirname(""))
135
- assert_equal(".", File.dirname("."))
136
- assert_equal(".", File.dirname(".."))
137
- assert_equal(".", File.dirname("./"))
138
- end
139
-
140
- test "dirname method does not modify its argument" do
141
- path = "C:\\foo\\bar"
142
- assert_nothing_raised{ File.dirname(path) }
143
- assert_equal("C:\\foo\\bar", path)
144
- end
145
-
146
- test "dirname method ignores trailing slashes" do
147
- assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz/"))
148
- assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz//"))
149
- assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz///"))
150
- assert_equal("C:\\foo\\bar", File.dirname("C:\\foo\\bar\\baz\\"))
151
- assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar\\baz\\"))
152
- end
153
-
154
- test "argument to dirname must be a string" do
155
- assert_raises(TypeError){ File.dirname(nil) }
156
- assert_raises(TypeError){ File.dirname(['foo', 'bar']) }
157
- end
158
-
159
- test "split method basic functionality" do
160
- assert_respond_to(File, :split)
161
- assert_nothing_raised{ File.split("C:\\foo\\bar") }
162
- assert_kind_of(Array, File.split("C:\\foo\\bar"))
163
- end
164
-
165
- test "split method handles standard windows path names" do
166
- assert_equal(["C:\\foo", "bar"], File.split("C:\\foo\\bar"))
167
- assert_equal([".", "foo"], File.split("foo"))
168
- end
169
-
170
- test "split method handles windows paths with forward slashes" do
171
- assert_equal(["C:\\foo", "bar"], File.split("C:/foo/bar"))
172
- assert_equal([".", "foo"], File.split("foo"))
173
- end
174
-
175
- test "split method handles standard unix paths as expected" do
176
- assert_equal(["\\foo","bar"], File.split("/foo/bar"))
177
- assert_equal(["\\", "foo"], File.split("/foo"))
178
- assert_equal([".", "foo"], File.split("foo"))
179
- end
180
-
181
- test "split method handles unc paths as expected" do
182
- assert_equal(["\\\\foo\\bar", "baz"], File.split("\\\\foo\\bar\\baz"))
183
- assert_equal(["\\\\foo\\bar", ""], File.split("\\\\foo\\bar"))
184
- assert_equal(["\\\\foo", ""], File.split("\\\\foo"))
185
- assert_equal(["\\\\", ""], File.split("\\\\"))
186
- end
187
-
188
- test "split method handles various edge cases as expected" do
189
- assert_equal(["C:\\", ""], File.split("C:\\"))
190
- assert_equal(["", ""], File.split(""))
191
- end
192
-
193
- test "split method does not modify its arguments" do
194
- path = "C:\\foo\\bar"
195
- assert_nothing_raised{ File.split(path) }
196
- assert_equal("C:\\foo\\bar", path)
197
- end
198
-
199
- test "long_path method works as expected" do
200
- assert_respond_to(File, :long_path)
201
- assert_equal(@long_file, File.long_path(@short_file))
202
- assert_equal('PATH_T~1.TXT', File.basename(@short_file))
203
- end
204
-
205
- test "short_path method works as expected" do
206
- assert_respond_to(File, :short_path)
207
- assert_equal('path_test.txt', File.basename(@long_file))
208
- end
209
-
210
- test "join method works as expected" do
211
- assert_respond_to(File, :join)
212
- end
213
-
214
- test "join handles multiple arguments as expected" do
215
- assert_equal("C:\\foo\\bar", File.join("C:", "foo", "bar"))
216
- assert_equal("foo\\bar", File.join("foo", "bar"))
217
- end
218
-
219
- test "join handles multiple arguments as expected with unc paths" do
220
- assert_equal("\\\\foo", File.join("\\\\foo"))
221
- assert_equal("\\\\foo\\bar", File.join("\\\\foo", "bar"))
222
- end
223
-
224
- test "join does not normalize paths" do
225
- assert_equal("C:\\.\\foo\\..", File.join("C:", ".", "foo", ".."))
226
- end
227
-
228
- test "join with no arguments returns an empty string" do
229
- assert_equal('', File.join)
230
- end
231
-
232
- test "join with one argument returns the argument" do
233
- assert_equal('foo', File.join('foo'))
234
- assert_equal('c:', File.join('c:'))
235
- end
236
-
237
- def teardown
238
- @short_file = nil
239
- @long_file = nil
240
- end
241
-
242
- def self.shutdown
243
- File.delete(@@file) if File.exists?(@@file)
244
- @@file = nil
245
- end
246
- end
1
+ #############################################################################
2
+ # test_win32_file_path.rb
3
+ #
4
+ # Test case for the path related methods of win32-file. You should run this
5
+ # test via the 'rake test' or 'rake test_path' task.
6
+ #############################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'win32/file'
12
+
13
+ class TC_Win32_File_Path < Test::Unit::TestCase
14
+ def self.startup
15
+ Dir.chdir(File.dirname(File.expand_path(File.basename(__FILE__))))
16
+ @@file = File.join(Dir.pwd, 'path_test.txt')
17
+ File.open(@@file, 'w'){ |fh| fh.puts "This is a path test." }
18
+ end
19
+
20
+ def setup
21
+ @long_file = File.join(Dir.pwd, 'path_test.txt')
22
+ @short_file = File.join(Dir.pwd, 'PATH_T~1.TXT')
23
+ end
24
+
25
+ test "basename method basic functionality" do
26
+ assert_respond_to(File, :basename)
27
+ assert_nothing_raised{ File.basename("C:\\foo") }
28
+ assert_kind_of(String, File.basename("C:\\foo"))
29
+ end
30
+
31
+ test "basename method handles standard paths" do
32
+ assert_equal("baz.txt", File.basename("C:\\foo\\bar\\baz.txt"))
33
+ assert_equal("baz", File.basename("C:\\foo\\bar\\baz.txt", ".txt"))
34
+ assert_equal("baz.txt", File.basename("C:\\foo\\bar\\baz.txt", ".zip"))
35
+ assert_equal("bar", File.basename("C:\\foo\\bar"))
36
+ assert_equal("bar", File.basename("C:\\foo\\bar\\"))
37
+ assert_equal("foo", File.basename("C:\\foo"))
38
+ assert_equal("C:\\", File.basename("C:\\"))
39
+ end
40
+
41
+ test "basename method handles unc paths" do
42
+ assert_equal("baz.txt", File.basename("\\\\foo\\bar\\baz.txt"))
43
+ assert_equal("baz", File.basename("\\\\foo\\bar\\baz"))
44
+ assert_equal("\\\\foo", File.basename("\\\\foo"))
45
+ assert_equal("\\\\foo\\bar", File.basename("\\\\foo\\bar"))
46
+ end
47
+
48
+ test "basename method handles forward slashes in standard unix paths" do
49
+ assert_equal("bar", File.basename("/foo/bar"))
50
+ assert_equal("bar.txt", File.basename("/foo/bar.txt"))
51
+ assert_equal("bar.txt", File.basename("bar.txt"))
52
+ assert_equal("bar", File.basename("/bar"))
53
+ assert_equal("bar", File.basename("/bar/"))
54
+ assert_equal("baz", File.basename("//foo/bar/baz"))
55
+ end
56
+
57
+ test "basename method handles forward slashes in unc unix paths" do
58
+ assert_equal("\\\\foo", File.basename("//foo"))
59
+ assert_equal("\\\\foo\\bar", File.basename("//foo/bar"))
60
+ end
61
+
62
+ test "basename method handles forward slashes in windows paths" do
63
+ assert_equal("bar", File.basename("C:/foo/bar"))
64
+ assert_equal("bar", File.basename("C:/foo/bar/"))
65
+ assert_equal("foo", File.basename("C:/foo"))
66
+ assert_equal("C:\\", File.basename("C:/"))
67
+ assert_equal("bar", File.basename("C:/foo/bar//"))
68
+ end
69
+
70
+ test "basename handles edge cases as expected" do
71
+ assert_equal("", File.basename(""))
72
+ assert_equal(".", File.basename("."))
73
+ assert_equal("..", File.basename(".."))
74
+ assert_equal("foo", File.basename("//foo/"))
75
+ end
76
+
77
+ test "basename handles path names with suffixes" do
78
+ assert_equal("bar", File.basename("bar.txt", ".txt"))
79
+ assert_equal("bar", File.basename("/foo/bar.txt", ".txt"))
80
+ assert_equal("bar.txt", File.basename("bar.txt", ".exe"))
81
+ assert_equal("bar.txt", File.basename("bar.txt.exe", ".exe"))
82
+ assert_equal("bar.txt.exe", File.basename("bar.txt.exe", ".txt"))
83
+ assert_equal("bar", File.basename("bar.txt", ".*"))
84
+ assert_equal("bar.txt", File.basename("bar.txt.exe", ".*"))
85
+ end
86
+
87
+ test "basename method does not modify its argument" do
88
+ path = "C:\\foo\\bar"
89
+ assert_nothing_raised{ File.basename(path) }
90
+ assert_equal("C:\\foo\\bar", path)
91
+ end
92
+
93
+ test "basename removes all trailing slashes" do
94
+ assert_equal("foo.txt", File.basename("C:/foo.txt/"))
95
+ assert_equal("foo.txt", File.basename("C:/foo.txt//"))
96
+ assert_equal("foo.txt", File.basename("C:/foo.txt///"))
97
+ assert_equal("foo.txt", File.basename("C:\\foo.txt\\"))
98
+ assert_equal("foo.txt", File.basename("C:\\foo.txt\\\\"))
99
+ assert_equal("foo.txt", File.basename("C:\\foo.txt\\\\\\"))
100
+ assert_equal("foo.txt", File.basename("foo.txt\\\\\\"))
101
+ end
102
+
103
+ test "dirname basic functionality" do
104
+ assert_respond_to(File, :dirname)
105
+ assert_nothing_raised{ File.dirname("C:\\foo") }
106
+ assert_kind_of(String, File.dirname("C:\\foo"))
107
+ end
108
+
109
+ test "dirname handles standard windows paths as expected" do
110
+ assert_equal("C:\\foo", File.dirname("C:\\foo\\bar.txt"))
111
+ assert_equal("C:\\foo", File.dirname("C:\\foo\\bar"))
112
+ assert_equal("C:\\", File.dirname("C:\\foo"))
113
+ assert_equal("C:\\", File.dirname("C:\\"))
114
+ assert_equal(".", File.dirname("foo"))
115
+ end
116
+
117
+ test "dirname handles unc windows paths as expected" do
118
+ assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar\\baz"))
119
+ assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar"))
120
+ assert_equal("\\\\foo", File.dirname("\\\\foo"))
121
+ assert_equal("\\\\", File.dirname("\\\\"))
122
+ end
123
+
124
+ test "dirname handles forward slashes in standard windows path names" do
125
+ assert_equal("C:\\foo", File.dirname("C:/foo/bar.txt"))
126
+ assert_equal("C:\\foo", File.dirname("C:/foo/bar"))
127
+ assert_equal("C:\\", File.dirname("C:/foo"))
128
+ assert_equal("C:\\", File.dirname("C:/"))
129
+ end
130
+
131
+ test "dirname handles forward slashes in unc windows path names" do
132
+ assert_equal("\\\\foo\\bar", File.dirname("//foo/bar/baz"))
133
+ assert_equal("\\\\foo\\bar", File.dirname("//foo/bar"))
134
+ assert_equal("\\\\foo", File.dirname("//foo"))
135
+ assert_equal("\\\\", File.dirname("//"))
136
+ end
137
+
138
+ test "dirname handles forward slashes in relative path names" do
139
+ assert_equal(".", File.dirname("./foo"))
140
+ assert_equal(".\\foo", File.dirname("./foo/bar"))
141
+ end
142
+
143
+ test "dirname handles various edge cases as expected" do
144
+ assert_equal(".", File.dirname(""))
145
+ assert_equal(".", File.dirname("."))
146
+ assert_equal(".", File.dirname(".."))
147
+ assert_equal(".", File.dirname("./"))
148
+ end
149
+
150
+ test "dirname method does not modify its argument" do
151
+ path = "C:\\foo\\bar"
152
+ assert_nothing_raised{ File.dirname(path) }
153
+ assert_equal("C:\\foo\\bar", path)
154
+ end
155
+
156
+ test "dirname method ignores trailing slashes" do
157
+ assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz/"))
158
+ assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz//"))
159
+ assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz///"))
160
+ assert_equal("C:\\foo\\bar", File.dirname("C:\\foo\\bar\\baz\\"))
161
+ assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar\\baz\\"))
162
+ end
163
+
164
+ test "argument to dirname must be a string" do
165
+ assert_raises(TypeError){ File.dirname(nil) }
166
+ assert_raises(TypeError){ File.dirname(['foo', 'bar']) }
167
+ end
168
+
169
+ test "split method basic functionality" do
170
+ assert_respond_to(File, :split)
171
+ assert_nothing_raised{ File.split("C:\\foo\\bar") }
172
+ assert_kind_of(Array, File.split("C:\\foo\\bar"))
173
+ end
174
+
175
+ test "split method handles standard windows path names" do
176
+ assert_equal(["C:\\foo", "bar"], File.split("C:\\foo\\bar"))
177
+ assert_equal([".", "foo"], File.split("foo"))
178
+ end
179
+
180
+ test "split method handles windows paths with forward slashes" do
181
+ assert_equal(["C:\\foo", "bar"], File.split("C:/foo/bar"))
182
+ assert_equal([".", "foo"], File.split("foo"))
183
+ end
184
+
185
+ test "split method handles standard unix paths as expected" do
186
+ assert_equal(["\\foo","bar"], File.split("/foo/bar"))
187
+ assert_equal(["\\", "foo"], File.split("/foo"))
188
+ assert_equal([".", "foo"], File.split("foo"))
189
+ end
190
+
191
+ test "split method handles unc paths as expected" do
192
+ assert_equal(["\\\\foo\\bar", "baz"], File.split("\\\\foo\\bar\\baz"))
193
+ assert_equal(["\\\\foo\\bar", ""], File.split("\\\\foo\\bar"))
194
+ assert_equal(["\\\\foo", ""], File.split("\\\\foo"))
195
+ assert_equal(["\\\\", ""], File.split("\\\\"))
196
+ end
197
+
198
+ test "split method handles various edge cases as expected" do
199
+ assert_equal(["C:\\", ""], File.split("C:\\"))
200
+ assert_equal(["", ""], File.split(""))
201
+ end
202
+
203
+ test "split method does not modify its arguments" do
204
+ path = "C:\\foo\\bar"
205
+ assert_nothing_raised{ File.split(path) }
206
+ assert_equal("C:\\foo\\bar", path)
207
+ end
208
+
209
+ test "long_path method works as expected" do
210
+ assert_respond_to(File, :long_path)
211
+ assert_equal(@long_file, File.long_path(@short_file))
212
+ assert_equal('PATH_T~1.TXT', File.basename(@short_file))
213
+ end
214
+
215
+ test "short_path method works as expected" do
216
+ assert_respond_to(File, :short_path)
217
+ assert_equal('path_test.txt', File.basename(@long_file))
218
+ end
219
+
220
+ test "join method works as expected" do
221
+ assert_respond_to(File, :join)
222
+ end
223
+
224
+ test "join handles multiple arguments as expected" do
225
+ assert_equal("C:\\foo\\bar", File.join("C:", "foo", "bar"))
226
+ assert_equal("foo\\bar", File.join("foo", "bar"))
227
+ end
228
+
229
+ test "join handles multiple arguments as expected with unc paths" do
230
+ assert_equal("\\\\foo", File.join("\\\\foo"))
231
+ assert_equal("\\\\foo\\bar", File.join("\\\\foo", "bar"))
232
+ end
233
+
234
+ test "join does not normalize paths" do
235
+ assert_equal("C:\\.\\foo\\..", File.join("C:", ".", "foo", ".."))
236
+ end
237
+
238
+ test "join with no arguments returns an empty string" do
239
+ assert_equal('', File.join)
240
+ end
241
+
242
+ test "join with one argument returns the argument" do
243
+ assert_equal('foo', File.join('foo'))
244
+ assert_equal('c:', File.join('c:'))
245
+ end
246
+
247
+ def teardown
248
+ @short_file = nil
249
+ @long_file = nil
250
+ end
251
+
252
+ def self.shutdown
253
+ File.delete(@@file) if File.exists?(@@file)
254
+ @@file = nil
255
+ end
256
+ end
@@ -15,52 +15,52 @@ require 'win32/file'
15
15
  require 'socket'
16
16
 
17
17
  class TC_Win32_File_Security < Test::Unit::TestCase
18
- def self.startup
19
- Dir.chdir(File.dirname(File.expand_path(File.basename(__FILE__))))
20
- @@host = Socket.gethostname
21
- @@file = File.join(Dir.pwd, 'security_test.txt')
22
- File.open(@@file, 'w'){ |fh| fh.puts "This is a security test." }
23
- end
18
+ def self.startup
19
+ Dir.chdir(File.dirname(File.expand_path(File.basename(__FILE__))))
20
+ @@host = Socket.gethostname
21
+ @@file = File.join(Dir.pwd, 'security_test.txt')
22
+ File.open(@@file, 'w'){ |fh| fh.puts "This is a security test." }
23
+ end
24
24
 
25
- def setup
26
- @perms = nil
27
- end
25
+ def setup
26
+ @perms = nil
27
+ end
28
28
 
29
- # This will fail if there is no "Users" builtin. Not to worry.
30
- def test_get_permissions
31
- assert_respond_to(File, :get_permissions)
32
- assert_nothing_raised{ File.get_permissions(@@file) }
33
- assert_kind_of(Hash, File.get_permissions(@@file))
34
- end
29
+ # This will fail if there is no "Users" builtin. Not to worry.
30
+ def test_get_permissions
31
+ assert_respond_to(File, :get_permissions)
32
+ assert_nothing_raised{ File.get_permissions(@@file) }
33
+ assert_kind_of(Hash, File.get_permissions(@@file))
34
+ end
35
35
 
36
- def test_get_permissions_with_host
37
- assert_nothing_raised{ File.get_permissions(@@file, @@host) }
38
- assert_kind_of(Hash, File.get_permissions(@@file))
39
- end
36
+ def test_get_permissions_with_host
37
+ assert_nothing_raised{ File.get_permissions(@@file, @@host) }
38
+ assert_kind_of(Hash, File.get_permissions(@@file))
39
+ end
40
40
 
41
- def test_set_permissions
42
- assert_respond_to(File, :set_permissions)
43
- assert_nothing_raised{ @perms = File.get_permissions(@@file) }
44
- assert_nothing_raised{ File.set_permissions(@@file, @perms) }
45
- end
41
+ def test_set_permissions
42
+ assert_respond_to(File, :set_permissions)
43
+ assert_nothing_raised{ @perms = File.get_permissions(@@file) }
44
+ assert_nothing_raised{ File.set_permissions(@@file, @perms) }
45
+ end
46
46
 
47
- def test_securities
48
- assert_respond_to(File, :securities)
49
- assert_nothing_raised{ @perms = File.get_permissions(@@file) }
47
+ def test_securities
48
+ assert_respond_to(File, :securities)
49
+ assert_nothing_raised{ @perms = File.get_permissions(@@file) }
50
50
 
51
- @perms.each{ |acct, mask|
52
- assert_nothing_raised{ File.securities(mask) }
53
- assert_kind_of(Array, File.securities(mask))
54
- }
55
- end
51
+ @perms.each{ |acct, mask|
52
+ assert_nothing_raised{ File.securities(mask) }
53
+ assert_kind_of(Array, File.securities(mask))
54
+ }
55
+ end
56
56
 
57
- def teardown
58
- @perms = nil
59
- end
57
+ def teardown
58
+ @perms = nil
59
+ end
60
60
 
61
- def self.shutdown
62
- File.delete(@@file) if File.exists?(@@file)
63
- @@file = nil
64
- @@host = nil
65
- end
61
+ def self.shutdown
62
+ File.delete(@@file) if File.exists?(@@file)
63
+ @@file = nil
64
+ @@host = nil
65
+ end
66
66
  end
data/win32-file.gemspec CHANGED
@@ -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.6.6'
5
+ spec.version = '0.6.7'
6
6
  spec.authors = ['Daniel J. Berger', 'Park Heesob']
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
@@ -10,7 +10,6 @@ Gem::Specification.new do |spec|
10
10
  spec.platform = Gem::Platform::RUBY
11
11
  spec.summary = 'Extra or redefined methods for the File class on Windows.'
12
12
  spec.test_files = Dir['test/test*']
13
- spec.has_rdoc = true
14
13
  spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
15
14
 
16
15
  spec.rubyforge_project = 'win32utils'
@@ -20,7 +19,7 @@ Gem::Specification.new do |spec|
20
19
  spec.add_dependency('win32-file-stat', '>= 1.3.2')
21
20
  spec.add_dependency('windows-pr', '>= 1.0.8')
22
21
 
23
- spec.add_development_dependency('test-unit', '>= 2.0.7')
22
+ spec.add_development_dependency('test-unit')
24
23
 
25
24
  spec.description = <<-EOF
26
25
  The win32-file library adds several methods to the core File class which
metadata CHANGED
@@ -1,90 +1,74 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: win32-file
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 6
8
- - 6
9
- version: 0.6.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.7
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Daniel J. Berger
13
9
  - Park Heesob
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2010-09-03 00:00:00 -06:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2011-11-23 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: win32-api
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 1
30
- - 2
31
- - 1
17
+ requirement: &19820904 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
32
22
  version: 1.2.1
33
23
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: win32-file-stat
37
24
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- segments:
43
- - 1
44
- - 3
45
- - 2
25
+ version_requirements: *19820904
26
+ - !ruby/object:Gem::Dependency
27
+ name: win32-file-stat
28
+ requirement: &19460016 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
46
33
  version: 1.3.2
47
34
  type: :runtime
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: windows-pr
51
35
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- segments:
57
- - 1
58
- - 0
59
- - 8
36
+ version_requirements: *19460016
37
+ - !ruby/object:Gem::Dependency
38
+ name: windows-pr
39
+ requirement: &19454796 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
60
44
  version: 1.0.8
61
45
  type: :runtime
62
- version_requirements: *id003
63
- - !ruby/object:Gem::Dependency
64
- name: test-unit
65
46
  prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- segments:
71
- - 2
72
- - 0
73
- - 7
74
- version: 2.0.7
47
+ version_requirements: *19454796
48
+ - !ruby/object:Gem::Dependency
49
+ name: test-unit
50
+ requirement: &19452456 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
75
56
  type: :development
76
- version_requirements: *id004
77
- description: " The win32-file library adds several methods to the core File class which\n are specific to MS Windows, such as the ability to set and retrieve file\n attributes. In addition, several core methods have been redefined in\n order to work properly on MS Windows, such as File.blksize. See the\n README file for more details.\n"
57
+ prerelease: false
58
+ version_requirements: *19452456
59
+ description: ! " The win32-file library adds several methods to the core File class
60
+ which\n are specific to MS Windows, such as the ability to set and retrieve file\n
61
+ \ attributes. In addition, several core methods have been redefined in\n order
62
+ to work properly on MS Windows, such as File.blksize. See the\n README file for
63
+ more details.\n"
78
64
  email: djberg96@gmail.com
79
65
  executables: []
80
-
81
66
  extensions: []
82
-
83
- extra_rdoc_files:
67
+ extra_rdoc_files:
84
68
  - README
85
69
  - CHANGES
86
70
  - MANIFEST
87
- files:
71
+ files:
88
72
  - CHANGES
89
73
  - lib/win32/file.rb
90
74
  - MANIFEST
@@ -97,37 +81,32 @@ files:
97
81
  - test/test_win32_file_security.rb
98
82
  - test/test_win32_file_stat.rb
99
83
  - win32-file.gemspec
100
- has_rdoc: true
101
84
  homepage: http://www.rubyforge.org/projects/win32utils
102
- licenses:
85
+ licenses:
103
86
  - Artistic 2.0
104
87
  post_install_message:
105
88
  rdoc_options: []
106
-
107
- require_paths:
89
+ require_paths:
108
90
  - lib
109
- required_ruby_version: !ruby/object:Gem::Requirement
110
- requirements:
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- segments:
114
- - 0
115
- version: "0"
116
- required_rubygems_version: !ruby/object:Gem::Requirement
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- segments:
121
- - 0
122
- version: "0"
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
123
103
  requirements: []
124
-
125
104
  rubyforge_project: win32utils
126
- rubygems_version: 1.3.6
105
+ rubygems_version: 1.8.10
127
106
  signing_key:
128
107
  specification_version: 3
129
108
  summary: Extra or redefined methods for the File class on Windows.
130
- test_files:
109
+ test_files:
131
110
  - test/test_win32_file_attributes.rb
132
111
  - test/test_win32_file_constants.rb
133
112
  - test/test_win32_file_encryption.rb