Commit 9ca803bb authored by Jérome Perrin's avatar Jérome Perrin

Do not set any TMP environment variables

This reverts daa833ea ( nexedi/slapos.recipe.cmmi!3 ) and extend it to not set `$TMP` either.

De facto, setting only `$TMP` was never effective ( see also [#20120530-132221B](https://nexedi.erp5.net/bug_module/20120530-132221B) ) and as we saw in nexedi/slapos.recipe.cmmi!3 (comment 67059) it causes more harm than good.

The conclusion so far is that environment variables related to temporary files should be handled by the parent process. The parent process is responsible for providing a directory short enough so that we can create unix sockets in `$TMPDIR`  and to clean up this directory afterwards.


In a pure buildout it could be:

```bash
tmpdir=$(mktemp -d)
trap 'rm -rf $tmpdir' SIGINT SIGTERM
TEMP=$tmpdir TMPDIR=$tmpdir TMP=$tmpdir buildout
rm -rf $tmpdir
```

/reviewed-on nexedi/slapos.recipe.cmmi!8
parents c42c6aee f101b03b
This diff is collapsed.
......@@ -144,10 +144,6 @@ class Recipe(object):
for key in self.environ:
self.environ[key] = self.environ[key] % os.environ
# Always define TMPDIR, TEMP and TMP
for key in ('TMPDIR', 'TEMP', 'TMP'):
self.environ[key] = os.path.join(options['default-location'], 'tmp')
def augmented_environment(self):
"""Returns a dictionary containing the current environment variables
augmented with the part specific overrides.
......@@ -155,6 +151,10 @@ class Recipe(object):
The dictionary is an independent copy of ``os.environ`` and
modifications will not be reflected in back in ``os.environ``.
"""
# Note that we don't set TMPDIR or TMP here as we use to do, because
# this path might be too deep and this will cause problem with some
# software (for example golang) who runs a test suite after build and
# use this TMPDIR to create unix sockets.
env = os.environ.copy()
env.update(self.environ)
return env
......@@ -342,9 +342,6 @@ class Recipe(object):
shutil.rmtree(location)
os.mkdir(location)
os.chdir(compile_dir)
tmp_path = self.environ['TMP']
shutil.rmtree(tmp_path, True)
os.mkdir(tmp_path)
if self.options['shared']:
self._signature.save(self.options["shared"])
......@@ -407,7 +404,7 @@ class Recipe(object):
and self.options['shared'] == ''
and os.path.exists(self.buildout_prefix)):
log.info('Getting installed file lists')
parts.extend(self.get_installed_files(tmp_path))
parts.extend(self.get_installed_files(compile_dir))
except:
with open('slapos.recipe.build.env.sh', 'w') as env_script:
......@@ -433,9 +430,6 @@ class Recipe(object):
raise
finally:
os.chdir(current_dir)
# If in shared mode and have error during installed, tmp_path was already deleted
if os.path.isdir(tmp_path):
shutil.rmtree(tmp_path)
# Check promises
self.check_promises(log)
......
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