struct yaffs_obj *olddir = NULL;
struct yaffs_obj *newdir = NULL;
struct yaffs_obj *obj = NULL;
+ struct yaffs_obj *newobj = NULL;
YCHAR *oldname;
YCHAR *newname;
int result= YAFFS_FAIL;
olddir = yaffsfs_FindDirectory(NULL,oldPath,&oldname,0,¬OldDir);
newdir = yaffsfs_FindDirectory(NULL,newPath,&newname,0,¬NewDir);
obj = yaffsfs_FindObject(NULL,oldPath,0,0,NULL,NULL);
+ newobj = yaffsfs_FindObject(NULL,newPath,0,0,NULL,NULL);
/* If the object being renamed is a directory and the
* path ended with a "/" then the olddir == obj.
} else if(obj->my_dev->read_only){
yaffsfs_SetError(-EROFS);
rename_allowed = 0;
+ } else if(yaffs_is_non_empty_dir(newobj)){
+ yaffsfs_SetError(-ENOTEMPTY);
+ rename_allowed = 0;
} else if(olddir->my_dev != newdir->my_dev) {
/* Rename must be on same device */
yaffsfs_SetError(-EXDEV);
/* Now do the handling for an existing target, if there is one */
existing_target = yaffs_find_by_name(new_dir, new_name);
- if (existing_target &&
- existing_target->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY
- && !list_empty(&existing_target->variant.dir_variant.
- children)) {
- /* There is a target that is a non-empty directory, so we fail */
- return YAFFS_FAIL; /* EEXIST or ENOTEMPTY */
+ if (yaffs_is_non_empty_dir(existing_target)){
+ return YAFFS_FAIL; /* ENOTEMPTY */
} else if (existing_target && existing_target != obj) {
/* Nuke the target first, using shadowing,
* but only if it isn't the same object.
}
}
-static int yaffs_is_non_empty_dir(struct yaffs_obj *obj)
+int yaffs_is_non_empty_dir(struct yaffs_obj *obj)
{
- return (obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) &&
- !(list_empty(&obj->variant.dir_variant.children));
+ return (obj &&
+ obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) &&
+ !(list_empty(&obj->variant.dir_variant.children));
}
static int yaffs_del_dir(struct yaffs_obj *obj)