diff options
Diffstat (limited to 'xlators/storage/posix/src/posix-handle.c')
-rw-r--r-- | xlators/storage/posix/src/posix-handle.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/xlators/storage/posix/src/posix-handle.c b/xlators/storage/posix/src/posix-handle.c index bc34e3e5dba..5c50d413640 100644 --- a/xlators/storage/posix/src/posix-handle.c +++ b/xlators/storage/posix/src/posix-handle.c @@ -741,6 +741,7 @@ posix_handle_hard(xlator_t *this, const char *oldpath, uuid_t gfid, char *newpath = NULL; struct stat newbuf; int ret = -1; + gf_boolean_t link_exists = _gf_false; MAKE_HANDLE_ABSPATH(newpath, this, gfid); @@ -762,11 +763,15 @@ posix_handle_hard(xlator_t *this, const char *oldpath, uuid_t gfid, ret = sys_link(oldpath, newpath); if (ret) { - gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_CREATE, - "link %s -> %s" - "failed ", - oldpath, newpath); - return -1; + if (errno != EEXIST) { + gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_HANDLE_CREATE, + "link %s -> %s" + "failed ", + oldpath, newpath); + return -1; + } else { + link_exists = _gf_true; + } } ret = sys_lstat(newpath, &newbuf); @@ -775,6 +780,11 @@ posix_handle_hard(xlator_t *this, const char *oldpath, uuid_t gfid, "lstat on %s failed", newpath); return -1; } + if ((link_exists) && (!S_ISREG(newbuf.st_mode))) { + gf_msg(this->name, GF_LOG_ERROR, EINVAL, P_MSG_HANDLE_CREATE, + "%s - Expected regular file", newpath); + return -1; + } } if (newbuf.st_ino != oldbuf->st_ino || newbuf.st_dev != oldbuf->st_dev) { |