Fix to tempdir cleanup behavior in server
The parallel support was causing problems with temp dirs. The
children process autoserv instances would 'cleanup' directories on
exit ripping files out from under the parent and other children.
Directories are only cleaned up for processes with matching pids now.
Signed-off-by: Ryan Stutsman <stutsman@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@649 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/utils.py b/server/utils.py
index 046ba53..acc57d2 100644
--- a/server/utils.py
+++ b/server/utils.py
@@ -29,8 +29,8 @@
import hosts
import errors
-
-__tmp_dirs= []
+# A dictionary of pid and a list of tmpdirs for that pid
+__tmp_dirs = {}
def sh_escape(command):
@@ -249,7 +249,10 @@
global __tmp_dirs
dir_name= tempfile.mkdtemp(prefix="autoserv-")
- __tmp_dirs.append(dir_name)
+ pid = os.getpid()
+ if not pid in __tmp_dirs:
+ __tmp_dirs[pid] = []
+ __tmp_dirs[pid].append(dir_name)
return dir_name
@@ -260,9 +263,16 @@
"""
global __tmp_dirs
- for dir in __tmp_dirs:
- shutil.rmtree(dir)
- __tmp_dirs= []
+ pid = os.getpid()
+ if pid not in __tmp_dirs:
+ return
+ for dir in __tmp_dirs[pid]:
+ try:
+ shutil.rmtree(dir)
+ except OSError, e:
+ if e.errno == 2:
+ pass
+ __tmp_dirs[pid] = []
def unarchive(host, source_material):