win32-file-stat 1.2.3 → 1.2.4
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.
- data/CHANGES +3 -0
- data/README +15 -3
- data/lib/win32/file/stat.rb +22 -12
- data/test/tc_file_stat.rb +17 -4
- data/win32-file-stat.gemspec +2 -2
- metadata +6 -4
data/CHANGES
CHANGED
data/README
CHANGED
@@ -18,7 +18,7 @@ gem install win32-file-stat-<version>.gem
|
|
18
18
|
gem install win32-file-stat
|
19
19
|
|
20
20
|
= Synopsis
|
21
|
-
require 'win32/file/stat'
|
21
|
+
require 'win32/file/stat' # Don't do this in practice - see below
|
22
22
|
|
23
23
|
stat = File::Stat.new('file.txt')
|
24
24
|
stat.size
|
@@ -43,8 +43,20 @@ stat.hidden?
|
|
43
43
|
hidden, etc.
|
44
44
|
* The pp (pretty print) output has been customized.
|
45
45
|
|
46
|
-
= Known issues
|
47
|
-
|
46
|
+
= Known issues
|
47
|
+
You should not require 'win32/file/stat' directly. Instead, require the
|
48
|
+
win32-file package which will, in turn, require win32-file-stat. This is
|
49
|
+
the preferred approach because some modules (i.e. 'find') use the pass-through
|
50
|
+
methods of the File class, such as File.lstat. Many of the pass through
|
51
|
+
methods have been redefined in the win32-file package to work in conjunction
|
52
|
+
with the custom File::Stat objects created by this package.
|
53
|
+
|
54
|
+
Failure to follow these instructions could lead to cases where the core Ruby
|
55
|
+
File class attempts to use the custom File::Stat object defined in this class,
|
56
|
+
which will likely cause problems.
|
57
|
+
|
58
|
+
= Known bugs
|
59
|
+
None that I'm aware of. Please report any bugs you find on the project page
|
48
60
|
at http://www.rubyforge.org/projects/win32utils.
|
49
61
|
|
50
62
|
= Miscellaneous
|
data/lib/win32/file/stat.rb
CHANGED
@@ -6,6 +6,7 @@ require 'windows/path'
|
|
6
6
|
require 'windows/file'
|
7
7
|
require 'windows/error'
|
8
8
|
require 'windows/handle'
|
9
|
+
require 'windows/volume'
|
9
10
|
require 'pp'
|
10
11
|
|
11
12
|
class File::Stat
|
@@ -17,9 +18,10 @@ class File::Stat
|
|
17
18
|
include Windows::File
|
18
19
|
include Windows::Error
|
19
20
|
include Windows::Handle
|
21
|
+
include Windows::Volume
|
20
22
|
include Comparable
|
21
23
|
|
22
|
-
VERSION = '1.2.
|
24
|
+
VERSION = '1.2.4'
|
23
25
|
|
24
26
|
# Defined in Ruby's win32.h. Not meant for public consumption.
|
25
27
|
S_IWGRP = 0020
|
@@ -35,11 +37,16 @@ class File::Stat
|
|
35
37
|
def initialize(file)
|
36
38
|
@file = file
|
37
39
|
|
38
|
-
@
|
39
|
-
@file_type = get_file_type(file) # May update @blockdev
|
40
|
-
|
40
|
+
@file_type = get_file_type(file)
|
41
41
|
@chardev = @file_type == FILE_TYPE_CHAR
|
42
42
|
|
43
|
+
case GetDriveType(file)
|
44
|
+
when DRIVE_REMOVABLE, DRIVE_CDROM, DRIVE_RAMDISK
|
45
|
+
@blockdev = true
|
46
|
+
else
|
47
|
+
@blockdev = false
|
48
|
+
end
|
49
|
+
|
43
50
|
stat_buf = [0,0,0,0,0,0,0,0,0,0,0,0,0].pack('ISSssssIIQQQQ')
|
44
51
|
|
45
52
|
# The stat64 function doesn't seem to like character devices
|
@@ -63,9 +70,13 @@ class File::Stat
|
|
63
70
|
@mode = 33188 if @chardev
|
64
71
|
|
65
72
|
attr = GetFileAttributes(file)
|
73
|
+
error_num = GetLastError()
|
66
74
|
|
75
|
+
# Ignore errors caused by empty/open/used block devices.
|
67
76
|
if attr == INVALID_FILE_ATTRIBUTES
|
68
|
-
|
77
|
+
unless error_num == ERROR_NOT_READY
|
78
|
+
raise ArgumentError, get_last_error(error_num)
|
79
|
+
end
|
69
80
|
end
|
70
81
|
|
71
82
|
@blksize = get_blksize(file)
|
@@ -527,8 +538,13 @@ class File::Stat
|
|
527
538
|
0
|
528
539
|
)
|
529
540
|
|
541
|
+
error_num = GetLastError()
|
542
|
+
|
543
|
+
# Ignore errors caused by open/empty/used block devices.
|
530
544
|
if handle == INVALID_HANDLE_VALUE
|
531
|
-
|
545
|
+
unless error_num == ERROR_NOT_READY
|
546
|
+
raise ArgumentError, get_last_error(error_num)
|
547
|
+
end
|
532
548
|
end
|
533
549
|
|
534
550
|
file_type = GetFileType(handle)
|
@@ -536,12 +552,6 @@ class File::Stat
|
|
536
552
|
|
537
553
|
CloseHandle(handle)
|
538
554
|
|
539
|
-
if error == 0
|
540
|
-
if file_type == FILE_TYPE_DISK || file_type == FILE_TYPE_UNKNOWN
|
541
|
-
@blockdev = true
|
542
|
-
end
|
543
|
-
end
|
544
|
-
|
545
555
|
file_type
|
546
556
|
end
|
547
557
|
|
data/test/tc_file_stat.rb
CHANGED
@@ -13,18 +13,30 @@ end
|
|
13
13
|
|
14
14
|
require 'test/unit'
|
15
15
|
require 'win32/file/stat'
|
16
|
+
include Windows::Volume
|
17
|
+
|
18
|
+
# Find a block device
|
19
|
+
'A'.upto('Z'){ |volume|
|
20
|
+
volume += ":\\"
|
21
|
+
case GetDriveType(volume)
|
22
|
+
when DRIVE_REMOVABLE, DRIVE_CDROM, DRIVE_RAMDISK
|
23
|
+
$block_dev = volume
|
24
|
+
break
|
25
|
+
end
|
26
|
+
}
|
16
27
|
|
17
28
|
class TC_Win32_File_Stat < Test::Unit::TestCase
|
18
|
-
include Windows::File
|
29
|
+
include Windows::File
|
30
|
+
|
19
31
|
def setup
|
20
32
|
@file = 'sometestfile.txt'
|
21
33
|
@exe = 'sometestfile.exe'
|
22
34
|
@dir = Dir.pwd
|
23
|
-
@stat = File::Stat.new(@file)
|
35
|
+
@stat = File::Stat.new(@file)
|
24
36
|
end
|
25
37
|
|
26
38
|
def test_version
|
27
|
-
assert_equal('1.2.
|
39
|
+
assert_equal('1.2.4', File::Stat::VERSION)
|
28
40
|
end
|
29
41
|
|
30
42
|
# One or more tests will fail if the archive attribute on @file is not set.
|
@@ -46,8 +58,9 @@ class TC_Win32_File_Stat < Test::Unit::TestCase
|
|
46
58
|
|
47
59
|
def test_blockdev
|
48
60
|
assert_respond_to(@stat, :blockdev?)
|
49
|
-
assert_equal(
|
61
|
+
assert_equal(false, @stat.blockdev?)
|
50
62
|
assert_equal(false, File::Stat.new('NUL').blockdev?)
|
63
|
+
assert_equal(true, File::Stat.new($block_dev).blockdev?)
|
51
64
|
end
|
52
65
|
|
53
66
|
def test_blocks
|
data/win32-file-stat.gemspec
CHANGED
@@ -2,7 +2,7 @@ require "rubygems"
|
|
2
2
|
|
3
3
|
spec = Gem::Specification.new do |gem|
|
4
4
|
gem.name = "win32-file-stat"
|
5
|
-
gem.version = "1.2.
|
5
|
+
gem.version = "1.2.4"
|
6
6
|
gem.author = "Daniel J. Berger"
|
7
7
|
gem.email = "djberg96@gmail.com"
|
8
8
|
gem.homepage = "http://www.rubyforge.org/projects/win32utils"
|
@@ -15,7 +15,7 @@ spec = Gem::Specification.new do |gem|
|
|
15
15
|
gem.files.reject! { |fn| fn.include? "CVS" }
|
16
16
|
gem.require_path = "lib"
|
17
17
|
gem.extra_rdoc_files = ["README", "CHANGES"]
|
18
|
-
gem.add_dependency("windows-pr", ">= 0.
|
18
|
+
gem.add_dependency("windows-pr", ">= 0.6.0")
|
19
19
|
end
|
20
20
|
|
21
21
|
if $0 == __FILE__
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
2
|
+
rubygems_version: 0.9.0.8
|
3
3
|
specification_version: 1
|
4
4
|
name: win32-file-stat
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.2.
|
7
|
-
date:
|
6
|
+
version: 1.2.4
|
7
|
+
date: 2007-01-22 00:00:00 -07:00
|
8
8
|
summary: A File::Stat class tailored to MS Windows
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -31,12 +31,14 @@ authors:
|
|
31
31
|
files:
|
32
32
|
- lib/win32/file/stat.rb
|
33
33
|
- CHANGES
|
34
|
+
- CVS
|
34
35
|
- install.rb
|
35
36
|
- lib
|
36
37
|
- MANIFEST
|
37
38
|
- README
|
38
39
|
- test
|
39
40
|
- win32-file-stat.gemspec
|
41
|
+
- test/CVS
|
40
42
|
- test/sometestfile.exe
|
41
43
|
- test/sometestfile.txt
|
42
44
|
- test/tc_file_stat.rb
|
@@ -61,5 +63,5 @@ dependencies:
|
|
61
63
|
requirements:
|
62
64
|
- - ">="
|
63
65
|
- !ruby/object:Gem::Version
|
64
|
-
version: 0.
|
66
|
+
version: 0.6.0
|
65
67
|
version:
|