Set parent of a root node to point to itself.

This way we can ensure a root node is not added to another dir.
This commit is contained in:
Vreixo Formoso 2007-12-02 19:08:51 +01:00
parent c587c79220
commit f2deae8503
1 changed files with 9 additions and 1 deletions

View File

@ -164,7 +164,12 @@ int iso_dir_add_node(IsoDir *dir, IsoNode *child)
if ((IsoNode*)dir == child) { if ((IsoNode*)dir == child) {
return ISO_WRONG_ARG_VALUE; return ISO_WRONG_ARG_VALUE;
} }
if (child->parent != NULL) {
/*
* check if child is already added to another dir, or if child
* is the root node, where parent == itself
*/
if (child->parent != NULL || child->parent == (IsoDir*)child) {
return ISO_NODE_ALREADY_ADDED; return ISO_NODE_ALREADY_ADDED;
} }
@ -405,6 +410,9 @@ int iso_node_new_root(IsoDir **root)
dir->node.type = LIBISO_DIR; dir->node.type = LIBISO_DIR;
dir->node.atime = dir->node.ctime = dir->node.mtime = time(NULL); dir->node.atime = dir->node.ctime = dir->node.mtime = time(NULL);
dir->node.mode = S_IFDIR | 0555; dir->node.mode = S_IFDIR | 0555;
/* set parent to itself, to prevent root to be added to another dir */
dir->node.parent = dir;
*root = dir; *root = dir;
return ISO_SUCCESS; return ISO_SUCCESS;
} }