On Thu, Sep 11, 2003 at 08:36:02PM +0300, Vladimir Lipskiy wrote:
> > Famous last words: "Our data is perfect, we don't need to check our
> inputs."
>
> Yes. Our data is perfect and we don't need to check our inputs if we
> play by rules. And the rules are:
>
> Always use concat_dirnames to concatenate directory names
> Always use append_filename to append a file name to a path
> Always keep in mind that this tool gives you a proper result
> when you give it proper input, which is simple directory
> names, simple file names, and paths produced by this tool only.
> If you observe the rules, you won't get into a mess.
People make mistakes. Perhaps you should produce some errors if a user
strays outside these rules. Garbage in, garbage out: Bad. Garbage in,
error out: Good.
I'll admit to not knowing the general error philosophy of Parrot ops.
> > Ok, but what happens when I pass filepaths with volumes attached to
> > concat_dirnames?
>
> You get what you do, nonsense. Even File::Spec, a tool of a lot more
> higher level, doesn't protect you from such things.
>
> D:\>perl -MFile::Spec::Functions -e "print catdir('C:\hh','C:\dd'), qq(\n)"
> C:\hh\C:\dd
Justifying your own tool's bad behavior using another tool's bad behavior
is not a terribly compelling design argument. Just because File::Spec's
handling of volumes is historicly lousy doesn't mean yours has to be.
> >What if the volumes don't match?
>
> Don't match against what? concat_dirnames doesn't do matching arguments
> against anything but PARROT_FS_DIRNAME_START and PARROT_FS_DIRNAME_END,
> which, for example, are '[' and ']' on VMS.
What if I feed you:
concat_dirnames("VOL1:[dir.dir]", "VOL2:[dir.dir]")
Well, I suppose that's simple, its an error since you can't usefully
concatenate two absolute directories. Anyhow, the point is is an *error*.
> > What if I'm adding a path with a volume to one without?
>
> Still. You get what you do. On Mac:
>
> concat_dirnames('my disk:a', ':b') = ':my disk:a:b'
Mac's a special case since, IIRC, :b can either mean "The volume called b"
or "The file/directory in the current directory called b". On VMS or
Windows no such ambiguity exists.
But I was unclear. I meant the other way around.
concat_dirnames("b", ":my disk:a");
Trying to concatenate an absolute directory onto a relative one should
produce an error.
> File::Spec has an individual function for such purposes, catpath().
> We can't process more than two in-arguments in PASM, so we would take
> advantage of prepend_volume and things of such sort.
Unless I'm missing something, since the volumes and root dirs are already
attached to the filepath string, you don't need more than two arguments.
--
Michael G Schwern [EMAIL PROTECTED] http://www.pobox.com/~schwern/
It's Ecstacy time!