Add replace flag to iso_dir_add_node().
This commit is contained in:
parent
14f4aa7d07
commit
8e7fe9b5a5
1
TODO
1
TODO
@ -10,6 +10,7 @@ TODO
|
||||
#00003 make error.h header public
|
||||
#00004 (fsource-h) -> Add a get_mime_type() function.
|
||||
#00005 (node.c) -> optimize iso_dir_iter_take.
|
||||
#00006 (libisofs.h) -> define more replace values when adding a node to a dir
|
||||
|
||||
FIXME
|
||||
=====
|
||||
|
@ -261,15 +261,23 @@ gid_t iso_node_get_gid(const IsoNode *node);
|
||||
* to other dir, and that the node name is unique inside the child.
|
||||
* Otherwise this function will return a failure, and the child won't be
|
||||
* inserted.
|
||||
* @param replace
|
||||
* if the dir already contains a node with the same name, whether to
|
||||
* replace or not the old node with this.
|
||||
* - 0 not replace (will fail with ISO_NODE_NAME_NOT_UNIQUE)
|
||||
* - 1 replace
|
||||
* 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?)
|
||||
* @return
|
||||
* number of nodes in dir if succes, < 0 otherwise
|
||||
* Possible errors:
|
||||
* ISO_NULL_POINTER, if dir or child are NULL
|
||||
* ISO_NODE_ALREADY_ADDED, if child is already added to other dir
|
||||
* ISO_NODE_NAME_NOT_UNIQUE, a node with same name already exists
|
||||
* ISO_WRONG_ARG_VALUE, if child == dir
|
||||
* ISO_WRONG_ARG_VALUE, if child == dir, or replace != (0,1)
|
||||
*/
|
||||
int iso_dir_add_node(IsoDir *dir, IsoNode *child);
|
||||
int iso_dir_add_node(IsoDir *dir, IsoNode *child, int replace);
|
||||
|
||||
/**
|
||||
* Locate a node inside a given dir.
|
||||
|
17
src/node.c
17
src/node.c
@ -161,7 +161,7 @@ gid_t iso_node_get_gid(const IsoNode *node)
|
||||
* @return
|
||||
* number of nodes in dir if succes, < 0 otherwise
|
||||
*/
|
||||
int iso_dir_add_node(IsoDir *dir, IsoNode *child)
|
||||
int iso_dir_add_node(IsoDir *dir, IsoNode *child, int replace)
|
||||
{
|
||||
IsoNode **pos;
|
||||
|
||||
@ -185,7 +185,20 @@ int iso_dir_add_node(IsoDir *dir, IsoNode *child)
|
||||
pos = &((*pos)->next);
|
||||
}
|
||||
if (*pos != NULL && !strcmp((*pos)->name, child->name)) {
|
||||
return ISO_NODE_NAME_NOT_UNIQUE;
|
||||
/* a node with same name already exists */
|
||||
if (replace == 0) {
|
||||
return ISO_NODE_NAME_NOT_UNIQUE;
|
||||
} else if (replace == 1) {
|
||||
child->next = (*pos)->next;
|
||||
(*pos)->parent = NULL;
|
||||
(*pos)->next = NULL;
|
||||
iso_node_unref(*pos);
|
||||
*pos = child;
|
||||
child->parent = dir;
|
||||
return dir->nchildren;
|
||||
} else {
|
||||
return ISO_WRONG_ARG_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
child->next = *pos;
|
||||
|
Loading…
x
Reference in New Issue
Block a user