7f4c2a
From ae85bbe6d89744e31be374dfba7287250d93a729 Mon Sep 17 00:00:00 2001
7f4c2a
From: Saravanakumar Arumugam <sarumuga@redhat.com>
7f4c2a
Date: Fri, 17 Jul 2015 15:51:22 +0530
7f4c2a
Subject: [PATCH 306/320] tools/glusterfind: Prepend prefix in case of delete
7f4c2a
7f4c2a
In case of delete operation alone, output prefix adding
7f4c2a
was not handled earlier.
7f4c2a
Output prefix is added now.
7f4c2a
7f4c2a
Change-Id: Ia91444dddbff501b26a864f6185ca4c0aaf4c802
7f4c2a
Reviewed-on: http://review.gluster.org/11712/
7f4c2a
Reviewed-on: http://review.gluster.org/12016/
7f4c2a
BUG: 1241385
7f4c2a
Signed-off-by: Saravanakumar Arumugam <sarumuga@redhat.com>
7f4c2a
Reviewed-on: https://code.engineering.redhat.com/gerrit/56398
7f4c2a
Reviewed-by: Milind Changire <mchangir@redhat.com>
7f4c2a
Reviewed-by: Kotresh Hiremath Ravishankar <khiremat@redhat.com>
7f4c2a
Reviewed-by: Aravinda Vishwanathapura Krishna Murthy <avishwan@redhat.com>
7f4c2a
Tested-by: Aravinda Vishwanathapura Krishna Murthy <avishwan@redhat.com>
7f4c2a
---
7f4c2a
 tools/glusterfind/src/changelog.py     |   18 ++++--------------
7f4c2a
 tools/glusterfind/src/changelogdata.py |    8 ++++++--
7f4c2a
 tools/glusterfind/src/utils.py         |   13 +++++++++++++
7f4c2a
 3 files changed, 23 insertions(+), 16 deletions(-)
7f4c2a
7f4c2a
diff --git a/tools/glusterfind/src/changelog.py b/tools/glusterfind/src/changelog.py
7f4c2a
index 5939d48..4d0a190 100644
7f4c2a
--- a/tools/glusterfind/src/changelog.py
7f4c2a
+++ b/tools/glusterfind/src/changelog.py
7f4c2a
@@ -21,6 +21,7 @@ import libgfchangelog
7f4c2a
 from utils import mkdirp, symlink_gfid_to_path
7f4c2a
 from utils import fail, setup_logger, find
7f4c2a
 from utils import get_changelog_rollover_time
7f4c2a
+from utils import output_path_prepare
7f4c2a
 from changelogdata import ChangelogData
7f4c2a
 import conf
7f4c2a
 
7f4c2a
@@ -37,17 +38,6 @@ history_turn_time = 0
7f4c2a
 logger = logging.getLogger()
7f4c2a
 
7f4c2a
 
7f4c2a
-def output_path_prepare(path, output_prefix):
7f4c2a
-    """
7f4c2a
-    If Prefix is set, joins to Path, removes ending slash
7f4c2a
-    and encodes it.
7f4c2a
-    """
7f4c2a
-    if output_prefix != ".":
7f4c2a
-        path = os.path.join(output_prefix, path)
7f4c2a
-        if path.endswith("/"):
7f4c2a
-            path = path[0:len(path)-1]
7f4c2a
-
7f4c2a
-    return urllib.quote_plus(path)
7f4c2a
 
7f4c2a
 
7f4c2a
 def pgfid_to_path(brick, changelog_data):
7f4c2a
@@ -217,7 +207,7 @@ def gfid_to_path_using_batchfind(brick, changelog_data):
7f4c2a
          ignore_dirs=ignore_dirs)
7f4c2a
 
7f4c2a
 
7f4c2a
-def parse_changelog_to_db(changelog_data, filename):
7f4c2a
+def parse_changelog_to_db(changelog_data, filename, args):
7f4c2a
     """
7f4c2a
     Parses a Changelog file and populates data in gfidpath table
7f4c2a
     """
7f4c2a
@@ -240,7 +230,7 @@ def parse_changelog_to_db(changelog_data, filename):
7f4c2a
                 changelog_data.when_rename(changelogfile, data)
7f4c2a
             elif data[0] == "E" and data[2] in ["UNLINK", "RMDIR"]:
7f4c2a
                 # UNLINK/RMDIR
7f4c2a
-                changelog_data.when_unlink_rmdir(changelogfile, data)
7f4c2a
+                changelog_data.when_unlink_rmdir(changelogfile, data, args)
7f4c2a
 
7f4c2a
 
7f4c2a
 def get_changes(brick, hash_dir, log_file, start, end, args):
7f4c2a
@@ -300,7 +290,7 @@ def get_changes(brick, hash_dir, log_file, start, end, args):
7f4c2a
                 if change.endswith(".%s" % start):
7f4c2a
                     continue
7f4c2a
                 try:
7f4c2a
-                    parse_changelog_to_db(changelog_data, change)
7f4c2a
+                    parse_changelog_to_db(changelog_data, change, args)
7f4c2a
                     libgfchangelog.cl_history_done(change)
7f4c2a
                 except IOError as e:
7f4c2a
                     logger.warn("Error parsing changelog file %s: %s" %
7f4c2a
diff --git a/tools/glusterfind/src/changelogdata.py b/tools/glusterfind/src/changelogdata.py
7f4c2a
index 08d711b..39a16d5 100644
7f4c2a
--- a/tools/glusterfind/src/changelogdata.py
7f4c2a
+++ b/tools/glusterfind/src/changelogdata.py
7f4c2a
@@ -13,7 +13,7 @@ import urllib
7f4c2a
 import os
7f4c2a
 
7f4c2a
 from utils import RecordType
7f4c2a
-
7f4c2a
+from utils import output_path_prepare
7f4c2a
 
7f4c2a
 class OutputMerger(object):
7f4c2a
     """
7f4c2a
@@ -386,12 +386,16 @@ class ChangelogData(object):
7f4c2a
            not self.gfidpath_exists({"gfid": data[1], "type": "MODIFY"}):
7f4c2a
             self.gfidpath_add(changelogfile, RecordType.MODIFY, data[1])
7f4c2a
 
7f4c2a
-    def when_unlink_rmdir(self, changelogfile, data):
7f4c2a
+    def when_unlink_rmdir(self, changelogfile, data, args):
7f4c2a
         # E <GFID> <UNLINK|RMDIR> <PGFID>/<BASENAME>
7f4c2a
         pgfid1, bn1 = urllib.unquote_plus(data[3]).split("/", 1)
7f4c2a
         # Quote again the basename
7f4c2a
         bn1 = urllib.quote_plus(bn1.strip())
7f4c2a
+
7f4c2a
         deleted_path = data[4] if len(data) == 5 else ""
7f4c2a
+        if deleted_path != "":
7f4c2a
+                deleted_path = output_path_prepare(deleted_path,
7f4c2a
+                                                args.output_prefix)
7f4c2a
 
7f4c2a
         if self.gfidpath_exists({"gfid": data[1], "type": "NEW",
7f4c2a
                                  "pgfid1": pgfid1, "bn1": bn1}):
7f4c2a
diff --git a/tools/glusterfind/src/utils.py b/tools/glusterfind/src/utils.py
7f4c2a
index cda5ea6..fdf61fe 100644
7f4c2a
--- a/tools/glusterfind/src/utils.py
7f4c2a
+++ b/tools/glusterfind/src/utils.py
7f4c2a
@@ -226,3 +226,16 @@ def get_changelog_rollover_time(volumename):
7f4c2a
         return int(tree.find('volGetopts/Value').text)
7f4c2a
     except ParseError:
7f4c2a
         return DEFAULT_CHANGELOG_INTERVAL
7f4c2a
+
7f4c2a
+
7f4c2a
+def output_path_prepare(path, output_prefix):
7f4c2a
+    """
7f4c2a
+    If Prefix is set, joins to Path, removes ending slash
7f4c2a
+    and encodes it.
7f4c2a
+    """
7f4c2a
+    if output_prefix != ".":
7f4c2a
+        path = os.path.join(output_prefix, path)
7f4c2a
+        if path.endswith("/"):
7f4c2a
+            path = path[0:len(path)-1]
7f4c2a
+
7f4c2a
+    return urllib.quote_plus(path)
7f4c2a
-- 
7f4c2a
1.7.1
7f4c2a