From 60f040576ba63811b53541aec90761998286b95d Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Fri, 16 Feb 2018 14:03:41 +0200 Subject: [PATCH] makedirs with chown --- code/app.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/code/app.py b/code/app.py index 99866e8..370fbfb 100644 --- a/code/app.py +++ b/code/app.py @@ -310,8 +310,7 @@ def get_share(name, require_auth = True): "authenticated": authenticated }) if not os.path.exists(share['path']): - os.makedirs(share['path']) - set_rights(share['path']) + makedirs_rights(share['path']) return (True,share) def is_expired(share): @@ -326,6 +325,16 @@ def print_debug(s): sys.stderr.write(str(s)+"\n") sys.stderr.flush() +def makedirs_rights(path): + # os.makedirs with chown + path_list = path.split(os.sep) + for p in range(len(path_list)): + current_path = os.sep.join(path_list[0:(p+1)]) + if not os.path.exist(current_path): + os.mkdir(current_path) + set_rights(current_path) + + def set_rights(path): os.chown(path, app.config['UID'], app.config['GID']) st = os.stat(path)