libpts: Use path_base|dirname()

This commit is contained in:
Tobias Brunner
2014-02-24 12:04:11 +01:00
parent 9222d58634
commit 6b895d7b25
4 changed files with 18 additions and 14 deletions
+6 -5
View File
@@ -266,19 +266,20 @@ static void do_args(int argc, char *argv[])
continue; continue;
case 'F': case 'F':
{ {
char *path = strdup(optarg); char *dir = path_dirname(optarg);
char *dir = dirname(path); char *file = path_basename(optarg);
char *file = basename(optarg);
if (*dir != '.') if (*dir != '.')
{ {
if (!attest->set_directory(attest, dir, op == OP_ADD)) if (!attest->set_directory(attest, dir, op == OP_ADD))
{ {
free(path); free(file);
free(dir);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
free(path); free(file);
free(dir);
if (!attest->set_file(attest, file, op == OP_ADD)) if (!attest->set_file(attest, file, op == OP_ADD))
{ {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
+1 -1
View File
@@ -627,7 +627,7 @@ METHOD(pts_t, get_metadata, pts_file_meta_t*,
metadata->destroy(metadata); metadata->destroy(metadata);
return NULL; return NULL;
} }
entry->filename = strdup(basename(pathname)); entry->filename = path_basename(pathname);
metadata->add(metadata, entry); metadata->add(metadata, entry);
} }
+9 -7
View File
@@ -249,7 +249,7 @@ METHOD(pts_database_t, check_file_measurement, status_t,
enumerator_t *e; enumerator_t *e;
chunk_t hash; chunk_t hash;
status_t status = NOT_FOUND; status_t status = NOT_FOUND;
char *path, *dir, *file; char *dir, *file;
if (strlen(filename) < 1) if (strlen(filename) < 1)
{ {
@@ -257,9 +257,8 @@ METHOD(pts_database_t, check_file_measurement, status_t,
} }
/* separate filename into directory and basename components */ /* separate filename into directory and basename components */
path = strdup(filename); dir = path_dirname(filename);
dir = dirname(path); file = path_basename(filename);
file = basename(filename);
if (*dir == '.') if (*dir == '.')
{ /* relative pathname */ { /* relative pathname */
@@ -281,7 +280,8 @@ METHOD(pts_database_t, check_file_measurement, status_t,
DB_TEXT, dir, DB_INT); DB_TEXT, dir, DB_INT);
if (!e) if (!e)
{ {
free(path); free(file);
free(dir);
return FAILED; return FAILED;
} }
dir_found = e->enumerate(e, &did); dir_found = e->enumerate(e, &did);
@@ -289,7 +289,8 @@ METHOD(pts_database_t, check_file_measurement, status_t,
if (!dir_found) if (!dir_found)
{ {
free(path); free(file);
free(dir);
return NOT_FOUND; return NOT_FOUND;
} }
@@ -301,7 +302,8 @@ METHOD(pts_database_t, check_file_measurement, status_t,
DB_TEXT, product, DB_INT, did, DB_TEXT, file, DB_INT, algo, DB_TEXT, product, DB_INT, did, DB_TEXT, file, DB_INT, algo,
DB_BLOB); DB_BLOB);
} }
free(path); free(file);
free(dir);
if (!e) if (!e)
{ {
+2 -1
View File
@@ -341,9 +341,10 @@ pts_file_meas_t *pts_file_meas_create_from_path(u_int16_t request_id,
success = FALSE; success = FALSE;
goto end; goto end;
} }
filename = use_rel_name ? basename(pathname) : pathname; filename = use_rel_name ? path_basename(pathname) : strdup(pathname);
DBG2(DBG_PTS, " %#B for '%s'", &measurement, filename); DBG2(DBG_PTS, " %#B for '%s'", &measurement, filename);
add(this, filename, measurement); add(this, filename, measurement);
free(filename);
} }
end: end: