mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-24 07:06:41 +00:00
Only read magic-folder config from config reader
Also, fix the umask feature which was completely broken previously due to failure to parse the umask string into an integer.
This commit is contained in:
parent
0bdabacce3
commit
ac6269dd2d
@ -606,7 +606,7 @@ class _Client(node.Node, pollmixin.PollMixin):
|
||||
collective_dircap=mf_config["collective_dircap"],
|
||||
local_path_u=abspath_expanduser_unicode(local_dir_config, base=self.basedir),
|
||||
dbfile=abspath_expanduser_unicode(db_filename),
|
||||
umask=self.get_config("magic_folder", "download.umask", 0077),
|
||||
umask=mf_config["umask"],
|
||||
name=name,
|
||||
downloader_delay=poll_interval,
|
||||
)
|
||||
|
@ -30,6 +30,9 @@ from allmydata.immutable.upload import FileName, Data
|
||||
from allmydata import magicfolderdb, magicpath
|
||||
|
||||
|
||||
# Mask off all non-owner permissions for magic-folders files by default.
|
||||
_DEFAULT_DOWNLOAD_UMASK = 0o077
|
||||
|
||||
IN_EXCL_UNLINK = 0x04000000L
|
||||
|
||||
def get_inotify_module():
|
||||
@ -157,11 +160,17 @@ def load_magic_folders(node_directory):
|
||||
)
|
||||
)
|
||||
|
||||
if config.has_option("magic_folder", "download.umask"):
|
||||
umask = int(config.get("magic_folder", "download.umask"), 8)
|
||||
else:
|
||||
umask = _DEFAULT_DOWNLOAD_UMASK
|
||||
|
||||
folders[u"default"] = {
|
||||
u"directory": directory,
|
||||
u"upload_dircap": fileutil.read(up_fname),
|
||||
u"collective_dircap": fileutil.read(coll_fname),
|
||||
u"poll_interval": interval,
|
||||
u"umask": umask,
|
||||
}
|
||||
else:
|
||||
# without any YAML file AND no local.directory option it's
|
||||
@ -213,6 +222,12 @@ def load_magic_folders(node_directory):
|
||||
if isinstance(mf_config[k], unicode):
|
||||
mf_config[k] = mf_config[k].encode('ascii')
|
||||
|
||||
if not isinstance(
|
||||
mf_config.setdefault(u"umask", _DEFAULT_DOWNLOAD_UMASK),
|
||||
int,
|
||||
):
|
||||
raise Exception("magic-folder download umask must be an integer")
|
||||
|
||||
return folders
|
||||
|
||||
|
||||
|
@ -65,6 +65,7 @@ class NewConfigUtilTests(unittest.TestCase):
|
||||
def test_load(self):
|
||||
folders = magic_folder.load_magic_folders(self.basedir)
|
||||
self.assertEqual(['default'], list(folders.keys()))
|
||||
self.assertEqual(folders['default'][u'umask'], 0o077)
|
||||
|
||||
def test_both_styles_of_config(self):
|
||||
os.unlink(join(self.basedir, u"private", u"magic_folders.yaml"))
|
||||
@ -115,6 +116,23 @@ class NewConfigUtilTests(unittest.TestCase):
|
||||
str(ctx.exception)
|
||||
)
|
||||
|
||||
def test_wrong_umask_obj(self):
|
||||
"""
|
||||
If a umask is given for a magic-folder that is not an integer, an
|
||||
exception is raised.
|
||||
"""
|
||||
self.folders[u"default"][u"umask"] = "0077"
|
||||
yaml_fname = join(self.basedir, u"private", u"magic_folders.yaml")
|
||||
with open(yaml_fname, "w") as f:
|
||||
f.write(yamlutil.safe_dump({u"magic-folders": self.folders}))
|
||||
|
||||
with self.assertRaises(Exception) as ctx:
|
||||
magic_folder.load_magic_folders(self.basedir)
|
||||
self.assertIn(
|
||||
"umask must be an integer",
|
||||
str(ctx.exception)
|
||||
)
|
||||
|
||||
def test_wrong_sub_obj(self):
|
||||
yaml_fname = join(self.basedir, u"private", u"magic_folders.yaml")
|
||||
with open(yaml_fname, "w") as f:
|
||||
|
Loading…
Reference in New Issue
Block a user