1111 * All rights reserved.
1212 * Copyright (c) 2015 Research Organization for Information Science
1313 * and Technology (RIST). All rights reserved.
14+ * Copyright (c) 2016-2017 Intel, Inc. All rights reserved.
1415 * $COPYRIGHT$
1516 *
1617 * Additional copyrights may follow
3940
4041#include "opal/util/output.h"
4142#include "opal/util/os_dirpath.h"
43+ #include "opal/util/show_help.h"
4244#include "opal/util/argv.h"
4345#include "opal/util/os_path.h"
4446#include "opal/constants.h"
@@ -63,11 +65,9 @@ int opal_os_dirpath_create(const char *path, const mode_t mode)
6365 if (0 == (ret = chmod (path , (buf .st_mode | mode )))) { /* successfully change mode */
6466 return (OPAL_SUCCESS );
6567 }
66- opal_output (0 ,
67- "opal_os_dirpath_create: "
68- "Error: Unable to create directory (%s), unable to set the correct mode [%d]\n" ,
69- path , ret );
70- return (OPAL_ERROR ); /* can't set correct mode */
68+ opal_show_help ("help-opal-util.txt" , "dir-mode" , true,
69+ path , mode , strerror (errno ));
70+ return (OPAL_ERR_PERM ); /* can't set correct mode */
7171 }
7272
7373 /* quick -- try to make directory */
@@ -112,14 +112,11 @@ int opal_os_dirpath_create(const char *path, const mode_t mode)
112112 strcat (tmp , parts [i ]);
113113 }
114114
115- /* Now that we finally have the name to check, check it.
116- Create it if it doesn't exist. */
115+ /* Now that we have the name, try to create it */
117116 ret = mkdir (tmp , mode );
118- if ((0 > ret && EEXIST != errno ) || 0 != stat (tmp , & buf )) {
119- opal_output (0 ,
120- "opal_os_dirpath_create: "
121- "Error: Unable to create the sub-directory (%s) of (%s), mkdir failed [%d]\n" ,
122- tmp , path , ret );
117+ if (0 != stat (tmp , & buf )) {
118+ opal_show_help ("help-opal-util.txt" , "mkdir-failed" , true,
119+ tmp , strerror (errno ));
123120 opal_argv_free (parts );
124121 free (tmp );
125122 return OPAL_ERROR ;
@@ -263,19 +260,19 @@ bool opal_os_dirpath_is_empty(const char *path ) {
263260 struct dirent * ep ;
264261
265262 if (NULL != path ) { /* protect against error */
266- dp = opendir (path );
267- if (NULL != dp ) {
268- while ((ep = readdir (dp ))) {
269- if ((0 != strcmp (ep -> d_name , "." )) &&
270- (0 != strcmp (ep -> d_name , ".." ))) {
263+ dp = opendir (path );
264+ if (NULL != dp ) {
265+ while ((ep = readdir (dp ))) {
266+ if ((0 != strcmp (ep -> d_name , "." )) &&
267+ (0 != strcmp (ep -> d_name , ".." ))) {
271268 closedir (dp );
272- return false;
273- }
274- }
275- closedir (dp );
276- return true;
277- }
278- return false;
269+ return false;
270+ }
271+ }
272+ closedir (dp );
273+ return true;
274+ }
275+ return false;
279276 }
280277
281278 return true;
@@ -306,4 +303,3 @@ int opal_os_dirpath_access(const char *path, const mode_t in_mode ) {
306303 return ( OPAL_ERR_NOT_FOUND );
307304 }
308305}
309-
0 commit comments