mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[fix] Create parents directories with proper permissions in mkdir util
This commit is contained in:
parent
038491146f
commit
929d96fd93
2 changed files with 21 additions and 7 deletions
|
@ -8,6 +8,8 @@
|
|||
"root_required" : "You must be root to perform this action",
|
||||
"instance_already_running" : "An instance is already running",
|
||||
"error_see_log" : "An error occured. Please see the log for details.",
|
||||
"file_exists" : "File already exists: '{path}'",
|
||||
"folder_exists" : "Folder already exists: '{path}'",
|
||||
"file_not_exist" : "File does not exist",
|
||||
"folder_not_exist" : "Folder does not exist",
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import errno
|
||||
import shutil
|
||||
from pwd import getpwnam
|
||||
from grp import getgrnam
|
||||
|
@ -23,15 +24,26 @@ def mkdir(path, mode=0777, parents=False, uid=None, gid=None, force=False):
|
|||
|
||||
"""
|
||||
if os.path.exists(path) and not force:
|
||||
return
|
||||
raise OSError(errno.EEXIST, m18n.g('folder_exists', path=path))
|
||||
|
||||
if parents:
|
||||
os.makedirs(path, mode)
|
||||
else:
|
||||
os.mkdir(path, mode)
|
||||
try:
|
||||
# Create parents directories as needed
|
||||
head, tail = os.path.split(path)
|
||||
if not tail:
|
||||
head, tail = path.split(head)
|
||||
if head and tail and not os.path.exists(head):
|
||||
try:
|
||||
mkdir(head, mode, parents, uid, gid, force)
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
if tail == os.curdir:
|
||||
return
|
||||
|
||||
# Create directory and set permissions
|
||||
os.mkdir(path, mode)
|
||||
if uid is not None or gid is not None:
|
||||
chown(path, uid, gid)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def chown(path, uid=None, gid=None, recursive=False):
|
||||
|
|
Loading…
Reference in a new issue