def datadir_init(self, uname=None, datadir=None): ''' Initialize datadir ''' if datadir: self.datadir = datadir else: self.datadir = utils_hier.LOCALSTATEDIR logging.debug('filesys_posix: datadir: %s', self.datadir) logging.debug('filesys_posix: user name: %s', uname) if uname: self.passwd = utils_posix.getpwnam(uname) else: self.passwd = system_posix.getpwnam() # The common case logging.debug('filesys_posix: uid: %d', self.passwd.pw_uid) logging.debug('filesys_posix: gid: %d', self.passwd.pw_gid) # # Here we are assuming that /var (BSD) or /var/lib (Linux) # exists and has the correct permissions. # We are also assuming that we are running with enough privs # to be able to create a directory there on behalf of the # specified uid and gid. # logging.debug('filesys_posix: datadir init: %s', self.datadir) utils_posix.mkdir_idempotent(self.datadir, self.passwd.pw_uid, self.passwd.pw_gid)
def really_init_datadir(self, uname=None, datadir=None): ''' Initialize datadir ''' # # Note: this code is the implementation of datadir_init(), # which may be called by the backends that need it. # # The reason for this code structure is that some backends # (e.g., the volatile backend) don't need to initialize # the datadir, while others (e.g., the mlab backend) need # to initialize the datadir. # if datadir: self.datadir = datadir else: self.datadir = utils_hier.LOCALSTATEDIR logging.debug('backend: datadir: %s', self.datadir) logging.debug('backend: user name: %s', uname) if uname: self.passwd = self.vfs.getpwnam(uname) else: # # The common case (in which you don't override the # default user name with a custom name). # # XXX The following lines are the only piece of code # in this file that is heavily system dependent. # # Ideally it would be better to move the functionality # that they implement into system-specific files. # # BTW the lines below are so heavily system-dependent # because I adapted them from a POSIX-only file. # if os.name == "posix": from neubot import system_posix self.passwd = system_posix.getpwnam() elif os.name == "nt": from neubot import utils_nt self.passwd = utils_nt.PWEntry() else: raise RuntimeError("backend: unsupported system") logging.debug('backend: uid: %d', self.passwd.pw_uid) logging.debug('backend: gid: %d', self.passwd.pw_gid) # # Here we are assuming that the /var/lib (or /var) dir # exists and has the correct permissions. # # We are also assuming that we are running with enough privs # to be able to create a directory there on behalf of the # specified uid and gid. # logging.debug('backend: datadir init: %s', self.datadir) self.vfs.mkdir_idempotent(self.datadir, self.passwd.pw_uid, self.passwd.pw_gid)