Commit c94489f2 authored by Julien Muchembled's avatar Julien Muchembled

runUnitTest: use symlinks to avoid dangerous copies of static files

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39577 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0cf5e636
import errno
import os import os
import shutil import shutil
import socket import socket
...@@ -9,7 +10,7 @@ from asyncore import socket_map ...@@ -9,7 +10,7 @@ from asyncore import socket_map
from ZODB.DemoStorage import DemoStorage from ZODB.DemoStorage import DemoStorage
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
from Products.ERP5Type.tests.utils import getMySQLArguments, instance_random from Products.ERP5Type.tests.utils import getMySQLArguments, instance_random
from Products.ERP5Type.tests.runUnitTest import static_dir_list from Products.ERP5Type.tests.runUnitTest import static_dir_list, WIN
def _print(message): def _print(message):
sys.stderr.write(message + "\n") sys.stderr.write(message + "\n")
...@@ -45,9 +46,12 @@ if save_mysql: ...@@ -45,9 +46,12 @@ if save_mysql:
os.system(command) os.system(command)
_print("Cleaning static files ... ") _print("Cleaning static files ... ")
for dir in static_dir_list: for static_dir in static_dir_list:
for f in glob.glob(os.path.join(instance_home, dir, '*')): static_dir = os.path.join(instance_home, static_dir)
os.remove(f) if os.path.islink(static_dir):
os.remove(static_dir)
elif os.path.exists(static_dir):
shutil.rmtree(static_dir)
if load: if load:
if save_mysql: if save_mysql:
...@@ -68,11 +72,20 @@ if load: ...@@ -68,11 +72,20 @@ if load:
else: else:
backup_path = full_path + '.bak' backup_path = full_path + '.bak'
if os.path.exists(backup_path): if os.path.exists(backup_path):
os.rmdir(full_path) if not save or WIN:
shutil.copytree(backup_path, full_path, symlinks=True) shutil.copytree(backup_path, full_path, symlinks=True)
else:
if not live_instance_path:
backup_path = os.path.basename(backup_path)
os.symlink(backup_path, full_path)
elif save and not zeo_client and os.path.exists(data_fs_path): elif save and not zeo_client and os.path.exists(data_fs_path):
os.remove(data_fs_path) os.remove(data_fs_path)
for static_dir in static_dir_list:
static_dir = os.path.join(instance_home, static_dir)
if not os.path.exists(static_dir):
os.mkdir(static_dir)
zeo_server_pid = None zeo_server_pid = None
zeo_client_pid_list = [] zeo_client_pid_list = []
......
...@@ -159,14 +159,7 @@ def initializeInstanceHome(tests_framework_home, ...@@ -159,14 +159,7 @@ def initializeInstanceHome(tests_framework_home,
old_pwd = os.getcwd() old_pwd = os.getcwd()
try: try:
os.chdir(instance_home) os.chdir(instance_home)
# Before r23751, Extensions dir was initialized to be a symlink to real for d in ('bin', 'etc', 'tests', 'var', 'log'):
# instance home Extensions folder, now it's initialized as an independant
# folder. If this test instance still have a symlink for Extensions, change
# it in a folder.
if os.path.islink('Extensions'):
os.remove('Extensions')
for d in static_dir_list + ('bin', 'etc', 'tests', 'var', 'log'):
if not os.path.exists(d): if not os.path.exists(d):
os.mkdir(d) os.mkdir(d)
for d in ('Products', 'bt5', 'svn', 'lib', 'import'): for d in ('Products', 'bt5', 'svn', 'lib', 'import'):
...@@ -571,6 +564,8 @@ def runUnitTestList(test_list, verbosity=1, debug=0): ...@@ -571,6 +564,8 @@ def runUnitTestList(test_list, verbosity=1, debug=0):
_print('Dumping static files...\n') _print('Dumping static files...\n')
live_instance_path = os.environ.get('live_instance_path') live_instance_path = os.environ.get('live_instance_path')
for static_dir in static_dir_list: for static_dir in static_dir_list:
if os.path.islink(static_dir):
continue
if live_instance_path: if live_instance_path:
backup_path = os.path.join(live_instance_path, static_dir) backup_path = os.path.join(live_instance_path, static_dir)
else: else:
...@@ -580,7 +575,7 @@ def runUnitTestList(test_list, verbosity=1, debug=0): ...@@ -580,7 +575,7 @@ def runUnitTestList(test_list, verbosity=1, debug=0):
except OSError, e: except OSError, e:
if e.errno != errno.ENOENT: if e.errno != errno.ENOENT:
raise raise
shutil.copytree(static_dir, backup_path, symlinks=True) os.rename(static_dir, backup_path)
elif zeo_client_pid_list is not None: elif zeo_client_pid_list is not None:
_print('WARNING: No static files saved. You will have to do it manually.') _print('WARNING: No static files saved. You will have to do it manually.')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment