Ticket #1071 (closed defect: fixed)

Opened 22 months ago

Last modified 11 months ago

#'Directory with no type returns results different from wild type

Reported by: svspire Owned by: svspire
Priority: minor Milestone:
Component: ANSI CL Compliance Version: trunk
Keywords: Cc: stassats@…

Description

(directory #P"foo/*" :directories nil) [(directory #P"foo:*" :directories nil) in MCL]

MCL: Returns all files under the foo directory, regardless of whether they have a type or not.

CCL: Returns only files that have no type under foo directory.

Test: (= (length (directory #P"ccl:*.*")) (length (directory #P"ccl:*"))) Should return T if this bug is fixed.

Technically, this is probably not an ANSI compliance issue since ANSI is vague on what #'directory is supposed to do. But current behavior is different from MCL, which is presumably where many CCL users come from. It would be interesting to see what ACL does here.

Fix is simple:

--- pathnames.lisp (revision 15751) +++ pathnames.lisp (working copy) @@ -582,6 +582,10 @@

(%path-str*= pstr pattern))

(defun %file*= (name-pat type-pat pstr)

+ (when (and (eq name-pat :wild) + (or (null type-pat) + (eq type-pat :unspecific))) + (setq type-pat :wild))

(if (eq name-pat :wild) (setq name-pat "*")) (if (eq type-pat :wild) (setq type-pat "*")) (when (and (null name-pat) (null type-pat))

Change History

comment:1 follow-up: ↓ 2 Changed 22 months ago by stassats

  • Cc stassats@… added

I'm not convinced by "many CCL users come from MCL" reasoning. Nowadays many CCL users come from CCL, and CCL had this behavior for quite some time.

comment:2 in reply to: ↑ 1 Changed 22 months ago by svspire

Replying to stassats:

I'm not convinced by "many CCL users come from MCL" reasoning. Nowadays many CCL users come from CCL, and CCL had this behavior for quite some time.

Okay, "some" CCL users come from MCL. But that wasn't even the reason I noticed it. It was because in the CCL IDE's "Search Files" dialog, a single asterisk matches every file (probably because it's calling out to Unix/grep rather than calling #'directory, but there's no reason it has to; MCL does the same thing with #'directory and Boyer/Moore? rather than grep). CCL's #'directory behavior should be consistent with its own IDE that does something #'directory-like.

comment:3 Changed 22 months ago by gz

With this change, how would you search for all files that do not have a type?

comment:4 Changed 21 months ago by svspire

(directory #P"foo:*" :directories nil :test (lambda (x) (null (pathname-type x))))

comment:5 follow-up: ↓ 6 Changed 21 months ago by gb

Rather than breaking existing user code with this change - whose motivation seems to be "so that DIRECTORY will behave more like the shell command used to run grep in the IDE on OSX, or something like that" - I think that it would be better to extend DIRECTORY with yet another keyword argument. For want of a better name, let's assume that that argument is called :TREAT-NULL-TYPE-AS-WILD and that it defaults to the value of *DIRECTORY-TREATS-NULL-TYPE-AS-WILD* which in turn defaults to NIL.

When called with :TREAT-NULL-TYPE-AS-WILD T, DIRECTORY merges its pathname argument with #p".*" (e.g., (directory #p"/somewhere/*") will be treated as (directory #p"/somewhere/*.*")). In all other cases, things will behave as they have in CCL for the last 12 years or so, existing user code won't break, and no one will have to explain why this change was made the way it's currently made. (I'd personally find it very hard to explain that; the rationales given make little sense to me.)

comment:6 in reply to: ↑ 5 Changed 21 months ago by svspire

Replying to gb:

... In all other cases, things will behave as they have in CCL for the last 12 years or so, existing user code won't break, and no one will have to explain why this change was made the way it's currently made. (I'd personally find it very hard to explain that; the rationales given make little sense to me.)

Turns out it hasn't been quite 12 years; the original OpenMCL behaved like MCL in this regard. The "non-MCL-like" behavior was introduced in r7272 on 2007-09-22, probably inadvertently. So in that sense this could be considered a fix of a long-standing bug that nobody noticed until now.

I suggest we leave the fix in the trunk and see if anybody complains. We could also ask openmcl-devel to see if any existing code might be impacted, but I suspect it's unlikely. Anybody who's been calling #'directory with *.* won't notice any changes; anybody who's been calling it with * will see more (not fewer) files returned.

comment:7 Changed 11 months ago by svspire

  • Status changed from new to closed
  • Resolution set to fixed

Fixed by changeset:15778

Note: See TracTickets for help on using tickets.