Michał Górny avatar Michał Górny committed 8e0b4e9

Use separate temporary files for BashServer.

This should handle the issue of leftover temporary files.

Comments (0)

Files changed (2)


 import shutil, subprocess, tempfile
 from gentoopm.bash import BashParser
+from gentoopm.exceptions import InvalidBashCodeError
 _bash_script = '''
 while true; do
 	def __init__(self):
-		self._tmpf = tempfile.NamedTemporaryFile('w+b')
 		self._bashproc = subprocess.Popen(['bash', '-c', _bash_script],
 			stdin = subprocess.PIPE, stdout = subprocess.PIPE,
 			env = {})
 	def __del__(self):
-		self._tmpf.close()
 	def load_file(self, envf):
-		f = self._tmpf
-		f.seek(0, 0)
-		f.truncate(0)
+		f = tempfile.NamedTemporaryFile('w+b')
 		shutil.copyfileobj(envf, f)
-				'source %s' % repr(f.name))
+				'source %s && printf "OK\\0" || printf "FAIL\\0"' % repr(f.name))
+		resp = self._read1()
+		f.close()
+		if resp != 'OK':
+			raise InvalidBashCodeError()
 	def _read1(self):
 		f = self._bashproc.stdout


 	An invalid string was passed to the atom constructor.
+	pass
+class InvalidBashCodeError(PMException):
+	"""
+	An invalid code has been passed to the bash parser.
+	"""
+	pass
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.