[Win32utils-devel] User sid
Daniel Berger
djberg96 at gmail.com
Tue Jul 8 00:38:04 EDT 2008
2008/7/7 Daniel Berger <djberg96 at gmail.com>:
> On Mon, Jul 7, 2008 at 8:59 PM, Heesob Park <phasis at gmail.com> wrote:
>> Hi,
>
> <snip>
>
>>>
>>> The next major upgrade I have planned is to make our libraries more
>>> Unicode friendly, which means lots of manual string handling via
>>> multi_to_wide and so forth. The example that inspired me was
>>> http://tinyurl.com/6e473w.
>>>
>> I can't find any example :)
>>
>>> Sound like a plan?
>>>
>> Please let me know your idea about unicode handling.
>
> File.size("C:\\Documents and Settings\\Artūras") was the example.
>
> Although, come to think of it, maybe all we need to do is alter
> win32-file-stat so that it uses wstat64() + multi_to_wide, and that
> would probably solve a good number of the File class methods.
Well, I tried this patch, but I'm still getting 3 test errors, but I'm
having trouble nailing them down. The error indicates that
get_file_type is failing, but I don't know why.
### Eclipse Workspace Patch 1.0
#P win32-file-stat
Index: lib/win32/file/stat.rb
===================================================================
RCS file: /var/cvs/win32utils/win32-file-stat/lib/win32/file/stat.rb,v
retrieving revision 1.29
diff -u -r1.29 stat.rb
--- lib/win32/file/stat.rb 2 Oct 2007 04:29:56 -0000 1.29
+++ lib/win32/file/stat.rb 8 Jul 2008 04:37:07 -0000
@@ -7,6 +7,7 @@
require 'windows/error'
require 'windows/handle'
require 'windows/volume'
+require 'windows/unicode'
require 'pp'
class File::Stat
@@ -19,9 +20,10 @@
include Windows::Error
include Windows::Handle
include Windows::Volume
+ include Windows::Unicode
include Comparable
- VERSION = '1.2.7'
+ VERSION = '1.2.8'
# Defined in Ruby's win32.h. Not meant for public consumption.
S_IWGRP = 0020
@@ -48,12 +50,13 @@
# the file after that point will not be reflected.
#
def initialize(file)
- @file = file
+ @file = multi_to_wide(file, CP_UTF8)
+ @file = "\\\\?\\" + file unless PathIsRelativeW(@file)
- @file_type = get_file_type(file)
+ @file_type = get_file_type(@file)
@chardev = @file_type == FILE_TYPE_CHAR
- case GetDriveType(file)
+ case GetDriveTypeW(@file)
when DRIVE_REMOVABLE, DRIVE_CDROM, DRIVE_RAMDISK
@blockdev = true
else
@@ -63,7 +66,7 @@
stat_buf = [0,0,0,0,0,0,0,0,0,0,0,0,0].pack('ISSssssIIQQQQ')
# The stat64 function doesn't seem to like character devices
- if stat64(file, stat_buf) != 0
+ if wstat64(@file, stat_buf) != 0
raise ArgumentError, get_last_error unless @chardev
end
@@ -91,17 +94,17 @@
@mode = 33188 if @chardev
- attr = GetFileAttributes(file)
+ attributes = GetFileAttributesW(@file)
error_num = GetLastError()
# Ignore errors caused by empty/open/used block devices.
- if attr == INVALID_FILE_ATTRIBUTES
+ if attributes == INVALID_FILE_ATTRIBUTES
unless error_num == ERROR_NOT_READY
raise ArgumentError, get_last_error(error_num)
end
end
- @blksize = get_blksize(file)
+ @blksize = get_blksize(@file)
# This is a reasonable guess
case @blksize
@@ -113,19 +116,19 @@
@blocks = (@size.to_f / @blksize.to_f).ceil
end
- @readonly = attr & FILE_ATTRIBUTE_READONLY > 0
- @hidden = attr & FILE_ATTRIBUTE_HIDDEN > 0
- @system = attr & FILE_ATTRIBUTE_SYSTEM > 0
- @archive = attr & FILE_ATTRIBUTE_ARCHIVE > 0
- @directory = attr & FILE_ATTRIBUTE_DIRECTORY > 0
- @encrypted = attr & FILE_ATTRIBUTE_ENCRYPTED > 0
- @normal = attr & FILE_ATTRIBUTE_NORMAL > 0
- @temporary = attr & FILE_ATTRIBUTE_TEMPORARY > 0
- @sparse = attr & FILE_ATTRIBUTE_SPARSE_FILE > 0
- @reparse_point = attr & FILE_ATTRIBUTE_REPARSE_POINT > 0
- @compressed = attr & FILE_ATTRIBUTE_COMPRESSED > 0
- @offline = attr & FILE_ATTRIBUTE_OFFLINE > 0
- @indexed = attr & ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED > 0
+ @readonly = attributes & FILE_ATTRIBUTE_READONLY > 0
+ @hidden = attributes & FILE_ATTRIBUTE_HIDDEN > 0
+ @system = attributes & FILE_ATTRIBUTE_SYSTEM > 0
+ @archive = attributes & FILE_ATTRIBUTE_ARCHIVE > 0
+ @directory = attributes & FILE_ATTRIBUTE_DIRECTORY > 0
+ @encrypted = attributes & FILE_ATTRIBUTE_ENCRYPTED > 0
+ @normal = attributes & FILE_ATTRIBUTE_NORMAL > 0
+ @temporary = attributes & FILE_ATTRIBUTE_TEMPORARY > 0
+ @sparse = attributes & FILE_ATTRIBUTE_SPARSE_FILE > 0
+ @reparse_point = attributes & FILE_ATTRIBUTE_REPARSE_POINT > 0
+ @compressed = attributes & FILE_ATTRIBUTE_COMPRESSED > 0
+ @offline = attributes & FILE_ATTRIBUTE_OFFLINE > 0
+ @indexed = attributes & ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED > 0
@executable = GetBinaryType(file, '')
@regular = @file_type == FILE_TYPE_DISK
@@ -536,17 +539,19 @@
free = [0].pack('L')
total = [0].pack('L')
+ p file
+
# If there's a drive letter it must contain a trailing backslash.
# The dup is necessary here because, for some odd reason, the function
# appears to modify the argument passed in.
- if PathStripToRoot(file.dup)
+ if PathStripToRootW(file.dup)
file += "\\" unless file[-1].chr == "\\"
else
file = 0 # Default to root drive
end
# Don't check for an error here. Just default to nil.
- if GetDiskFreeSpace(file, sectors, bytes, free, total)
+ if GetDiskFreeSpaceW(file, sectors, bytes, free, total)
size = sectors.unpack('L').first * bytes.unpack('L').first
end
@@ -555,8 +560,8 @@
# Returns the file's type (as a numeric).
#
- def get_file_type(file)
- handle = CreateFile(
+ def get_file_type(file)
+ handle = CreateFileW(
file,
0,
0,
Suggestions? Or is there a problem with the test suite itself perhaps?
Regards,
Dan
More information about the win32utils-devel
mailing list