* more Ada.Directories questions @ 2011-04-01 5:49 tmoran 2011-04-01 15:27 ` Adam Beneschan 0 siblings, 1 reply; 3+ messages in thread From: tmoran @ 2011-04-01 5:49 UTC (permalink / raw) 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. So the only reason to use Create_Directory rather than Create_Path is to detect the case where a file or directory of that name already exists, correct? 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? ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: more Ada.Directories questions 2011-04-01 5:49 more Ada.Directories questions tmoran @ 2011-04-01 15:27 ` Adam Beneschan 2011-04-02 1:34 ` Randy Brukardt 0 siblings, 1 reply; 3+ messages in thread From: Adam Beneschan @ 2011-04-01 15:27 UTC (permalink / raw) 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. > So the only reason to use Create_Directory rather than Create_Path is > to detect the case where a file or directory of that name already > exists, correct? Incorrect, I think. Create_Path will create other directories along the path if they don't exist, and that may not be what you want. Suppose Arg is a command-line argument and I want to say something like Create_Directory (Arg & "/Work_Directory"); [actually, I'd use other routines to create the path name instead of "&", but that's not relevant to my point]. If Arg includes a directory component that doesn't exist because it's misspelled, I'd want Create_Directory to fail---not to go ahead and create a new misspelled path. > 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". -- Adam ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: more Ada.Directories questions 2011-04-01 15:27 ` Adam Beneschan @ 2011-04-02 1:34 ` Randy Brukardt 0 siblings, 0 replies; 3+ messages in thread From: Randy Brukardt @ 2011-04-02 1:34 UTC (permalink / raw) "Adam Beneschan" <adam@irvine.com> 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 ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-04-02 1:34 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2011-04-01 5:49 more Ada.Directories questions tmoran 2011-04-01 15:27 ` Adam Beneschan 2011-04-02 1:34 ` Randy Brukardt
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox