REBOL3 tracker
  0.9.12 beta
Ticket #0000602 User: anonymous

Project:



rss
TypeBug Statustested Date3-Feb-2009 09:59
Versionalpha 33 CategoryMezzanine Submitted byhenrikmk
PlatformAll Severityminor Priorityurgent

Summary DIR? incorrect with existing files (not dirs)
Description (Based on a complaint from Kaj that DIR? does not behave like in R2.)

DIR? has two changes relative to R2, one good and one bad.
- The good: DIR? tests true for a non-existing file! with a "/" on the end.
- The bad: DIR? tests true for an existing file (not directory) with a "/" on the end.

The rest works the same as R2. An explanation of why the good is a good change is in the comments.
Example code
; On Windows and WINE, alpha 33, correct unless marked otherwise **
>> dir? %doesnotexist
== false
>> dir? %doesnotexist/
== true  ; Good change from R2
>> dir? %file
== false
>> dir? %file/
== true  ; ** Should be false
>> dir? %directory
== true
>> dir? %directory/
== true

Assigned ton/a Fixed inalpha 99 Last Update8-May-2010 00:22


Comments
(0000400)
BrianH
3-Feb-2009 22:18

Restated the complaint and added example code to point out the bug and illustrate the desired behavior.

The reason why the first change is an improvement: file! values that don't refer to existing files can't be said to be real directories or not - they don't exist. So if you are insisting on DIR? telling whether the file is really a directory, it should return NONE because neither TRUE nor FALSE is correct.

It is much more useful to return whether the theoretical file would be a directory if it existed. You can still test for existence separately. The tests of existing files and directories should reflect whether they are really files or directories. Best of both worlds.

We need the above examples to be tested on WINE as well.

There will be incompatibilities with R2 where appropriate, and this is definitely one of those occasions where it is appropriate.
(0000405)
Kaj
5-Feb-2009 04:35

The results on WINE are exactly the same.

The real problem is that the behaviour is different from R2 and mixing testing of type and actual file nodes this way is very confusing. It was already confusing because file? and dir? have different meanings.
(0000407)
BrianH
5-Feb-2009 07:18

Thanks for the WINE testing. FILE? is the same as in R2, just a datatype check. One of the goals in R3 is to fix design flaws in R2, so you can expect *many* changes. Discussions in chat, R3/Natives/File (1697).

We are backporting the new mezzanines (well, I am) and new natives (as mezzanines), though obviously their implementation is different in R2. It will be trickier to backport the changes to existing natives, because we aren't going to be changing R2 in ways that are incompatible with existing code, just R3. (Except for possibly functions noone uses...)

Look to the r2-forward.r file in DevBase for the backports.
(0002322)
Carl
6-May-2010 01:05

The reasoning behind the design of DIR? was to avoid doing a file system request each time to see if the file was a directory or not. This function is really doing two things: a real check and a "virtual check" (that's based on the name alone.)

So, it's been modified for A98. This means that using DIR? will ALWAYS cause a file system request, even in cases where the file name is known not to be local to the current directory.

Programmers should be advised to use #"/" = last file for virtual checks where file system access is not desired.
(0002333)
BrianH
6-May-2010 09:04

Still doesn't return false for existing files specified with a / on the end - the "; ** Should be false" case in the example code.

Tested on Windows 7 x64. Any others willing to test this, in case it's a platform thing?
(0002341)
Carl
6-May-2010 17:32

It's not going to work. We need to redefine it. See:
http://www.rebol.net/r3blogs/0319.html
(0002347)
Carl
6-May-2010 19:48

Moving DIR? to mezzanine and redefining as acting only on the file path string, regardless of the file storage. Use EXISTS? for that function (returns 'dir).
(0002351)
BrianH
7-May-2010 10:05

Given the #606 fix, the new behavior of DIR? should be good enough, and less confusing.

Date User Field Action Change
8-May-2010 00:22 BrianH Status Modified built => tested
8-May-2010 00:22 BrianH Category Modified Native => Mezzanine
7-May-2010 10:05 BrianH Comment : 0002351 Added -
6-May-2010 19:48 carl Status Modified reviewed => built
6-May-2010 19:48 carl Fixedin Modified => alpha 99
6-May-2010 19:48 carl Comment : 0002347 Added -
6-May-2010 17:32 carl Comment : 0002341 Added -
6-May-2010 09:05 BrianH Comment : 0002333 Modified -
6-May-2010 09:04 BrianH Comment : 0002333 Added -
6-May-2010 09:02 BrianH Status Modified built => reviewed
6-May-2010 09:02 BrianH Category Modified Unspecified => Native
6-May-2010 09:02 BrianH Fixedin Modified alpha 98 => none
6-May-2010 01:05 carl Comment : 0002322 Added -
6-May-2010 00:58 carl Fixedin Modified => alpha 98
6-May-2010 00:58 carl Status Modified reviewed => built
6-May-2010 00:58 carl Category Modified => Unspecified
26-Feb-2009 02:58 BrianH Priority Modified normal => urgent
6-Feb-2009 18:42 BrianH Code Modified -
6-Feb-2009 18:40 BrianH Comment : 0000407 Modified -
5-Feb-2009 07:20 BrianH Comment : 0000407 Modified -
5-Feb-2009 07:18 BrianH Comment : 0000407 Added -
5-Feb-2009 05:00 Kaj Comment : 0000405 Modified -
5-Feb-2009 04:57 Kaj Comment : 0000405 Modified -
5-Feb-2009 04:35 Kaj Comment : 0000405 Added -
3-Feb-2009 22:18 BrianH Comment : 0000400 Added -
3-Feb-2009 22:08 BrianH Status Modified submitted => reviewed
3-Feb-2009 22:08 BrianH Severity Modified tweak => minor
3-Feb-2009 22:08 BrianH Code Modified -
3-Feb-2009 22:08 BrianH Description Modified -
3-Feb-2009 22:08 BrianH Summary Modified Correct behavior for DIR? with non-existing dirs => DIR? incorrect with existing files (not dirs)
3-Feb-2009 09:59 henrikmk Ticket Added -