Skip to content

Commit 854119e

Browse files
authored
Merge pull request #2756 from rhc54/cmr20x/session
Cleanup the os_dirpath logic
2 parents 9ec026b + de539e0 commit 854119e

File tree

2 files changed

+51
-27
lines changed

2 files changed

+51
-27
lines changed

opal/util/help-opal-util.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- text -*-
22
#
33
# Copyright (c) 2009 Cisco Systems, Inc. All rights reserved.
4+
# Copyright (c) 2017 Intel, Inc. All rights reserved.
45
# $COPYRIGHT$
56
#
67
# Additional copyrights may follow
@@ -93,3 +94,23 @@ resource:
9394
Limit: %s
9495

9596
Please correct the request and try again.
97+
#
98+
[dir-mode]
99+
While working through a directory tree, we were unable to set
100+
a directory to the desired mode:
101+
102+
Directory: %s
103+
Mode: %0x
104+
Error: %s
105+
106+
Please check to ensure you have adequate permissions to perform
107+
the desired operation.
108+
#
109+
[mkdir-failed]
110+
A call to mkdir was unable to create the desired directory:
111+
112+
Directory: %s
113+
Error: %s
114+
115+
Please check to ensure you have adequate permissions to perform
116+
the desired operation.

opal/util/os_dirpath.c

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
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
@@ -39,6 +40,7 @@
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

Comments
 (0)