Filestore default permissions
Currently all files and directories in the filestore are created without group write permissions, which is a persistent source of irritation in the lab, where we share a single filestore. For example, the "[subject]/cache" directory is not group writeable, so if someone else created the subject and did not already run quickshow or webshow, then you cannot do so (without sudo fuckery).
Here's what I propose to solve this. (1) Create a new configuration option called "filestore_umask". If this option is blank or not present, it will default to current settings (644 for files, 755 for directories). (2) Wrap all code that writes to the filestore in blocks that set and unset the umask. (AFAIK this will include code in database.py, freesurfer.py, segment.py, mapper.py, utils.py, and mapper/init.py.. anywhere else?)
It would be possible to write a little contextmanager that would make this easy, e.g.
import os
from contextlib import contextmanager
import cortex
@contextmanager
def umask_context():
old_umask = os.umask(cortex.options.config.get("basic", "filestore_umask"))
yield
os.umask(old_umask)
# Then:
with umask_context():
# write to filestore
Is there any less tedious way to solve this? Setting the umask globally is not an option.
Talking to Fatma today, we came up with a potential (partial) fix for this. Since this issue arises most frequently with the "cache" directory in each subject, would it be awful to create local cache directories for each individual install? The location for the cache directory could be set in the options.cfg file, and that would basically contain a local version of the pycortex_store repo with ONLY the cache for each subject in it. I think it's reasonable to make each cache a local, user-specific thing, while keeping the ROI files general and shared.
Thoughts?
+1