[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Issue: CREATE-DIRECTORY
I don't see a problem about any of the gotchas you mentioned, and
if we frame this functionality right, I don't think users will see
any problems either. I believe the following is the shape of what
we're looking for...
CREATE-DIRECTORY pathname => exists-p, existed-p
Attempts to assure that the directory in which the pathname
does or would reside is in existence.
If the directory existed prior to the call, no action is taken
and the values T, T are returned.
If the directory did not exist, an attempt is made to create
it. If the attempt succeeds, the returned values are T, NIL;
otherwise, the returned values are NIL, NIL.
NO-SUCH-DIRECTORY Condition (subtype of FILE-ERROR)
A condition of this type is signaled by functions such as OPEN,
PROBE-FILE, RENAME-FILE, etc. when an attempt is made to
open a file in a directory that does not exist. The name of
the file upon which the open was attempted is accessible from
FILE-ERROR-PATHNAME. It is conventional in functions such as
OPEN, etc. for a CONTINUE restart to be provided, so that the
file operation can be retried once the situation has been corrected.
Typical use:
(DEFUN AUTO-CREATE-DIRECTORY (CONDITION)
(LET ((R (FIND-RESTART 'CONTINUE CONDITION)))
(WHEN (AND R (CREATE-DIRECTORY (FILE-ERROR-PATHNAME CONDITION)))
(INVOKE-RESTART R))))
(DEFUN RENAME-FILE-CREATING-DIRECTORY-IF-NECESSARY-AND-POSSIBLE
(OLD-NAME NEW-NAME)
(CONDITION-BIND ((NO-SUCH-DIRECTORY #'AUTO-CREATE-DIRECTORY))
(RENAME-FILE OLD-NAME NEW-NAME)))
Note that if the directory creation fails, you'll end up in the debugger
in the RENAME-FILE, so the concern you had about how this would just
lead to more errors is moot--you're in exactly the same debugger break
as you'd have been in if this functionality hadn't been added. But if
the attempt to create the directory succeeds, your program continues to
run much farther than it might have been able to.
If your concern is that directory attributes won't be set correctly
upon creation, that's already a concern if the user created the directory
outside of Lisp, too. The user either has to worry about that or he
doesn't, but the vendor can certainly figure out how to set the default
attributes conservatively. The most important thing is only that the
creator have access to the newly created dir--which is certainly the
default in most file systems I know of. So the likelihood of falling
through to code which doesn't have the right accesses is very small.