Fix extfs rename between directories.

This commit is contained in:
Jonas 'Sortie' Termansen 2014-10-04 23:30:12 +02:00
parent 2492f0bad7
commit 26c9b266b8
2 changed files with 4 additions and 3 deletions

View File

@ -593,7 +593,7 @@ void HandleRename(int svr, int chl, struct fsm_req_rename* msg, Filesystem* fs)
const char* oldname = path;
const char* newname = path + msg->oldnamelen + 1;
Inode* olddir = fs->GetInode((uint32_t) msg->newdirino);
Inode* olddir = fs->GetInode((uint32_t) msg->olddirino);
if ( !olddir ) { free(path); RespondError(svr, chl, errno); return; }
Inode* newdir = fs->GetInode((uint32_t) msg->newdirino);
if ( !newdir ) { olddir->Unref(); free(path); RespondError(svr, chl, errno); return; }

View File

@ -714,9 +714,10 @@ bool Inode::Rename(Inode* olddir, const char* oldname, const char* newname)
return false;
if ( Inode* dst_inode = Open(newname, O_RDONLY, 0) )
{
if ( src_inode->inode_id == dst_inode->inode_id )
return dst_inode->Unref(), src_inode->Unref(), 0;
bool same_inode = src_inode->inode_id == dst_inode->inode_id;
dst_inode->Unref();
if ( same_inode )
return src_inode->Unref(), true;
}
// TODO: Prove that this cannot fail and handle such a situation.
if ( EXT2_S_ISDIR(src_inode->Mode()) )