def download(self, url, file_path=None, auth=None, retry=None, retry_wait=None, overwrite=False, headers=None, md5=None, sha1=None, sha256=None): """ compatible interface of FileDownloader + checksum """ checksum = sha256 or sha1 or md5 # If it is a user download, it must contain a checksum assert (not self._user_download) or (self._user_download and checksum) h = self._get_hash(url, checksum) lock = os.path.join(self._cache_folder, "locks", h) cached_path = os.path.join(self._cache_folder, h) with SimpleLock(lock): # Once the process has access, make sure multithread is locked too # as SimpleLock doesn't work multithread thread_lock = self._thread_locks.setdefault(lock, Lock()) thread_lock.acquire() try: if not os.path.exists(cached_path): try: self._file_downloader.download(url, cached_path, auth, retry, retry_wait, overwrite, headers) self._check_checksum(cached_path, md5, sha1, sha256) except Exception: if os.path.exists(cached_path): os.remove(cached_path) raise else: # specific check for corrupted cached files, will raise, but do nothing more # user can report it or "rm -rf cache_folder/path/to/file" try: self._check_checksum(cached_path, md5, sha1, sha256) except ConanException as e: raise ConanException( "%s\nCached downloaded file corrupted: %s" % (str(e), cached_path)) if file_path is not None: file_path = os.path.abspath(file_path) mkdir(os.path.dirname(file_path)) shutil.copy2(cached_path, file_path) else: with open(cached_path, 'rb') as handle: tmp = handle.read() return tmp finally: thread_lock.release()
def _lock(self, lock_id): lock = os.path.join(self._cache_folder, "locks", lock_id) with SimpleLock(lock): # Once the process has access, make sure multithread is locked too # as SimpleLock doesn't work multithread thread_lock = self._thread_locks.setdefault(lock, Lock()) thread_lock.acquire() try: yield finally: thread_lock.release()
def package_lock(self, package_ref): if self._no_locks(): return NoLock() return SimpleLock( join(self.conan(package_ref.conan), "locks", package_ref.package_id))
def package_lock(self, pref): if self._no_lock: return NoLock() return SimpleLock(os.path.join(self._base_folder, "locks", pref.id))
def package_lock(self, pref): if self._no_lock: return NoLock() return SimpleLock(os.path.join(self.conan(), "locks", pref.id))