Remove Rainbow, avoid race in creating directories
Sugar depended on Rainbow for clearing the activity instance/ and tmp/ directories. But Rainbow is no longer used downstream. - remove support for Rainbow, - avoid race when creating directories; don't check they exist before we create.
This commit is contained in:
parent
a1371b5f94
commit
8d4298ee9e
@ -38,6 +38,7 @@ import os
|
|||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
import pwd
|
import pwd
|
||||||
|
import shutil
|
||||||
|
|
||||||
_SHELL_SERVICE = 'org.laptop.Shell'
|
_SHELL_SERVICE = 'org.laptop.Shell'
|
||||||
_SHELL_PATH = '/org/laptop/Shell'
|
_SHELL_PATH = '/org/laptop/Shell'
|
||||||
@ -67,26 +68,30 @@ def create_activity_id():
|
|||||||
return util.unique_id()
|
return util.unique_id()
|
||||||
|
|
||||||
|
|
||||||
|
def _mkdir(path):
|
||||||
|
try:
|
||||||
|
os.mkdir(path)
|
||||||
|
except OSError, e:
|
||||||
|
if e.errno != EEXIST:
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def get_environment(activity):
|
def get_environment(activity):
|
||||||
environ = os.environ.copy()
|
environ = os.environ.copy()
|
||||||
|
|
||||||
bin_path = os.path.join(activity.get_path(), 'bin')
|
bin_path = os.path.join(activity.get_path(), 'bin')
|
||||||
|
|
||||||
activity_root = env.get_profile_path(activity.get_bundle_id())
|
activity_root = env.get_profile_path(activity.get_bundle_id())
|
||||||
if not os.path.exists(activity_root):
|
_mkdir(activity_root)
|
||||||
os.mkdir(activity_root)
|
|
||||||
|
|
||||||
data_dir = os.path.join(activity_root, 'instance')
|
instance_dir = os.path.join(activity_root, 'instance')
|
||||||
if not os.path.exists(data_dir):
|
_mkdir(instance_dir)
|
||||||
os.mkdir(data_dir)
|
|
||||||
|
|
||||||
data_dir = os.path.join(activity_root, 'data')
|
data_dir = os.path.join(activity_root, 'data')
|
||||||
if not os.path.exists(data_dir):
|
_mkdir(data_dir)
|
||||||
os.mkdir(data_dir)
|
|
||||||
|
|
||||||
tmp_dir = os.path.join(activity_root, 'tmp')
|
tmp_dir = os.path.join(activity_root, 'tmp')
|
||||||
if not os.path.exists(tmp_dir):
|
_mkdir(tmp_dir)
|
||||||
os.mkdir(tmp_dir)
|
|
||||||
|
|
||||||
environ['SUGAR_BUNDLE_PATH'] = activity.get_path()
|
environ['SUGAR_BUNDLE_PATH'] = activity.get_path()
|
||||||
environ['SUGAR_BUNDLE_ID'] = activity.get_bundle_id()
|
environ['SUGAR_BUNDLE_ID'] = activity.get_bundle_id()
|
||||||
@ -222,30 +227,6 @@ class ActivityCreationHandler(GObject.GObject):
|
|||||||
self._handle.object_id, self._handle.uri,
|
self._handle.object_id, self._handle.uri,
|
||||||
self._handle.invited)
|
self._handle.invited)
|
||||||
|
|
||||||
environment_dir = None
|
|
||||||
if os.path.exists('/etc/olpc-security') \
|
|
||||||
and os.access('/usr/bin/rainbow-run', os.X_OK):
|
|
||||||
environment_dir = tempfile.mkdtemp()
|
|
||||||
command = ['sudo', '-E', '--',
|
|
||||||
'rainbow-run',
|
|
||||||
'-v', '-v',
|
|
||||||
'-a', 'rainbow-sugarize',
|
|
||||||
'-s', '/var/spool/rainbow/2',
|
|
||||||
'-f', '1',
|
|
||||||
'-f', '2',
|
|
||||||
'-c', self._bundle.get_path(),
|
|
||||||
'-u', pwd.getpwuid(os.getuid()).pw_name,
|
|
||||||
'-i', environ['SUGAR_BUNDLE_ID'],
|
|
||||||
'-e', environment_dir,
|
|
||||||
'--',
|
|
||||||
] + command
|
|
||||||
|
|
||||||
for key, value in environ.items():
|
|
||||||
file_path = os.path.join(environment_dir, str(key))
|
|
||||||
open(file_path, 'w').write(str(value))
|
|
||||||
|
|
||||||
log_file.write(' '.join(command) + '\n\n')
|
|
||||||
|
|
||||||
dev_null = file('/dev/null', 'r')
|
dev_null = file('/dev/null', 'r')
|
||||||
child = subprocess.Popen([str(s) for s in command],
|
child = subprocess.Popen([str(s) for s in command],
|
||||||
env=environ,
|
env=environ,
|
||||||
@ -257,7 +238,7 @@ class ActivityCreationHandler(GObject.GObject):
|
|||||||
|
|
||||||
GObject.child_watch_add(child.pid,
|
GObject.child_watch_add(child.pid,
|
||||||
_child_watch_cb,
|
_child_watch_cb,
|
||||||
(environment_dir, log_file,
|
(log_file,
|
||||||
self._handle.activity_id))
|
self._handle.activity_id))
|
||||||
|
|
||||||
def _no_reply_handler(self, *args):
|
def _no_reply_handler(self, *args):
|
||||||
@ -319,11 +300,7 @@ def create_with_object_id(bundle, object_id):
|
|||||||
|
|
||||||
|
|
||||||
def _child_watch_cb(pid, condition, user_data):
|
def _child_watch_cb(pid, condition, user_data):
|
||||||
# FIXME we use standalone method here instead of ActivityCreationHandler's
|
log_file, activity_id = user_data
|
||||||
# member to have workaround code, see #1123
|
|
||||||
environment_dir, log_file, activity_id = user_data
|
|
||||||
if environment_dir is not None:
|
|
||||||
subprocess.call(['/bin/rm', '-rf', environment_dir])
|
|
||||||
|
|
||||||
if os.WIFEXITED(condition):
|
if os.WIFEXITED(condition):
|
||||||
status = os.WEXITSTATUS(condition)
|
status = os.WEXITSTATUS(condition)
|
||||||
|
Loading…
Reference in New Issue
Block a user