1
1

Merge pull request #2755 from rhc54/topic/session

Update and cleanup os_dirpath
Этот коммит содержится в:
Ralph Castain 2017-01-18 13:57:44 -08:00 коммит произвёл GitHub
родитель ec51ba3133 b257c32d2c
Коммит d1880d8ba1
2 изменённых файлов: 41 добавлений и 30 удалений

Просмотреть файл

@ -1,6 +1,7 @@
# -*- text -*- # -*- text -*-
# #
# Copyright (c) 2009 Cisco Systems, Inc. All rights reserved. # Copyright (c) 2009 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2017 Intel, Inc. All rights reserved.
# $COPYRIGHT$ # $COPYRIGHT$
# #
# Additional copyrights may follow # Additional copyrights may follow
@ -93,3 +94,23 @@ resource:
Limit: %s Limit: %s
Please correct the request and try again. 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. * All rights reserved.
* Copyright (c) 2015-2016 Research Organization for Information Science * Copyright (c) 2015-2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved. * and Technology (RIST). All rights reserved.
* Copyright (c) 2016 Intel, Inc. All rights reserved. * Copyright (c) 2016-2017 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -40,6 +40,7 @@
#include "opal/util/output.h" #include "opal/util/output.h"
#include "opal/util/os_dirpath.h" #include "opal/util/os_dirpath.h"
#include "opal/util/show_help.h"
#include "opal/util/argv.h" #include "opal/util/argv.h"
#include "opal/util/os_path.h" #include "opal/util/os_path.h"
#include "opal/constants.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 */ if (0 == (ret = chmod(path, (buf.st_mode | mode)))) { /* successfully change mode */
return(OPAL_SUCCESS); return(OPAL_SUCCESS);
} }
opal_output(0, opal_show_help("help-opal-util.txt", "dir-mode", true,
"opal_os_dirpath_create: " path, mode, strerror(errno));
"Error: Unable to create directory (%s), unable to set the correct mode [%d] (%s)\n",
path, errno, strerror(errno));
return(OPAL_ERR_PERM); /* can't set correct mode */ return(OPAL_ERR_PERM); /* can't set correct mode */
} }
@ -113,19 +112,11 @@ int opal_os_dirpath_create(const char *path, const mode_t mode)
strcat(tmp, parts[i]); strcat(tmp, parts[i]);
} }
/* Now that we finally have the name to check, check it. /* Now that we have the name, try to create it */
Create it if it doesn't exist. */
ret = mkdir(tmp, mode); ret = mkdir(tmp, mode);
if ((0 > ret && EEXIST != errno) || 0 != stat(tmp, &buf)) { if (0 != stat(tmp, &buf)) {
if (0 > ret && EEXIST != errno) { opal_show_help("help-opal-util.txt", "mkdir-failed", true,
opal_output(0, "opal_os_dirpath_create: " tmp, strerror(errno));
"Error: Unable to create the sub-directory (%s) of (%s), mkdir failed [%d] (%s)]\n",
tmp, path, errno, strerror(errno));
} else {
opal_output(0, "opal_os_dirpath_create: "
"Error: Unable to stat the sub-directory (%s) of (%s), mkdir failed [%d] (%s)]\n",
tmp, path, errno, strerror(errno));
}
opal_argv_free(parts); opal_argv_free(parts);
free(tmp); free(tmp);
return OPAL_ERROR; return OPAL_ERROR;
@ -270,19 +261,19 @@ bool opal_os_dirpath_is_empty(const char *path ) {
struct dirent *ep; struct dirent *ep;
if (NULL != path) { /* protect against error */ if (NULL != path) { /* protect against error */
dp = opendir(path); dp = opendir(path);
if (NULL != dp) { if (NULL != dp) {
while ((ep = readdir(dp))) { while ((ep = readdir(dp))) {
if ((0 != strcmp(ep->d_name, ".")) && if ((0 != strcmp(ep->d_name, ".")) &&
(0 != strcmp(ep->d_name, ".."))) { (0 != strcmp(ep->d_name, ".."))) {
closedir(dp); closedir(dp);
return false; return false;
} }
} }
closedir(dp); closedir(dp);
return true; return true;
} }
return false; return false;
} }
return true; return true;
@ -311,4 +302,3 @@ int opal_os_dirpath_access(const char *path, const mode_t in_mode ) {
return( OPAL_ERR_NOT_FOUND ); return( OPAL_ERR_NOT_FOUND );
} }
} }