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