ntfsmount: fix rename if destination already exists.

edge.strict_endians
yura 2006-12-06 19:51:59 +00:00
parent c475778b47
commit 82747f3c47
2 changed files with 28 additions and 0 deletions

View File

@ -98,6 +98,7 @@ xx/xx/2006 - x.xx.x - .
- Turn ntfs_pathname_to_inode() into ntfs_pathname_to_inode_num() which
returns ntfs inode number instead of opened inode itself.
Reimplement ntfs_pathname_to_inode() as wrapper to new API. (Yura)
- ntfsmount: fix rename if destination already exists. (Yura)
21/06/2006 - 1.13.1 - Various fixes.

View File

@ -1013,9 +1013,36 @@ static int ntfs_fuse_unlink(const char *org_path)
static int ntfs_fuse_rename(const char *old_path, const char *new_path)
{
int ret;
u64 inum_new, inum_old;
/* Check whether destination already exists. */
if ((inum_new = ntfs_pathname_to_inode_num(ctx->vol, NULL, new_path)) !=
(u64)-1) {
if (errno != ENOENT)
return -errno;
/*
* If source and destination belongs to the same inode, then
* just unlink source if mount is case sensitive or return
* -EINVAL if mount is case insensitive, because of a lot of
* brain damaged cases here. Anyway coreutils is broken for
* case sensitive filesystems.
*
* If source and destination belongs to different inodes, then
* unlink current destination, so we can create link to source.
*/
inum_old = ntfs_pathname_to_inode_num(ctx->vol, NULL, old_path);
if (inum_old == inum_new) {
if (NVolCaseSensitive(ctx->vol))
goto unlink;
else
return -EINVAL;
} else
if ((ret = ntfs_fuse_unlink(new_path)))
return ret;
}
if ((ret = ntfs_fuse_link(old_path, new_path)))
return ret;
unlink:
if ((ret = ntfs_fuse_unlink(old_path))) {
ntfs_fuse_unlink(new_path);
return ret;