def rebuild_index_from_scratch(self, fmris, tmp_index_dir=None): """Removes any existing index directory and rebuilds the index based on the fmris and manifests provided as an argument. The "tmp_index_dir" parameter allows for a different directory than the default to be used.""" self.file_version_number = INITIAL_VERSION_NUMBER self.empty_index = True # A lock can't be held while the index directory is being # removed as that can cause rmtree() to fail when using # NFS. As such, attempt to get the lock first, then # unlock, immediately rename the old index directory, # and then remove the old the index directory and # create a new one. self.lock() self.unlock() portable.rename(self._index_dir, self._index_dir + ".old") try: shutil.rmtree(self._index_dir + ".old") makedirs(self._index_dir) except OSError as e: if e.errno == errno.EACCES: raise search_errors.ProblematicPermissionsIndexException( self._index_dir) self._generic_update_index(fmris, IDX_INPUT_TYPE_FMRI, tmp_index_dir) self.empty_index = False
def makedirs(pathname): """Create a directory at the specified location if it does not already exist (including any parent directories). """ try: os.makedirs(pathname, PKG_DIR_MODE) except EnvironmentError as e: if e.filename == pathname and (e.errno == errno.EEXIST or os.path.exists(e.filename)): return elif e.errno in (errno.EACCES, errno.EROFS): raise search_errors.ProblematicPermissionsIndexException( e.filename) elif e.errno != errno.EEXIST or e.filename != pathname: raise
def rebuild_index_from_scratch(self, fmris, tmp_index_dir = None): """Removes any existing index directory and rebuilds the index based on the fmris and manifests provided as an argument. The "tmp_index_dir" parameter allows for a different directory than the default to be used.""" self.file_version_number = INITIAL_VERSION_NUMBER self.empty_index = True try: shutil.rmtree(self._index_dir) os.makedirs(self._index_dir) except OSError, e: if e.errno == errno.EACCES: raise search_errors.ProblematicPermissionsIndexException( self._index_dir)