added safe mkdir in utils, use utils.mkdir_safe() in backup
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
"""Backup script for pre-installed instance"""
|
"""Backup script for pre-installed instance"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import pwd
|
||||||
import shutil
|
import shutil
|
||||||
|
import stat
|
||||||
|
|
||||||
from .. import database
|
from .. import database
|
||||||
from .. import utils
|
from .. import utils
|
||||||
@@ -31,8 +33,9 @@ class Backup():
|
|||||||
|
|
||||||
|
|
||||||
def preparePath(self):
|
def preparePath(self):
|
||||||
|
pw = pwd.getpwnam("root")
|
||||||
for dir in self.BACKUPDIRECTORY:
|
for dir in self.BACKUPDIRECTORY:
|
||||||
utils.mkdir(self.destinationPath + dir)
|
utils.mkdir_safe(self.destinationPath + dir, stat.S_IRWXU | stat.S_IRWXG, pw[2], pw[3])
|
||||||
|
|
||||||
|
|
||||||
def validatePath(self, path):
|
def validatePath(self, path):
|
||||||
@@ -49,7 +52,8 @@ class Backup():
|
|||||||
createDir = input(f"\"{path}\" doesn't exists, would you like to create it ? [Y/n]\n").lower()
|
createDir = input(f"\"{path}\" doesn't exists, would you like to create it ? [Y/n]\n").lower()
|
||||||
|
|
||||||
if createDir == "y" or createDir == "yes":
|
if createDir == "y" or createDir == "yes":
|
||||||
os.mkdir(path)
|
pw = pwd.getpwnam("root")
|
||||||
|
utils.mkdir_safe(path, stat.S_IRWXU | stat.S_IRWXG, pw[2], pw[3])
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,11 @@ def mkdir(path, mode, uid, gid):
|
|||||||
os.chmod(path, mode)
|
os.chmod(path, mode)
|
||||||
os.chown(path, uid, gid)
|
os.chown(path, uid, gid)
|
||||||
|
|
||||||
|
def mkdir_safe(path, mode, uid, gid):
|
||||||
|
"""Create a directory. Safe way (-p)"""
|
||||||
|
if not os.path.exists(path):
|
||||||
|
os.makedirs(os.path.abspath(path), mode)
|
||||||
|
mkdir(path, mode, uid, gid)
|
||||||
|
|
||||||
def make_password(length=16):
|
def make_password(length=16):
|
||||||
"""Create a random password."""
|
"""Create a random password."""
|
||||||
|
|||||||
Reference in New Issue
Block a user