Commit a095eb9d7165c3e5eb67762b6de68adb2384c842

Paul Eggert 2005-09-22T23:24:03

* mkdir-p.c (ENOSYS): Define to EEXIST if not defined. (make_dir_parents): Treat ENOSYS like EEXIST. Improve quality of diagnostics on restore_cwd failure. * mkdir-p.h (make_dir): Remove. All uses replaced by mkdir. (make_dir_parents): Last arg is now int * (for errno), not bool *. * mkdir-p.c (make_dir, make_dir_parents): Likewise. Rewrite "mkdir -p" algorithm to avoid the need for "stat" each time through the loop. Do not diagnose restore_cwd failure; that is the caller's job (and perhaps the caller does not care). * mkdir-p.c (CLEANUP_CWD, CLEANUP): Remove. (make_dir_parents): Revamp to avoid need for CLEANUP_CWD, CLEANUP. If the file already exists but is not a directory, don't bother to try to make its parents. Close potential file descriptor leak if we can't chdir("/") (!). Don't always return true if chdir($PWD) fails; return true only if the requested action was done successfully (except for the chdir($PWD)). Don't log final directory unless we actually made it. Refactor to avoid duplicate code to fix up permissions. Don't attempt to fix up parent permissions if chdir($PWD) fails. * mkdir-p.c (make_dir_parents): Don't let a failed chdir($PWD) stop us from restricting permissions of just-created absolute-named directories. * mkdir-p.c (CLEANUP_CWD): Return *true*, not false when failing to restore initial working directory. * mkdir-p.c (make_dir_parents): New parameter: different_working_dir, to tell caller if/when we change the working directory and are unable to return to the initial one. * mkdir-p.h (make_dir_parents): Update prototype. * mkdir-p.c (CLEANUP_CWD): Change one more `return 1' to `return false'. This fixes a bug introduced on 2004-07-30. Assume HAVE_UNISTD_H, i.e., include <unistd.h> unconditionally. Assume HAVE_FCNTL_H (i.e., include <fcntl.h> unconditionally, and don't include <sys/file.h>).