def clear_cache(self): """ Clear all the Entropy default cache directory. This function is fault tolerant and will never return any exception. """ with self._cacher: # no data is written while holding self._cacher by the balls # drop all the buffers then remove on-disk data self._cacher.discard() # clear repositories live cache if self._installed_repository is not None: self._installed_repository.clearCache() with self._repodb_cache_mutex: for repo in self._repodb_cache.values(): repo.clearCache() cache_dir = self._cacher.current_directory() try: shutil.rmtree(cache_dir, True) except (shutil.Error, IOError, OSError): return try: os.makedirs(cache_dir, 0o775) except (IOError, OSError): return try: const_setup_perms(cache_dir, etpConst['entropygid']) except (IOError, OSError): return
def clear_cache(self): """ Clear all the Entropy default cache directory. This function is fault tolerant and will never return any exception. """ with self._cacher: # no data is written while holding self._cacher by the balls # drop all the buffers then remove on-disk data self._cacher.discard() # clear repositories live cache inst_repo = self.installed_repository() if inst_repo is not None: inst_repo.clearCache() with self._repodb_cache_mutex: for repo in self._repodb_cache.values(): repo.clearCache() cache_dir = self._cacher.current_directory() try: shutil.rmtree(cache_dir, True) except (shutil.Error, IOError, OSError): return try: os.makedirs(cache_dir, 0o775) except (IOError, OSError): return try: const_setup_perms(cache_dir, etpConst['entropygid']) except (IOError, OSError): return
def _ensure_package_sets_dir(): sets_dir = SystemSettings.packages_sets_directory() if not os.path.isdir(sets_dir): if os.path.lexists(sets_dir): os.remove(sets_dir) os.makedirs(sets_dir, 0o775) const_setup_perms(sets_dir, etpConst['entropygid'], recursion = False)
def __init__(self): object.__init__(self) self.__dump_lock = threading.Lock() try: if not os.path.isdir(MtimePingus.PINGUS_DIR): os.makedirs(MtimePingus.PINGUS_DIR, 0o775) const_setup_perms(MtimePingus.PINGUS_DIR, etpConst["entropygid"]) except (OSError, IOError): MtimePingus.PINGUS_DIR = const_mkdtemp(prefix="pingus_dir")
def _setup_url_directories(self, url_data): """ Create the directories needed to download the files in url_data. """ for _pkg_id, _repository_id, _url, dest_path, _cksum, _sig in url_data: dest_dir = os.path.dirname(dest_path) try: os.makedirs(dest_dir, 0o775) const_setup_perms(dest_dir, etpConst['entropygid']) except OSError as err: if err.errno != errno.EEXIST: raise
def _setup_store_path(self, path): path = os.path.realpath(path) if not os.path.isabs(path): raise PermissionDenied("not a valid directory path") if not os.path.isdir(path): try: os.makedirs(path) except OSError as err: raise PermissionDenied(err) if etpConst['entropygid'] != None: const_setup_perms(path, etpConst['entropygid'], recursion = False) self.STORE_PATH = path
def __init__(self): object.__init__(self) self.__dump_lock = threading.Lock() try: if not os.path.isdir(MtimePingus.PINGUS_DIR): os.makedirs(MtimePingus.PINGUS_DIR, 0o775) const_setup_perms(MtimePingus.PINGUS_DIR, etpConst['entropygid']) except ( OSError, IOError, ): MtimePingus.PINGUS_DIR = const_mkdtemp(prefix="pingus_dir")
def _setup_store_path(self, path): path = os.path.realpath(path) if not os.path.isabs(path): raise PermissionDenied("not a valid directory path") if not os.path.isdir(path): try: os.makedirs(path) except OSError as err: raise PermissionDenied(err) if etpConst['entropygid'] != None: const_setup_perms(path, etpConst['entropygid'], recursion=False) self.STORE_PATH = path
def _insert_generic_file(self, pkgkey, userid, username, file_path, file_name, doc_type, title, description, keywords): file_path = os.path.realpath(file_path) # do a virus check? virus_found, virus_type = self._scan_for_viruses(file_path) if virus_found: os.remove(file_path) return False, None # flood control flood_risk = self.insert_flood_control_check(userid) if flood_risk: return False, 'flooding detected' # validity check if doc_type == self.DOC_TYPES['image']: valid = False if os.path.isfile(file_path) and os.access(file_path, os.R_OK): valid = entropy.tools.is_supported_image_file(file_path) if not valid: return False, 'not a valid image' dest_path = os.path.join(self.STORE_PATH, file_name) # create dir if not exists dest_dir = os.path.dirname(dest_path) if not os.path.isdir(dest_dir): try: os.makedirs(dest_dir) except OSError as err: raise PermissionDenied(err) if etpConst['entropygid'] != None: const_setup_perms(dest_dir, etpConst['entropygid'], recursion=False) orig_dest_path = dest_path dcount = 0 while os.path.isfile(dest_path): dcount += 1 dest_path_name = "%s_%s" % ( dcount, os.path.basename(orig_dest_path), ) dest_path = os.path.join(os.path.dirname(orig_dest_path), dest_path_name) if os.path.dirname(file_path) != dest_dir: try: os.rename(file_path, dest_path) except OSError: # fallback to non atomic shutil.move(file_path, dest_path) if etpConst['entropygid'] != None: try: const_setup_file(dest_path, etpConst['entropygid'], 0o664) except OSError: pass # at least set chmod try: const_set_chmod(dest_path, 0o664) except OSError: pass title = title[:self.entropy_docs_title_len] description = description[:self.entropy_docs_description_len] # now store in db idkey = self._handle_pkgkey(pkgkey) self.execute_query( """ INSERT INTO entropy_docs VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s) """, ( None, idkey, userid, username, doc_type, file_name, title, description, None, )) iddoc = self.lastrowid() self._insert_keywords(iddoc, keywords) store_url = os.path.basename(dest_path) if self._store_url: store_url = os.path.join(self._store_url, store_url) return True, (iddoc, store_url)
def makedirs(self, remote_path): remote_str = self._setup_remote_path(remote_path) if not os.path.isdir(remote_str): os.makedirs(remote_str, 0o755) const_setup_perms(remote_str, etpConst['entropygid'], recursion = False) return True
def _insert_generic_file(self, pkgkey, userid, username, file_path, file_name, doc_type, title, description, keywords): file_path = os.path.realpath(file_path) # do a virus check? virus_found, virus_type = self._scan_for_viruses(file_path) if virus_found: os.remove(file_path) return False, None # flood control flood_risk = self.insert_flood_control_check(userid) if flood_risk: return False, 'flooding detected' # validity check if doc_type == self.DOC_TYPES['image']: valid = False if os.path.isfile(file_path) and os.access(file_path, os.R_OK): valid = entropy.tools.is_supported_image_file(file_path) if not valid: return False, 'not a valid image' dest_path = os.path.join(self.STORE_PATH, file_name) # create dir if not exists dest_dir = os.path.dirname(dest_path) if not os.path.isdir(dest_dir): try: os.makedirs(dest_dir) except OSError as err: raise PermissionDenied(err) if etpConst['entropygid'] != None: const_setup_perms(dest_dir, etpConst['entropygid'], recursion = False) orig_dest_path = dest_path dcount = 0 while os.path.isfile(dest_path): dcount += 1 dest_path_name = "%s_%s" % (dcount, os.path.basename(orig_dest_path),) dest_path = os.path.join(os.path.dirname(orig_dest_path), dest_path_name) if os.path.dirname(file_path) != dest_dir: try: os.rename(file_path, dest_path) except OSError: # fallback to non atomic shutil.move(file_path, dest_path) if etpConst['entropygid'] != None: try: const_setup_file(dest_path, etpConst['entropygid'], 0o664) except OSError: pass # at least set chmod try: const_set_chmod(dest_path, 0o664) except OSError: pass title = title[:self.entropy_docs_title_len] description = description[:self.entropy_docs_description_len] # now store in db idkey = self._handle_pkgkey(pkgkey) self.execute_query(""" INSERT INTO entropy_docs VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s) """, (None, idkey, userid, username, doc_type, file_name, title, description, None,)) iddoc = self.lastrowid() self._insert_keywords(iddoc, keywords) store_url = os.path.basename(dest_path) if self._store_url: store_url = os.path.join(self._store_url, store_url) return True, (iddoc, store_url)