From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7300df8db68b4232 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: more Ada.Directories questions Date: Fri, 1 Apr 2011 20:34:05 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1301708047 32252 69.95.181.76 (2 Apr 2011 01:34:07 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Sat, 2 Apr 2011 01:34:07 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5931 Path: g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!feed.ac-versailles.fr!news.ecp.fr!news.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail Xref: g2news1.google.com comp.lang.ada:18679 Date: 2011-04-01T20:34:05-05:00 List-Id: "Adam Beneschan" wrote in message news:a2b3581f-47a5-47a1-84f9-28fb819f7284@n2g2000prj.googlegroups.com... >On Mar 31, 10:49 pm, tmo...@acm.org wrote: >> Does Ada.Directories.Create_Directory("X"); raise Use_Error if directory >> X >> already exists? It seems it should if the system does not support >> creation of something that already exists. (On Windows at least, mkdir x >> fails if x already exists.) Ditto if file "X" exists and the system won't >> allow a file and a directory of the same name. Does "Create" mean "change >> the state of the file system" or does it mean "arrange that the file >> system has a certain state"? Create_Directory apparently means the >> former. >> >> Apparently the latter meaning applies to Create_Path, since >> according to the Rationale, Ada.Directories.Create_Path("X"); >> does not raise Use_Error, but is a NOP, if directory X exists. > >I wonder if this was the intent. If you say Create_Path("/a/b/c"), >then clearly the intent is to create /a and /a/b if they don't exist, >but use the existing ones if they do. I'm not certain that that was >supposed to apply to the final directory name, /a/b/c. The description of Create_Path starts out "Creates zero or more directories...". So it seems pretty clear that it can do nothing when it is called. I know that I expect it to be usable as a precaution (that is, call this just in case the directory doesn't exist). It sort of is an assertion that this directory exists; and that's how I tend to use it. Note that since these operations intrinsicly have race conditions (with other things going on a machine), testing for existence and creating only if it fails is not certain to work, so having a single routine to do the entire operation is better. >> If "???" is an illegal name for a directory, it seems that >> Create_Path("a/b/???/c"); will raise Name_Error without creating "a/b". >> Correct? >I don't think the RM is clear on this. In fact, it may be unfeasible >to implement Create_Path in a way that doesn't attempt to create >earlier directories before finding out that a later one has a bad >name, if the implementation depends on the OS to tell it whether a >name is bad or not. In fact, this raises another question: suppose a/ >b cannot be created for some reason (no permission), then does the >above Create_Path call raise Use_Error or Name_Error? My guess is >"not specified by the language". While I doubt that there will be an ACATS test for it, the language seems reasonably clear that Name_Error is tested first - for the whole string. It's mentioned first, and it is described as a test on the whole string. I think there would be some argument that that is over-specification, and I don't see any great reason to insist on it (thus no ACATS test). I do hope that you won't turn this answer into an Ada-Comment; you already have introduced many of the least important AIs ever... :-) Randy. -- Adam