Default Builder is now based on low level node create functions.
This commit is contained in:
parent
0ad92fc56d
commit
ea45f858cb
@ -124,7 +124,7 @@ int main(int argc, char **argv)
|
|||||||
iso_tree_set_ignore_hidden(image, 0);
|
iso_tree_set_ignore_hidden(image, 0);
|
||||||
iso_tree_set_ignore_special(image, 0);
|
iso_tree_set_ignore_special(image, 0);
|
||||||
iso_set_abort_severity("SORRY");
|
iso_set_abort_severity("SORRY");
|
||||||
iso_tree_set_report_callback(image, callback);
|
/*iso_tree_set_report_callback(image, callback);*/
|
||||||
|
|
||||||
result = iso_tree_add_dir_rec(image, iso_image_get_root(image), argv[optind]);
|
result = iso_tree_add_dir_rec(image, iso_image_get_root(image), argv[optind]);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
|
@ -102,5 +102,6 @@ int main(int argc, char **argv)
|
|||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
|
|
||||||
iso_image_unref(image);
|
iso_image_unref(image);
|
||||||
return 0;
|
iso_finish();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
132
src/builder.c
132
src/builder.c
@ -33,50 +33,45 @@ static
|
|||||||
int default_create_file(IsoNodeBuilder *builder, IsoImage *image,
|
int default_create_file(IsoNodeBuilder *builder, IsoImage *image,
|
||||||
IsoFileSource *src, IsoFile **file)
|
IsoFileSource *src, IsoFile **file)
|
||||||
{
|
{
|
||||||
int res;
|
int ret;
|
||||||
struct stat info;
|
struct stat info;
|
||||||
IsoStream *stream;
|
IsoStream *stream;
|
||||||
IsoFile *node;
|
IsoFile *node;
|
||||||
|
char *name;
|
||||||
|
|
||||||
if (builder == NULL || src == NULL || file == NULL) {
|
if (builder == NULL || src == NULL || file == NULL) {
|
||||||
return ISO_NULL_POINTER;
|
return ISO_NULL_POINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = iso_file_source_stat(src, &info);
|
ret = iso_file_source_stat(src, &info);
|
||||||
if (res < 0) {
|
if (ret < 0) {
|
||||||
return res;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this will fail if src is a dir, is not accessible... */
|
/* this will fail if src is a dir, is not accessible... */
|
||||||
res = iso_file_source_stream_new(src, &stream);
|
ret = iso_file_source_stream_new(src, &stream);
|
||||||
if (res < 0) {
|
if (ret < 0) {
|
||||||
return res;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
node = malloc(sizeof(IsoFile));
|
name = iso_file_source_get_name(src);
|
||||||
if (node == NULL) {
|
ret = iso_node_new_file(name, stream, &node);
|
||||||
|
if (ret < 0) {
|
||||||
/* the stream has taken our ref to src, so we need to add one */
|
/* the stream has taken our ref to src, so we need to add one */
|
||||||
iso_file_source_ref(src);
|
iso_file_source_ref(src);
|
||||||
iso_stream_unref(stream);
|
iso_stream_unref(stream);
|
||||||
return ISO_OUT_OF_MEM;
|
free(name);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fill node fields */
|
/* fill node fields */
|
||||||
node->node.refcount = 1;
|
iso_node_set_permissions((IsoNode*)node, info.st_mode);
|
||||||
node->node.type = LIBISO_FILE;
|
iso_node_set_uid((IsoNode*)node, info.st_uid);
|
||||||
node->node.name = iso_file_source_get_name(src);
|
iso_node_set_gid((IsoNode*)node, info.st_gid);
|
||||||
node->node.mode = S_IFREG | (info.st_mode & ~S_IFMT);
|
iso_node_set_atime((IsoNode*)node, info.st_atime);
|
||||||
node->node.uid = info.st_uid;
|
iso_node_set_mtime((IsoNode*)node, info.st_mtime);
|
||||||
node->node.gid = info.st_gid;
|
iso_node_set_ctime((IsoNode*)node, info.st_ctime);
|
||||||
node->node.atime = info.st_atime;
|
iso_node_set_uid((IsoNode*)node, info.st_uid);
|
||||||
node->node.ctime = info.st_ctime;
|
|
||||||
node->node.mtime = info.st_mtime;
|
|
||||||
node->node.hidden = 0;
|
|
||||||
node->node.parent = NULL;
|
|
||||||
node->node.next = NULL;
|
|
||||||
node->sort_weight = 0;
|
|
||||||
node->stream = stream;
|
|
||||||
node->msblock = 0;
|
|
||||||
|
|
||||||
*file = node;
|
*file = node;
|
||||||
return ISO_SUCCESS;
|
return ISO_SUCCESS;
|
||||||
@ -86,7 +81,7 @@ static
|
|||||||
int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
|
int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
|
||||||
IsoFileSource *src, IsoNode **node)
|
IsoFileSource *src, IsoNode **node)
|
||||||
{
|
{
|
||||||
int result;
|
int ret;
|
||||||
struct stat info;
|
struct stat info;
|
||||||
IsoNode *new;
|
IsoNode *new;
|
||||||
char *name;
|
char *name;
|
||||||
@ -97,12 +92,12 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
|
|||||||
|
|
||||||
/* get info about source */
|
/* get info about source */
|
||||||
if (iso_tree_get_follow_symlinks(image)) {
|
if (iso_tree_get_follow_symlinks(image)) {
|
||||||
result = iso_file_source_stat(src, &info);
|
ret = iso_file_source_stat(src, &info);
|
||||||
} else {
|
} else {
|
||||||
result = iso_file_source_lstat(src, &info);
|
ret = iso_file_source_lstat(src, &info);
|
||||||
}
|
}
|
||||||
if (result < 0) {
|
if (ret < 0) {
|
||||||
return result;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = iso_file_source_get_name(src);
|
name = iso_file_source_get_name(src);
|
||||||
@ -114,35 +109,27 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
|
|||||||
/* source is a regular file */
|
/* source is a regular file */
|
||||||
IsoStream *stream;
|
IsoStream *stream;
|
||||||
IsoFile *file;
|
IsoFile *file;
|
||||||
result = iso_file_source_stream_new(src, &stream);
|
ret = iso_file_source_stream_new(src, &stream);
|
||||||
if (result < 0) {
|
if (ret < 0) {
|
||||||
free(name);
|
break;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
/* take a ref to the src, as stream has taken our ref */
|
/* take a ref to the src, as stream has taken our ref */
|
||||||
iso_file_source_ref(src);
|
iso_file_source_ref(src);
|
||||||
file = calloc(1, sizeof(IsoFile));
|
|
||||||
if (file == NULL) {
|
/* create the file */
|
||||||
free(name);
|
ret = iso_node_new_file(name, stream, &file);
|
||||||
|
if (ret < 0) {
|
||||||
iso_stream_unref(stream);
|
iso_stream_unref(stream);
|
||||||
return ISO_OUT_OF_MEM;
|
|
||||||
}
|
}
|
||||||
file->msblock = 0;
|
|
||||||
file->sort_weight = 0;
|
|
||||||
file->stream = stream;
|
|
||||||
file->node.type = LIBISO_FILE;
|
|
||||||
new = (IsoNode*) file;
|
new = (IsoNode*) file;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case S_IFDIR:
|
case S_IFDIR:
|
||||||
{
|
{
|
||||||
/* source is a directory */
|
/* source is a directory */
|
||||||
new = calloc(1, sizeof(IsoDir));
|
IsoDir *dir;
|
||||||
if (new == NULL) {
|
ret = iso_node_new_dir(name, &dir);
|
||||||
free(name);
|
new = (IsoNode*)dir;
|
||||||
return ISO_OUT_OF_MEM;
|
|
||||||
}
|
|
||||||
new->type = LIBISO_DIR;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case S_IFLNK:
|
case S_IFLNK:
|
||||||
@ -151,18 +138,11 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
|
|||||||
char dest[PATH_MAX];
|
char dest[PATH_MAX];
|
||||||
IsoSymlink *link;
|
IsoSymlink *link;
|
||||||
|
|
||||||
result = iso_file_source_readlink(src, dest, PATH_MAX);
|
ret = iso_file_source_readlink(src, dest, PATH_MAX);
|
||||||
if (result < 0) {
|
if (ret < 0) {
|
||||||
free(name);
|
break;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
link = malloc(sizeof(IsoSymlink));
|
ret = iso_node_new_symlink(name, strdup(dest), &link);
|
||||||
if (link == NULL) {
|
|
||||||
free(name);
|
|
||||||
return ISO_OUT_OF_MEM;
|
|
||||||
}
|
|
||||||
link->dest = strdup(dest);
|
|
||||||
link->node.type = LIBISO_SYMLINK;
|
|
||||||
new = (IsoNode*) link;
|
new = (IsoNode*) link;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -173,32 +153,26 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
|
|||||||
{
|
{
|
||||||
/* source is an special file */
|
/* source is an special file */
|
||||||
IsoSpecial *special;
|
IsoSpecial *special;
|
||||||
special = malloc(sizeof(IsoSpecial));
|
ret = iso_node_new_special(name, info.st_mode, info.st_rdev,
|
||||||
if (special == NULL) {
|
&special);
|
||||||
free(name);
|
|
||||||
return ISO_OUT_OF_MEM;
|
|
||||||
}
|
|
||||||
special->dev = info.st_rdev;
|
|
||||||
special->node.type = LIBISO_SPECIAL;
|
|
||||||
new = (IsoNode*) special;
|
new = (IsoNode*) special;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
free(name);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* fill fields */
|
/* fill fields */
|
||||||
new->refcount = 1;
|
iso_node_set_permissions(new, info.st_mode);
|
||||||
new->name = name;
|
iso_node_set_uid(new, info.st_uid);
|
||||||
new->mode = info.st_mode;
|
iso_node_set_gid(new, info.st_gid);
|
||||||
new->uid = info.st_uid;
|
iso_node_set_atime(new, info.st_atime);
|
||||||
new->gid = info.st_gid;
|
iso_node_set_mtime(new, info.st_mtime);
|
||||||
new->atime = info.st_atime;
|
iso_node_set_ctime(new, info.st_ctime);
|
||||||
new->mtime = info.st_mtime;
|
iso_node_set_uid(new, info.st_uid);
|
||||||
new->ctime = info.st_ctime;
|
|
||||||
|
|
||||||
new->hidden = 0;
|
|
||||||
|
|
||||||
new->parent = NULL;
|
|
||||||
new->next = NULL;
|
|
||||||
|
|
||||||
*node = new;
|
*node = new;
|
||||||
return ISO_SUCCESS;
|
return ISO_SUCCESS;
|
||||||
|
Loading…
Reference in New Issue
Block a user