CP-35625: Extract calls to unlink to helper and log

From: Mark Syms <mark.syms@citrix.com>

Signed-off-by: Mark Syms <mark.syms@citrix.com>
---
 drivers/FileSR.py |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/FileSR.py b/drivers/FileSR.py
index 596f420..f95efea 100755
--- a/drivers/FileSR.py
+++ b/drivers/FileSR.py
@@ -773,6 +773,10 @@ class FileVDI(VDI.VDI):
         util.SMlog("FileVDI._link %s to %s" % (src, dst))
         os.link(src, dst)
 
+    def _unlink(self, path):
+        util.SMlog("FileVDI._unlink %s" % (path))
+        os.unlink(path)
+
     def _snapshot(self, snap_type, cbtlog=None, cbt_consistency=None):
         util.SMlog("FileVDI._snapshot for %s (type %s)" % (self.uuid, snap_type))
 
@@ -851,7 +855,7 @@ class FileVDI(VDI.VDI):
                         (snap_type == VDI.SNAPSHOT_SINGLE or \
                         snap_type == VDI.SNAPSHOT_INTERNAL or \
                         dstparent != newuuid):
-                    util.ioretry(lambda: os.unlink(newsrc))
+                    util.ioretry(lambda: self._unlink(newsrc))
                     introduce_parent = False
             except:
                 pass
@@ -950,15 +954,15 @@ class FileVDI(VDI.VDI):
     def _clonecleanup(self,src,dst,newsrc):
         try:
             if dst:
-                util.ioretry(lambda: os.unlink(dst))
-        except util.CommandException, inst:
+                util.ioretry(lambda: self._unlink(dst))
+        except util.CommandException as inst:
             pass
         try:
             if util.ioretry(lambda: util.pathexists(newsrc)):
                 stats = os.stat(newsrc)
                 # Check if we have more than one link to newsrc
                 if (stats.st_nlink > 1):
-                    util.ioretry(lambda: os.unlink(newsrc))
+                    util.ioretry(lambda: self._unlink(newsrc))
                 elif not self._is_hidden(newsrc):
                     self._rename(newsrc, src)
         except util.CommandException as inst:
