Exemple #1
0
    def __init__(self, repo, spawn_kwargs):
        # Note that repo.location cannot substitute for repo.user_location here,
        # since we manage a symlink that resides at repo.user_location, and
        # repo.location is the irreversible result of realpath(repo.user_location).
        self._user_location = repo.user_location
        self._spawn_kwargs = spawn_kwargs

        if not repo.sync_allow_hardlinks:
            raise RepoStorageException(
                "repos.conf sync-rcu setting"
                " for repo '%s' requires that sync-allow-hardlinks be enabled"
                % repo.name)

        # Raise an exception if repo.sync_rcu_store_dir is unset, since the
        # user needs to be aware of this location for bind mount and chroot
        # scenarios
        if not repo.sync_rcu_store_dir:
            raise RepoStorageException(
                "repos.conf sync-rcu setting"
                " for repo '%s' requires that sync-rcu-store-dir be set" %
                repo.name)

        self._storage_location = repo.sync_rcu_store_dir
        if repo.sync_rcu_spare_snapshots is None or repo.sync_rcu_spare_snapshots < 0:
            self._spare_snapshots = 1
        else:
            self._spare_snapshots = repo.sync_rcu_spare_snapshots
        if self._spare_snapshots < 0:
            self._spare_snapshots = 0
        if repo.sync_rcu_ttl_days is None or repo.sync_rcu_ttl_days < 0:
            self._ttl_days = 1
        else:
            self._ttl_days = repo.sync_rcu_ttl_days
        self._update_location = None
        self._latest_symlink = os.path.join(self._storage_location, 'latest')
        self._latest_canonical = os.path.realpath(self._latest_symlink)
        if not os.path.exists(self._latest_canonical) or os.path.islink(
                self._latest_canonical):
            # It doesn't exist, or it's a broken symlink.
            self._latest_canonical = None
        self._snapshots_dir = os.path.join(self._storage_location, 'snapshots')
    async def _check_call(self, cmd):
        """
		Run cmd and raise RepoStorageException on failure.

		@param cmd: command to executre
		@type cmd: list
		"""
        p = SpawnProcess(args=cmd,
                         scheduler=asyncio.get_event_loop(),
                         **self._spawn_kwargs)
        p.start()
        if await p.async_wait() != os.EX_OK:
            raise RepoStorageException('command exited with status {}: {}'.\
             format(p.returncode, ' '.join(cmd)))
Exemple #3
0
    def _check_call(self, cmd, privileged=False):
        """
		Run cmd and raise RepoStorageException on failure.

		@param cmd: command to executre
		@type cmd: list
		@param privileged: run with maximum privileges
		@type privileged: bool
		"""
        if privileged:
            kwargs = dict(fd_pipes=self._spawn_kwargs.get('fd_pipes'))
        else:
            kwargs = self._spawn_kwargs
        p = SpawnProcess(args=cmd, scheduler=asyncio._wrap_loop(), **kwargs)
        p.start()
        if (yield p.async_wait()) != os.EX_OK:
            raise RepoStorageException('command exited with status {}: {}'.\
             format(p.returncode, ' '.join(cmd)))
Exemple #4
0
 def current_update(self):
     if self._update_location is None:
         raise RepoStorageException('current update does not exist')
     return self._update_location