diff options
author | Jan Synacek <jsynacek@redhat.com> | 2013-09-18 08:33:03 +0200 |
---|---|---|
committer | Jan Synacek <jsynacek@redhat.com> | 2013-09-18 15:19:30 +0200 |
commit | cd13c983a49ce3685a3813e66001bd3ea8f796c8 (patch) | |
tree | c79386678dbfdbfbdbbccb48d690f7cd3f475c50 /src/logicalfile/LMI_DirectoryContainsFileProvider.c | |
parent | 2746832524f5e5d022b13ffa0890f895ab82355c (diff) | |
download | openlmi-providers-cd13c983a49ce3685a3813e66001bd3ea8f796c8.tar.gz openlmi-providers-cd13c983a49ce3685a3813e66001bd3ea8f796c8.tar.xz openlmi-providers-cd13c983a49ce3685a3813e66001bd3ea8f796c8.zip |
logicalfile: code cleanup and rewrite
GetInstance() calls were rewritten using cleaner code. Also, the macros
that were used before were either rewritten to functions, or cleaned up
so they wouldn't return or do anything unexpected.
Helper functions now use CMPIStatus more consistently.
Some memory leaks were fixed.
Diffstat (limited to 'src/logicalfile/LMI_DirectoryContainsFileProvider.c')
-rw-r--r-- | src/logicalfile/LMI_DirectoryContainsFileProvider.c | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/src/logicalfile/LMI_DirectoryContainsFileProvider.c b/src/logicalfile/LMI_DirectoryContainsFileProvider.c index 427c2a6..06bc7b9 100644 --- a/src/logicalfile/LMI_DirectoryContainsFileProvider.c +++ b/src/logicalfile/LMI_DirectoryContainsFileProvider.c @@ -90,10 +90,16 @@ static CMPIStatus dir_file_objectpaths( CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, err); } else { get_class_from_stat(&sb, fileclass); - check_assoc_class(_cb, namespace, resultClass, fileclass); - if (get_fsname_from_stat(&sb, &fsname) < 0) { + st = check_assoc_class(_cb, namespace, resultClass, fileclass); + check_class_check_status(st); + if (st.rc != CMPI_RC_OK) { closedir(dp); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name"); + return st; + } + st = get_fsname_from_stat(_cb, &sb, &fsname); + if (st.rc != CMPI_RC_OK) { + closedir(dp); + return st; } } @@ -155,7 +161,8 @@ static CMPIStatus associators( if (st.rc != CMPI_RC_OK) { return st; } - check_assoc_class(_cb, ns, assocClass, LMI_DirectoryContainsFile_ClassName); + st = check_assoc_class(_cb, ns, assocClass, LMI_DirectoryContainsFile_ClassName); + check_class_check_status(st); /* allow only LMI_UnixFile and classes derived from CIM_LogicalFile */ if (!check_valid_classes(cop)) { CMReturn(CMPI_RC_OK); @@ -200,6 +207,8 @@ static CMPIStatus associators( CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, "Too many files in a single directory..."); } + /* TODO: directories are walked in two passes + * rewrite using only one pass */ for (unsigned int i = 0; i < count; i++) { if (names) { CMReturnObjectPath(cr, refs[i]); @@ -210,21 +219,24 @@ static CMPIStatus associators( } } else { /* got LogicalFile - PartComponent */ + if (group == 1 || rgroup == 0) { + CMReturn(CMPI_RC_OK); + } + st = check_assoc_class(_cb, ns, resultClass, LMI_UnixDirectory_ClassName); + check_class_check_status(st); + CIM_DirectoryRef lmi_dr; CIM_DirectoryRef_Init(&lmi_dr, _cb, ns); char *aux = strdup(path); char *dir = dirname(aux); char *fsname; - if (group == 1 || rgroup == 0) { - CMReturn(CMPI_RC_OK); - } - check_assoc_class(_cb, ns, resultClass, LMI_UnixDirectory_ClassName); - - if (get_fsname_from_path(dir, &fsname) < 0) { + st = get_fsname_from_path(_cb, path, &fsname); + if (st.rc != CMPI_RC_OK) { free(aux); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name"); + return st; } + fill_logicalfile(CIM_DirectoryRef, &lmi_dr, dir, fsname, LMI_UnixDirectory_ClassName); o = CIM_DirectoryRef_ToObjectPath(&lmi_dr, &st); CMSetClassName(o, LMI_UnixDirectory_ClassName); @@ -263,7 +275,8 @@ static CMPIStatus references( CMPIInstance *ci; int group = -1; - check_assoc_class(_cb, ns, assocClass, LMI_DirectoryContainsFile_ClassName); + st = check_assoc_class(_cb, ns, assocClass, LMI_DirectoryContainsFile_ClassName); + check_class_check_status(st); /* allow only LMI_UnixFile and classes derived from CIM_LogicalFile */ if (!check_valid_classes(cop)) { CMReturn(CMPI_RC_OK); @@ -278,9 +291,7 @@ static CMPIStatus references( } } st = lmi_check_required(_cb, cop); - if (st.rc != CMPI_RC_OK) { - return st; - } + check_status(st); CIM_DirectoryRef_Init(&lmi_dr, _cb, ns); CIM_LogicalFileRef_Init(&lmi_lfr, _cb, ns); @@ -289,9 +300,8 @@ static CMPIStatus references( const char *ccname = get_string_property_from_op(cop, "CreationClassName"); const char *path = get_string_property_from_op(cop, "Name"); char *fsname; - if (get_fsname_from_path(path, &fsname) < 0) { - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name"); - } + st = get_fsname_from_path(_cb, path, &fsname); + check_status(st); if (strcmp(ccname, LMI_UnixDirectory_ClassName) == 0) { /* got GroupComponent - DirectoryRef */ @@ -304,12 +314,12 @@ static CMPIStatus references( CMPIObjectPath *refs[MAX_REFS]; unsigned int count; st = dir_file_objectpaths(cc, cr, NULL, group, -1, properties, ns, path, refs, &count); - if (st.rc != CMPI_RC_OK) { - return st; - } + check_status(st); if (count > MAX_REFS) { CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, "Too many files in a single directory..."); } + /* TODO: directories are walked in two passes + * rewrite using only one pass */ for (unsigned int i = 0; i < count; i++) { LMI_DirectoryContainsFile_SetObjectPath_PartComponent(&lmi_dcf, refs[i]); o = LMI_DirectoryContainsFile_ToObjectPath(&lmi_dcf, &st); @@ -335,9 +345,10 @@ static CMPIStatus references( char *aux = strdup(path); char *dir = dirname(aux); char *fsname; - if (get_fsname_from_path(dir, &fsname) < 0) { + st = get_fsname_from_path(_cb, dir, &fsname); + if (st.rc != CMPI_RC_OK) { free(aux); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name"); + return st; } fill_logicalfile(CIM_DirectoryRef, &lmi_dr, dir, fsname, LMI_UnixDirectory_ClassName); |