makedirs with chown

This commit is contained in:
2018-02-16 14:03:41 +02:00
parent 46e9cea720
commit 60f040576b

View File

@@ -310,8 +310,7 @@ def get_share(name, require_auth = True):
"authenticated": authenticated "authenticated": authenticated
}) })
if not os.path.exists(share['path']): if not os.path.exists(share['path']):
os.makedirs(share['path']) makedirs_rights(share['path'])
set_rights(share['path'])
return (True,share) return (True,share)
def is_expired(share): def is_expired(share):
@@ -326,6 +325,16 @@ def print_debug(s):
sys.stderr.write(str(s)+"\n") sys.stderr.write(str(s)+"\n")
sys.stderr.flush() 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): def set_rights(path):
os.chown(path, app.config['UID'], app.config['GID']) os.chown(path, app.config['UID'], app.config['GID'])
st = os.stat(path) st = os.stat(path)