From baf7f14b11382eac0f1e3c6f7d4ceb365ed4a438 Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Date: Mon, 31 Dec 2007 16:27:08 +0100 Subject: [PATCH] Change get_path() definition in IsoFileSource. --- src/fs_local.c | 7 +++---- src/fsource.h | 8 ++++---- src/stream.c | 2 +- src/tree.c | 26 +++++++++++++------------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/fs_local.c b/src/fs_local.c index 3613db6..3330282 100644 --- a/src/fs_local.c +++ b/src/fs_local.c @@ -12,6 +12,7 @@ #include "fsource.h" #include "error.h" +#include "util.h" #include #include @@ -32,8 +33,6 @@ IsoFilesystem *lfs= NULL; typedef struct { - /* IsoFilesystem *fs; It seems not needed */ - char *path; unsigned int openned :2; /* 0: not openned, 1: file, 2:dir */ union @@ -44,11 +43,11 @@ typedef struct } _LocalFsFileSource; static -const char* lfs_get_path(IsoFileSource *src) +char* lfs_get_path(IsoFileSource *src) { _LocalFsFileSource *data; data = src->data; - return data->path; + return strdup(data->path); } static diff --git a/src/fsource.h b/src/fsource.h index e2c1433..5dfc463 100644 --- a/src/fsource.h +++ b/src/fsource.h @@ -76,10 +76,10 @@ typedef struct IsoFileSource_Iface * belongs to. * * @return - * the path, that belong to the IsoFileSource and should not be - * freed by the user. + * the path of the FileSource inside the filesystem, it should be + * freed when no more needed. */ - const char* (*get_path)(IsoFileSource *src); + char* (*get_path)(IsoFileSource *src); /** * Get the name of the file, with the dir component of the path. @@ -266,7 +266,7 @@ void iso_file_source_unref(IsoFileSource *src); * this are just helpers to invoque methods in class */ extern inline -const char* iso_file_source_get_path(IsoFileSource *src) +char* iso_file_source_get_path(IsoFileSource *src) { return src->class->get_path(src); } diff --git a/src/stream.c b/src/stream.c index 3d1c34f..417628c 100644 --- a/src/stream.c +++ b/src/stream.c @@ -118,7 +118,7 @@ char *fsrc_get_name(IsoStream *stream) { FSrcStreamData *data; data = (FSrcStreamData*)stream->data; - return strdup(iso_file_source_get_path(data->src)); + return iso_file_source_get_path(data->src); } static diff --git a/src/tree.c b/src/tree.c index 26376d9..b80af75 100644 --- a/src/tree.c +++ b/src/tree.c @@ -460,8 +460,9 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir) result = iso_file_source_open(dir); if (result < 0) { - iso_msg_debug(image->messenger, "Can't open dir %s", - iso_file_source_get_path(dir)); + char *path = iso_file_source_get_path(dir); + iso_msg_debug(image->messenger, "Can't open dir %s", path); + free(path); return result; } @@ -469,24 +470,23 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir) action = 1; while ( (result = iso_file_source_readdir(dir, &file)) == 1) { int flag; - char *name; + char *name, *path; IsoNode *new; name = iso_file_source_get_name(file); + path = iso_file_source_get_path(file); - if (check_excludes(image, iso_file_source_get_path(file))) { - iso_msg_debug(image->messenger, "Skipping excluded file %s", - iso_file_source_get_path(file)); + if (check_excludes(image, path)) { + iso_msg_debug(image->messenger, "Skipping excluded file %s", path); action = 2; } else if (check_hidden(image, name)) { - iso_msg_debug(image->messenger, "Skipping hidden file %s", - iso_file_source_get_path(file)); + iso_msg_debug(image->messenger, "Skipping hidden file %s", path); action = 2; } else { - iso_msg_debug(image->messenger, "Adding file %s", - iso_file_source_get_path(file)); + iso_msg_debug(image->messenger, "Adding file %s", path); action = 1; } + free(path); /* find place where to insert */ flag = 0; @@ -522,10 +522,10 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir) /* ok, file will be added */ result = builder->create_node(builder, image, file, &new); if (result < 0) { - + char *path = iso_file_source_get_path(file); iso_msg_note(image->messenger, LIBISO_FILE_IGNORED, - "Error %d when adding file %s", result, - iso_file_source_get_path(file)); + "Error %d when adding file %s", result, path); + free(path); if (image->recOpts.report) { action = image->recOpts.report(file, result, flag);