Ruby Forum Ruby-core > [Bug #449] File.zero? returns true when given a directory on Windows

Posted by Anonymous (Guest)
on 15.08.2008 23:39
(Received via mailing list)
Bug #449: File.zero? returns true when given a directory on Windows
http://redmine.ruby-lang.org/issues/show/449

Author: Anonymous
Status: Open, Priority: Normal

On Mac OS X File.zero? returns false when given a directory.
Posted by Nobuyoshi Nakada (nobu)
on 16.08.2008 04:45
(Received via mailing list)
Hi,

At Sat, 16 Aug 2008 06:35:31 +0900,
Anonymous wrote in [ruby-core:18314]:
> Bug #449: File.zero? returns true when given a directory on Windows

> On Mac OS X File.zero? returns false when given a directory.

It is very file-system dependent behavior, and the result has
no meaning on any systems.

On unix-like systems, size of properly created directory can
never be 0, since there are "." and ".." always.

# `properly' means it is created with mkdir system call, but
# not mknod syscall by root.

On the other hand, Windows claims "size of a directory always
must be 0".
Posted by John Lam (IRONRUBY) (Guest)
on 18.08.2008 17:47
(Received via mailing list)
I submitted that original bug (first time using redmine :)). Here's some 
more context:

File.zero? on Windows when given a directory name produces a nonsensical 
result. It should do one of the following:

1) Provide consistent results given a directory name on both Windows and 
*nix
2) Throw an exception since File != Directory

Since 2) is not the Ruby Way, it makes more sense to either do 1), or 
mark its behavior as "undefined", or "platform specific" which will let 
individual implementations decide how to define it.

Does this sound reasonable to folks?


Thanks,
-John
Posted by Yukihiro Matsumoto (Guest)
on 18.08.2008 17:55
(Received via mailing list)
Hi,

In message "Re: [ruby-core:18325] Re: [Bug #449] File.zero? returns true 
when given a directory on Windows"
    on Tue, 19 Aug 2008 00:43:35 +0900, "John Lam (IRONRUBY)" 
<jflam@microsoft.com> writes:
|
|I submitted that original bug (first time using redmine :)). Here's some more context:
|
|File.zero? on Windows when given a directory name produces a nonsensical result. It should do one of the following:
|
|1) Provide consistent results given a directory name on both Windows and *nix
|2) Throw an exception since File != Directory
|
|Since 2) is not the Ruby Way, it makes more sense to either do 1), or mark its behavior as "undefined", or "platform specific" which will let individual implementations decide how to define it.
|
|Does this sound reasonable to folks?

Currently we define its behavior as "platform specific".  Any
objection?

              matz.
Posted by John Lam (IRONRUBY) (Guest)
on 18.08.2008 18:49
(Received via mailing list)
Not at all - it means we're now free to do the right thing :)

Thanks,
-John
Posted by Luis Lavena (luislavena)
on 18.08.2008 19:11
(Received via mailing list)
On Mon, Aug 18, 2008 at 6:45 PM, John Lam (IRONRUBY)
<jflam@microsoft.com> wrote:
> Not at all - it means we're now free to do the right thing :)
>

I hope by "the right thing" you don't say "raise an exception" as the
ideal option ;-)

File.zero? always return false when a Directory is being requested
(*nix), so similar thinking on Windows will reduce the surprise
factor, right?

Also the File.zero? documentation can be updated to reflect that
File.zero? is not reliable across platforms given the same scenario.

> Thanks,
> -John
>

Regards,
--
Luis Lavena
AREA 17
-
Human beings, who are almost unique in having the ability to learn from
the experience of others, are also remarkable for their apparent
disinclination to do so.
Douglas Adams
Posted by Nobuyoshi Nakada (nobu)
on 18.08.2008 20:12
(Received via mailing list)
Hi,

At Tue, 19 Aug 2008 02:07:03 +0900,
Luis Lavena wrote in [ruby-core:18328]:
> File.zero? always return false when a Directory is being requested
> (*nix), so similar thinking on Windows will reduce the surprise
> factor, right?

File.zero? isn't the real issue.  I can't imagine why you want
to use File.size for a directory.  It is a just garbage, I
think.  In what case is it usable?

> Also the File.zero? documentation can be updated to reflect that
> File.zero? is not reliable across platforms given the same scenario.

May Dir#empty? or something else be "expected" method?
Posted by Luis Lavena (luislavena)
on 18.08.2008 20:18
(Received via mailing list)
On Mon, Aug 18, 2008 at 8:08 PM, Nobuyoshi Nakada <nobu@ruby-lang.org> 
wrote:
> think.  In what case is it usable?
>

Don't look at me, I never thought about using it that way, but if
someone reported it maybe someone is using it wrongly?

>> Also the File.zero? documentation can be updated to reflect that
>> File.zero? is not reliable across platforms given the same scenario.
>
> May Dir#empty? or something else be "expected" method?
>

If this bug report came from the RubySpec, then the expectations are
bad... and the documentation can reflect this.

--
Luis Lavena
AREA 17
-
Human beings, who are almost unique in having the ability to learn from
the experience of others, are also remarkable for their apparent
disinclination to do so.
Douglas Adams