From 82747f3c4738fa278c2ed963451642f3bc455a86 Mon Sep 17 00:00:00 2001 From: yura Date: Wed, 6 Dec 2006 19:51:59 +0000 Subject: [PATCH] ntfsmount: fix rename if destination already exists. --- ChangeLog | 1 + ntfsprogs/ntfsmount.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/ChangeLog b/ChangeLog index 99c29c35..93a547de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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. diff --git a/ntfsprogs/ntfsmount.c b/ntfsprogs/ntfsmount.c index 54470d89..39387123 100644 --- a/ntfsprogs/ntfsmount.c +++ b/ntfsprogs/ntfsmount.c @@ -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;