Cleanup the os_dirpath logic so it doesn't error out if the directory actually gets created (regardless of what mkdir returns), and pretty-prints the error if it does error out.
Signed-off-by: Ralph Castain <rhc@open-mpi.org>
Этот коммит содержится в:
родитель
a3f21fb2aa
Коммит
b257c32d2c
@ -1,6 +1,7 @@
|
||||
# -*- text -*-
|
||||
#
|
||||
# Copyright (c) 2009 Cisco Systems, Inc. All rights reserved.
|
||||
# Copyright (c) 2017 Intel, Inc. All rights reserved.
|
||||
# $COPYRIGHT$
|
||||
#
|
||||
# Additional copyrights may follow
|
||||
@ -93,3 +94,23 @@ resource:
|
||||
Limit: %s
|
||||
|
||||
Please correct the request and try again.
|
||||
#
|
||||
[dir-mode]
|
||||
While working through a directory tree, we were unable to set
|
||||
a directory to the desired mode:
|
||||
|
||||
Directory: %s
|
||||
Mode: %0x
|
||||
Error: %s
|
||||
|
||||
Please check to ensure you have adequate permissions to perform
|
||||
the desired operation.
|
||||
#
|
||||
[mkdir-failed]
|
||||
A call to mkdir was unable to create the desired directory:
|
||||
|
||||
Directory: %s
|
||||
Error: %s
|
||||
|
||||
Please check to ensure you have adequate permissions to perform
|
||||
the desired operation.
|
||||
|
@ -11,7 +11,7 @@
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2015-2016 Research Organization for Information Science
|
||||
* and Technology (RIST). All rights reserved.
|
||||
* Copyright (c) 2016 Intel, Inc. All rights reserved.
|
||||
* Copyright (c) 2016-2017 Intel, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -40,6 +40,7 @@
|
||||
|
||||
#include "opal/util/output.h"
|
||||
#include "opal/util/os_dirpath.h"
|
||||
#include "opal/util/show_help.h"
|
||||
#include "opal/util/argv.h"
|
||||
#include "opal/util/os_path.h"
|
||||
#include "opal/constants.h"
|
||||
@ -64,10 +65,8 @@ int opal_os_dirpath_create(const char *path, const mode_t mode)
|
||||
if (0 == (ret = chmod(path, (buf.st_mode | mode)))) { /* successfully change mode */
|
||||
return(OPAL_SUCCESS);
|
||||
}
|
||||
opal_output(0,
|
||||
"opal_os_dirpath_create: "
|
||||
"Error: Unable to create directory (%s), unable to set the correct mode [%d] (%s)\n",
|
||||
path, errno, strerror(errno));
|
||||
opal_show_help("help-opal-util.txt", "dir-mode", true,
|
||||
path, mode, strerror(errno));
|
||||
return(OPAL_ERR_PERM); /* can't set correct mode */
|
||||
}
|
||||
|
||||
@ -113,14 +112,11 @@ int opal_os_dirpath_create(const char *path, const mode_t mode)
|
||||
strcat(tmp, parts[i]);
|
||||
}
|
||||
|
||||
/* Now that we finally have the name to check, check it.
|
||||
Create it if it doesn't exist. */
|
||||
/* Now that we have the name, try to create it */
|
||||
ret = mkdir(tmp, mode);
|
||||
if ((0 > ret && EEXIST != errno) || 0 != stat(tmp, &buf)) {
|
||||
opal_output(0,
|
||||
"opal_os_dirpath_create: "
|
||||
"Error: Unable to create the sub-directory (%s) of (%s), mkdir failed [%d]\n",
|
||||
tmp, path, ret);
|
||||
if (0 != stat(tmp, &buf)) {
|
||||
opal_show_help("help-opal-util.txt", "mkdir-failed", true,
|
||||
tmp, strerror(errno));
|
||||
opal_argv_free(parts);
|
||||
free(tmp);
|
||||
return OPAL_ERROR;
|
||||
@ -265,19 +261,19 @@ bool opal_os_dirpath_is_empty(const char *path ) {
|
||||
struct dirent *ep;
|
||||
|
||||
if (NULL != path) { /* protect against error */
|
||||
dp = opendir(path);
|
||||
if (NULL != dp) {
|
||||
while ((ep = readdir(dp))) {
|
||||
if ((0 != strcmp(ep->d_name, ".")) &&
|
||||
(0 != strcmp(ep->d_name, ".."))) {
|
||||
dp = opendir(path);
|
||||
if (NULL != dp) {
|
||||
while ((ep = readdir(dp))) {
|
||||
if ((0 != strcmp(ep->d_name, ".")) &&
|
||||
(0 != strcmp(ep->d_name, ".."))) {
|
||||
closedir(dp);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -306,4 +302,3 @@ int opal_os_dirpath_access(const char *path, const mode_t in_mode ) {
|
||||
return( OPAL_ERR_NOT_FOUND );
|
||||
}
|
||||
}
|
||||
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user