OpenMPI  0.1.1
os_dirpath.h File Reference

Creates a directory tree set to the specified permissions. More...

#include "opal_config.h"

Go to the source code of this file.

Typedefs

typedef bool(* opal_os_dirpath_destroy_callback_fn_t )(const char *root, const char *path)
 Callback for opal_os_dirpath_destroy(). More...
 

Functions

BEGIN_C_DECLS OPAL_DECLSPEC int opal_os_dirpath_create (const char *path, const mode_t mode)
 
OPAL_DECLSPEC bool opal_os_dirpath_is_empty (const char *path)
 Check to see if a directory is empty. More...
 
OPAL_DECLSPEC int opal_os_dirpath_access (const char *path, const mode_t mode)
 Check access to the directory. More...
 
OPAL_DECLSPEC int opal_os_dirpath_destroy (const char *path, bool recursive, opal_os_dirpath_destroy_callback_fn_t cbfunc)
 Destroy a directory. More...
 

Detailed Description

Creates a directory tree set to the specified permissions.

The opal_os_dirpath_create() function creates a directory tree, with each directory that is created in the tree having the specified access permissions. Existing directories within the tree are left untouched - however, if they do not permit the user to create a directory within them, the function will return an error condition.

If the specified full path name already exists, the opal_os_dirpath_create() function will check to ensure that the final directory in the tree has at least the specified access permission. In other words, if the directory has read-write-execute for all, and the user has requested read-write access for just the user, then the function will consider the directory acceptable. If the minimal permissions are not currently provided, the function will attempt to change the access permissions of the directory to add the specified permissions. The function will return OPAL_ERROR if this cannot be done.

Typedef Documentation

typedef bool(* opal_os_dirpath_destroy_callback_fn_t)(const char *root, const char *path)

Callback for opal_os_dirpath_destroy().

Call for every file/directory before taking action to remove/unlink it.

Parameters
rootA pointer to a string that contains the base path name (e.g., /tmp/foo from /tmp/foo/bar)
pathA pointer to a string that contains the file or directory (e.g., bar from /tmp/foo/bar)
Return values
trueAllow the program to remove the file/directory
falseDo not allow the program to remove the file/directory

Function Documentation

OPAL_DECLSPEC int opal_os_dirpath_access ( const char *  path,
const mode_t  mode 
)

Check access to the directory.

Parameters
pathA pointer to a string that contains the path name to be checked.
modeA mode_t bit mask that specifies the access permissions for the directory to be accessed.
Return values
OPAL_SUCCESSIf directory exists, and permissions match
OPAL_ERR_NOT_FOUNDIf directory does not exist
OPAL_ERRORIf directory exists, and permissions do not match

Referenced by opal_os_dirpath_destroy(), and orte_session_dir().

BEGIN_C_DECLS OPAL_DECLSPEC int opal_os_dirpath_create ( const char *  path,
const mode_t  mode 
)
Parameters
pathA pointer to a string that contains the path name to be built.
modeA mode_t bit mask that specifies the access permissions for the directories being constructed.
Return values
OPAL_SUCCESSIf the directory tree has been successfully created with the specified access permissions.
OPAL_ERRORIf the directory tree could not be created with the specified access permissions.

References opal_argv_count(), opal_argv_free(), opal_argv_split(), and opal_output().

Referenced by orte_iof_base_open().

OPAL_DECLSPEC int opal_os_dirpath_destroy ( const char *  path,
bool  recursive,
opal_os_dirpath_destroy_callback_fn_t  cbfunc 
)

Destroy a directory.

Parameters
pathA pointer to a string that contains the path name to be destroyed
recursiveRecursively desend the directory removing all files and directories. if set to 'false' then the directory must be empty to succeed.
cbfuncA function that will be called before removing a file or directory. If NULL, then assume all remove.
Return values
OPAL_SUCCESSIf the directory was successfully removed or removed to the specification of the user (i.e., obeyed the callback function).
OPAL_ERR_NOT_FOUNDIf directory does not exist.
OPAL_ERRORIf the directory cannnot be removed, accessed properly, or contains directories that could not be removed..

Destroy a directory.

If the recursive variable is non-zero, then it will try to recursively remove all directories. If provided, the callback function is executed prior to the directory or file being removed. If the callback returns non-zero, then no removal is done.

References opal_os_dirpath_access(), opal_os_dirpath_is_empty(), and opal_os_path().

Referenced by orte_session_dir_cleanup(), and orte_session_dir_finalize().

OPAL_DECLSPEC bool opal_os_dirpath_is_empty ( const char *  path)

Check to see if a directory is empty.

Parameters
pathA pointer to a string that contains the path name to be checked.
Return values
trueIf the directory is empty
falseIf the directory is not empty

Referenced by opal_os_dirpath_destroy(), orte_session_dir_cleanup(), and orte_session_dir_finalize().