Blob Blame History Raw
From a5ff2e613a5d0b2c2bf126ed16f3e36b0351c770 Mon Sep 17 00:00:00 2001
From: Aravinda VK <avishwan@redhat.com>
Date: Wed, 10 Aug 2016 14:02:09 +0530
Subject: [PATCH 198/206] geo-rep: Handle EISDIR error during Unlink

During Rename, If Source and Target has same inode then
Geo-rep unlinks source. But if source is a directory then
this will fail with below traceback

Traceback (most recent call last):
  File "/usr/libexec/glusterfs/python/syncdaemon/repce.py", line 113, in worker
    res = getattr(self.obj, rmeth)(*in_data[2:])
  File "/usr/libexec/glusterfs/python/syncdaemon/resource.py", line 772,
    in entry_ops
    os.unlink(entry)
OSError: [Errno 21] Is a directory: '.gfid/12711ebf-7fdc-4f4b-9850-2d75581eb
   452/New folder'

With this patch, if EISDIR, rmdir is tried. Logs error in Slave log in case
of ENOTEMPTY.

> Reviewed-on: http://review.gluster.org/15132
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Kotresh HR <khiremat@redhat.com>

BUG: 1385589
Change-Id: I099af4192adac5125c0a23988ceb6506f91e987f
Signed-off-by: Aravinda VK <avishwan@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/91362
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 geo-replication/syncdaemon/resource.py | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/geo-replication/syncdaemon/resource.py b/geo-replication/syncdaemon/resource.py
index 5cf5eb0..f3ce463 100644
--- a/geo-replication/syncdaemon/resource.py
+++ b/geo-replication/syncdaemon/resource.py
@@ -781,7 +781,23 @@ class Server(object):
                     else:
                         if st.st_ino == st1.st_ino:
                             # we have a hard link, we can now unlink source
-                            os.unlink(entry)
+                            try:
+                                os.unlink(entry)
+                            except OSError as e:
+                                if e.errno == EISDIR:
+                                    try:
+                                        os.rmdir(entry)
+                                    except OSError as e:
+                                        if e.errno == ENOTEMPTY:
+                                            logging.error(
+                                                "Unable to delete directory "
+                                                "{0}, Both Old({1}) and New{2}"
+                                                " directories exists".format(
+                                                    entry, entry, en))
+                                        else:
+                                            raise
+                                else:
+                                    raise
                         else:
                             rename_with_disk_gfid_confirmation(gfid, entry, en)
             if blob:
-- 
2.9.3