- // Unlink the target if it exists
- yaffs_Unlink(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
+ // Check if the target is an existing directory that is not empty.
+ target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
+
+ if(target &&
+ target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
+ !list_empty(&target->variant.directoryVariant.children))
+ {
+ retVal = YAFFS_FAIL;
+ }
+ else
+ {
+
+ // Unlink the target if it exists
+ removed = yaffs_Unlink(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);