Blob Blame History Raw
From ae85bbe6d89744e31be374dfba7287250d93a729 Mon Sep 17 00:00:00 2001
From: Saravanakumar Arumugam <sarumuga@redhat.com>
Date: Fri, 17 Jul 2015 15:51:22 +0530
Subject: [PATCH 306/320] tools/glusterfind: Prepend prefix in case of delete

In case of delete operation alone, output prefix adding
was not handled earlier.
Output prefix is added now.

Change-Id: Ia91444dddbff501b26a864f6185ca4c0aaf4c802
Reviewed-on: http://review.gluster.org/11712/
Reviewed-on: http://review.gluster.org/12016/
BUG: 1241385
Signed-off-by: Saravanakumar Arumugam <sarumuga@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/56398
Reviewed-by: Milind Changire <mchangir@redhat.com>
Reviewed-by: Kotresh Hiremath Ravishankar <khiremat@redhat.com>
Reviewed-by: Aravinda Vishwanathapura Krishna Murthy <avishwan@redhat.com>
Tested-by: Aravinda Vishwanathapura Krishna Murthy <avishwan@redhat.com>
---
 tools/glusterfind/src/changelog.py     |   18 ++++--------------
 tools/glusterfind/src/changelogdata.py |    8 ++++++--
 tools/glusterfind/src/utils.py         |   13 +++++++++++++
 3 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/tools/glusterfind/src/changelog.py b/tools/glusterfind/src/changelog.py
index 5939d48..4d0a190 100644
--- a/tools/glusterfind/src/changelog.py
+++ b/tools/glusterfind/src/changelog.py
@@ -21,6 +21,7 @@ import libgfchangelog
 from utils import mkdirp, symlink_gfid_to_path
 from utils import fail, setup_logger, find
 from utils import get_changelog_rollover_time
+from utils import output_path_prepare
 from changelogdata import ChangelogData
 import conf
 
@@ -37,17 +38,6 @@ history_turn_time = 0
 logger = logging.getLogger()
 
 
-def output_path_prepare(path, output_prefix):
-    """
-    If Prefix is set, joins to Path, removes ending slash
-    and encodes it.
-    """
-    if output_prefix != ".":
-        path = os.path.join(output_prefix, path)
-        if path.endswith("/"):
-            path = path[0:len(path)-1]
-
-    return urllib.quote_plus(path)
 
 
 def pgfid_to_path(brick, changelog_data):
@@ -217,7 +207,7 @@ def gfid_to_path_using_batchfind(brick, changelog_data):
          ignore_dirs=ignore_dirs)
 
 
-def parse_changelog_to_db(changelog_data, filename):
+def parse_changelog_to_db(changelog_data, filename, args):
     """
     Parses a Changelog file and populates data in gfidpath table
     """
@@ -240,7 +230,7 @@ def parse_changelog_to_db(changelog_data, filename):
                 changelog_data.when_rename(changelogfile, data)
             elif data[0] == "E" and data[2] in ["UNLINK", "RMDIR"]:
                 # UNLINK/RMDIR
-                changelog_data.when_unlink_rmdir(changelogfile, data)
+                changelog_data.when_unlink_rmdir(changelogfile, data, args)
 
 
 def get_changes(brick, hash_dir, log_file, start, end, args):
@@ -300,7 +290,7 @@ def get_changes(brick, hash_dir, log_file, start, end, args):
                 if change.endswith(".%s" % start):
                     continue
                 try:
-                    parse_changelog_to_db(changelog_data, change)
+                    parse_changelog_to_db(changelog_data, change, args)
                     libgfchangelog.cl_history_done(change)
                 except IOError as e:
                     logger.warn("Error parsing changelog file %s: %s" %
diff --git a/tools/glusterfind/src/changelogdata.py b/tools/glusterfind/src/changelogdata.py
index 08d711b..39a16d5 100644
--- a/tools/glusterfind/src/changelogdata.py
+++ b/tools/glusterfind/src/changelogdata.py
@@ -13,7 +13,7 @@ import urllib
 import os
 
 from utils import RecordType
-
+from utils import output_path_prepare
 
 class OutputMerger(object):
     """
@@ -386,12 +386,16 @@ class ChangelogData(object):
            not self.gfidpath_exists({"gfid": data[1], "type": "MODIFY"}):
             self.gfidpath_add(changelogfile, RecordType.MODIFY, data[1])
 
-    def when_unlink_rmdir(self, changelogfile, data):
+    def when_unlink_rmdir(self, changelogfile, data, args):
         # E <GFID> <UNLINK|RMDIR> <PGFID>/<BASENAME>
         pgfid1, bn1 = urllib.unquote_plus(data[3]).split("/", 1)
         # Quote again the basename
         bn1 = urllib.quote_plus(bn1.strip())
+
         deleted_path = data[4] if len(data) == 5 else ""
+        if deleted_path != "":
+                deleted_path = output_path_prepare(deleted_path,
+                                                args.output_prefix)
 
         if self.gfidpath_exists({"gfid": data[1], "type": "NEW",
                                  "pgfid1": pgfid1, "bn1": bn1}):
diff --git a/tools/glusterfind/src/utils.py b/tools/glusterfind/src/utils.py
index cda5ea6..fdf61fe 100644
--- a/tools/glusterfind/src/utils.py
+++ b/tools/glusterfind/src/utils.py
@@ -226,3 +226,16 @@ def get_changelog_rollover_time(volumename):
         return int(tree.find('volGetopts/Value').text)
     except ParseError:
         return DEFAULT_CHANGELOG_INTERVAL
+
+
+def output_path_prepare(path, output_prefix):
+    """
+    If Prefix is set, joins to Path, removes ending slash
+    and encodes it.
+    """
+    if output_prefix != ".":
+        path = os.path.join(output_prefix, path)
+        if path.endswith("/"):
+            path = path[0:len(path)-1]
+
+    return urllib.quote_plus(path)
-- 
1.7.1