Add new replace modes.

This commit is contained in:
Vreixo Formoso 2008-01-26 21:52:42 +01:00
parent 0131ce5ff0
commit 3528f9d0ef
4 changed files with 66 additions and 18 deletions

View File

@ -109,26 +109,28 @@ int main(int argc, char **argv)
} }
iso_read_opts_free(ropts); iso_read_opts_free(ropts);
iso_tree_set_replace_mode(image, ISO_REPLACE_IF_NEWER);
/* add new dir */ /* add new dir */
result = iso_tree_add_dir_rec(image, iso_image_get_root(image), argv[2]); result = iso_tree_add_dir_rec(image, iso_image_get_root(image), argv[2]);
if (result < 0) { if (result < 0) {
printf ("Error adding directory %d\n", result); printf ("Error adding directory %d\n", result);
return 1; return 1;
} }
/* generate a multisession image with new contents */ /* generate a multisession image with new contents */
result = iso_write_opts_new(&opts, 1); result = iso_write_opts_new(&opts, 1);
if (result < 0) { if (result < 0) {
printf("Cant create write opts, error %d\n", result); printf("Cant create write opts, error %d\n", result);
return 1; return 1;
} }
/* round up to 32kb aligment = 16 block */ /* round up to 32kb aligment = 16 block */
ms_block = ((features->size + 15) / 16 ) * 16; ms_block = ((features->size + 15) / 16 ) * 16;
iso_write_opts_set_ms_block(opts, ms_block); iso_write_opts_set_ms_block(opts, ms_block);
iso_write_opts_set_appendable(opts, 1); iso_write_opts_set_appendable(opts, 1);
iso_write_opts_set_overwrite_buf(opts, buf); iso_write_opts_set_overwrite_buf(opts, buf);
free(features); free(features);
result = iso_image_create_burn_source(image, opts, &burn_src); result = iso_image_create_burn_source(image, opts, &burn_src);

View File

@ -85,10 +85,22 @@ enum iso_replace_mode {
/** /**
* Always replace the old node with the new. * Always replace the old node with the new.
*/ */
ISO_REPLACE_ALWAYS ISO_REPLACE_ALWAYS,
/**
* Replace with the new node if it is the same file type
*/
ISO_REPLACE_IF_SAME_TYPE,
/**
* Replace with the new node if it is the same file type and its ctime
* is newer than the old one.
*/
ISO_REPLACE_IF_SAME_TYPE_AND_NEWER,
/**
* Replace with the new node if its ctime is newer than the old one.
*/
ISO_REPLACE_IF_NEWER
/* /*
* TODO #00006 define more values * TODO #00006 define more values
* -to replace only if both are the same kind of file
* -if both are dirs, add contents (and what to do with conflicts?) * -if both are dirs, add contents (and what to do with conflicts?)
*/ */
}; };

View File

@ -704,20 +704,42 @@ int iso_dir_insert(IsoDir *dir, IsoNode *node, IsoNode **pos,
{ {
if (*pos != NULL && !strcmp((*pos)->name, node->name)) { if (*pos != NULL && !strcmp((*pos)->name, node->name)) {
/* a node with same name already exists */ /* a node with same name already exists */
if (replace == ISO_REPLACE_NEVER) { switch(replace) {
case ISO_REPLACE_NEVER:
return ISO_NODE_NAME_NOT_UNIQUE; return ISO_NODE_NAME_NOT_UNIQUE;
} else if (replace == ISO_REPLACE_ALWAYS) { case ISO_REPLACE_IF_NEWER:
node->next = (*pos)->next; if ((*pos)->mtime >= node->mtime) {
(*pos)->parent = NULL; /* old file is newer */
(*pos)->next = NULL; return ISO_NODE_NAME_NOT_UNIQUE;
iso_node_unref(*pos); }
*pos = node; break;
node->parent = dir; case ISO_REPLACE_IF_SAME_TYPE_AND_NEWER:
return dir->nchildren; if ((*pos)->mtime >= node->mtime) {
} else { /* old file is newer */
return ISO_NODE_NAME_NOT_UNIQUE;
}
/* fall down */
case ISO_REPLACE_IF_SAME_TYPE:
if ((node->mode & S_IFMT) != ((*pos)->mode & S_IFMT)) {
/* different file types */
return ISO_NODE_NAME_NOT_UNIQUE;
}
break;
case ISO_REPLACE_ALWAYS:
break;
default:
/* CAN'T HAPPEN */ /* CAN'T HAPPEN */
return ISO_ASSERT_FAILURE; return ISO_ASSERT_FAILURE;
} }
/* if we are reach here we have to replace */
node->next = (*pos)->next;
(*pos)->parent = NULL;
(*pos)->next = NULL;
iso_node_unref(*pos);
*pos = node;
node->parent = dir;
return dir->nchildren;
} }
node->next = *pos; node->next = *pos;

View File

@ -555,12 +555,24 @@ int iso_add_dir_src_rec(IsoImage *image, IsoDir *parent, IsoFileSource *dir)
ret = iso_msg_submit(image->id, ISO_FILE_CANT_ADD, ret, ret = iso_msg_submit(image->id, ISO_FILE_CANT_ADD, ret,
"Error when adding file %s", path); "Error when adding file %s", path);
goto dir_rec_continue; goto dir_rec_continue;
} else {
iso_msg_debug(image->id, "Adding file %s", path);
} }
/* ok, node has correctly created, we need to add it */ /* ok, node has correctly created, we need to add it */
iso_dir_insert(parent, new, pos, replace); ret = iso_dir_insert(parent, new, pos, replace);
if (ret < 0) {
iso_node_unref(new);
if (ret != ISO_NODE_NAME_NOT_UNIQUE) {
/* error */
goto dir_rec_continue;
} else {
/* file ignored because a file with same node already exists */
iso_msg_debug(image->id, "Skipping file %s. A node with same "
"file already exists", path);
ret = 0;
}
} else {
iso_msg_debug(image->id, "Added file %s", path);
}
/* finally, if the node is a directory we need to recurse */ /* finally, if the node is a directory we need to recurse */
if (new->type == LIBISO_DIR && S_ISDIR(info.st_mode)) { if (new->type == LIBISO_DIR && S_ISDIR(info.st_mode)) {