99 * University of Stuttgart. All rights reserved.
1010 * Copyright (c) 2004-2005 The Regents of the University of California.
1111 * All rights reserved.
12- * Copyright (c) 2015 Research Organization for Information Science
12+ * Copyright (c) 2015-2017 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,17 +112,21 @@ 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. */
117- 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 );
115+ /* Now that we have the name, try to create it */
116+ mkdir (tmp , mode );
117+ ret = errno ; // save the errno for an error msg, if needed
118+ if (0 != stat (tmp , & buf )) {
119+ opal_show_help ("help-opal-util.txt" , "mkdir-failed" , true,
120+ tmp , strerror (ret ));
123121 opal_argv_free (parts );
124122 free (tmp );
125123 return OPAL_ERROR ;
124+ } else if (i == (len - 1 ) && (mode != (mode & buf .st_mode )) && (0 > chmod (tmp , (buf .st_mode | mode )))) {
125+ opal_show_help ("help-opal-util.txt" , "dir-mode" , true,
126+ tmp , mode , strerror (errno ));
127+ opal_argv_free (parts );
128+ free (tmp );
129+ return (OPAL_ERR_PERM ); /* can't set correct mode */
126130 }
127131 }
128132
@@ -263,19 +267,19 @@ bool opal_os_dirpath_is_empty(const char *path ) {
263267 struct dirent * ep ;
264268
265269 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 , ".." ))) {
270+ dp = opendir (path );
271+ if (NULL != dp ) {
272+ while ((ep = readdir (dp ))) {
273+ if ((0 != strcmp (ep -> d_name , "." )) &&
274+ (0 != strcmp (ep -> d_name , ".." ))) {
271275 closedir (dp );
272- return false;
273- }
274- }
275- closedir (dp );
276- return true;
277- }
278- return false;
276+ return false;
277+ }
278+ }
279+ closedir (dp );
280+ return true;
281+ }
282+ return false;
279283 }
280284
281285 return true;
@@ -306,4 +310,3 @@ int opal_os_dirpath_access(const char *path, const mode_t in_mode ) {
306310 return ( OPAL_ERR_NOT_FOUND );
307311 }
308312}
309-
0 commit comments