From 8c61cb00ef238c129944c304eb7ac7311d6d2436 Mon Sep 17 00:00:00 2001
From: Christophe Dumez <christophe@nexedi.com>
Date: Thu, 6 Apr 2006 11:17:16 +0000
Subject: [PATCH] - used unical tmp dirs generated by tempfile.mktemp

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6480 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Subversion/SubversionClient.py    |  8 ++++++--
 product/ERP5Subversion/Tool/SubversionTool.py | 14 ++++++++++++--
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/product/ERP5Subversion/SubversionClient.py b/product/ERP5Subversion/SubversionClient.py
index 872329f235..75a67e3161 100644
--- a/product/ERP5Subversion/SubversionClient.py
+++ b/product/ERP5Subversion/SubversionClient.py
@@ -37,6 +37,7 @@ from AccessControl import ClassSecurityInfo
 from Products.ERP5Type import Permissions
 from Products.PythonScripts.Utility import allow_class
 from zLOG import LOG, WARNING
+from tempfile import mktemp
 
 try:
   import pysvn
@@ -257,8 +258,11 @@ try:
     
     def diff(self, path):
       self._getPreferences()
-      os.system('mkdir -p /tmp/tmp-svn/')
-      return self.client.diff(tmp_path='/tmp/tmp-svn/', url_or_path=path, recurse=False)
+      tmp = mktemp()
+      os.system('mkdir -p %s'%tmp)
+      diff = self.client.diff(tmp_path=tmp, url_or_path=path, recurse=False)
+      os.system('rm -rf %s'%tmp)
+      return diff
     
     def revert(self, path):
       self._getPreferences()
diff --git a/product/ERP5Subversion/Tool/SubversionTool.py b/product/ERP5Subversion/Tool/SubversionTool.py
index f11e64a9cb..857d02e324 100644
--- a/product/ERP5Subversion/Tool/SubversionTool.py
+++ b/product/ERP5Subversion/Tool/SubversionTool.py
@@ -42,6 +42,7 @@ from App.config import getConfiguration
 from zExceptions import Unauthorized
 from OFS.Image import manage_addFile
 from cStringIO import StringIO
+from tempfile import mktemp
 
 try:
   from base64 import b64encode, b64decode
@@ -83,6 +84,11 @@ class DiffFile:
   # - new_revision
 
   def __init__(self, raw_diff):
+    if '@@' not in raw_diff:
+      self.binary=True
+      return
+    else:
+      self.binary=False
     self.header = raw_diff.split('@@')[0][:-1]
     # Getting file path in header
     self.path = self.header.split('====')[0][:-1].strip()
@@ -124,6 +130,9 @@ class DiffFile:
     
   def toHTML(self):
     # Adding header of the table
+    if self.binary:
+      return '<b>Binary File!</b><br><br><br>'
+    
     html = '''
     <table style="text-align: left; width: 100%%;" border="0" cellpadding="0" cellspacing="0">
   <tbody>
@@ -577,8 +586,9 @@ class SubversionTool(UniqueObject, Folder):
           parent.sub_dirs.append(File(full_path, str(msg_status)))
     return somethingModified and root
   
-  def extractBT(self, bt, path):
-    os.system('rm -rf %s'%path)
+  def extractBT(self, bt):
+    path = mktemp()
+    #os.system('rm -rf %s'%path)
     bt.export(path=path, local=1)
     svn_path = self.getPortalObject().portal_preferences.getPreference('subversion_working_copy')
     if not svn_path :
-- 
2.30.9