Download snapshot.

@param   string $id Snapshot id
@param   string $repository_name Name of repo
@return  bool|Snapshot
14476
public static function download( $id, $repository_name ) {
		if ( Utils\is_snapshot_cached( $id ) ) {
			Log::instance()->write( 'Snapshot found in cache.' );

			return self::get( $id );
		}

		$create_dir = Utils\create_snapshot_directory( $id );

		if ( ! $create_dir ) {
			Log::instance()->write( 'Cannot create necessary snapshot directories.', 0, 'error' );

			return false;
		}

		$repository = RepositoryManager::instance()->setup( $repository_name );

		if ( ! $repository ) {
			Log::instance()->write( 'Could not setup repository.', 0, 'error' );

			return false;
		}

		Log::instance()->write( 'Getting snapshot information...' );

		$snapshot = $repository->getDB()->getSnapshot( $id );

		if ( ! $snapshot ) {
			Log::instance()->write( 'Could not get snapshot from database.', 0, 'error' );

			return false;
		}

		if ( empty( $snapshot ) || empty( $snapshot['project'] ) ) {
			Log::instance()->write( 'Missing critical snapshot data.', 0, 'error' );
			return false;
		}

		/**
		 * Backwards compant. Add repository to meta before we started saving it.
		 */
		if ( empty( $snapshot['repository'] ) ) {
			$snapshot['repository'] = $repository_name;
		}

		Log::instance()->write( 'Downloading snapshot files and database (' . Utils\format_bytes( $snapshot['size'] ) . ')...' );

		$snapshot_path = Utils\get_snapshot_directory() . $id . '/';

		$download = $repository->getS3()->downloadSnapshot( $id, $snapshot['project'], $snapshot_path . 'data.sql.gz', $snapshot_path . 'files.tar.gz' );

		if ( ! $download ) {
			Log::instance()->write( 'Failed to download snapshot.', 0, 'error' );

			return false;
		}

		/**
		 * Finally save snapshot meta to meta.json
		 */
		$meta_handle = @fopen( $snapshot_path . 'meta.json', 'x' ); // Create file and fail if it exists.

		if ( ! $meta_handle ) {
			Log::instance()->write( 'Could not create meta.json.', 0, 'error' );

			return false;
		}

		fwrite( $meta_handle, json_encode( $snapshot, JSON_PRETTY_PRINT ) );

		return new self( $id, $repository_name, $snapshot, true );
	}
453317
protected function getRepositoryUrlCache()
    {
        $repositoryUrlCache = $this->getSession()->get(SessionParameter::REPOSITORY_URL_CACHE);
        if ($repositoryUrlCache === null) {
            $repositoryUrlCache = new RepositoryUrlCache();
            $this->getSession()->put(SessionParameter::REPOSITORY_URL_CACHE, $repositoryUrlCache);
        }

        return $repositoryUrlCache;
    }
93904
protected function getSnapshot($id)
    {
        $snapshot = $this->snapshotManager->findOneBy(['id' => $id]);

        if (null === $snapshot) {
            throw new NotFoundHttpException(sprintf('Snapshot (%d) not found', $id));
        }

        return $snapshot;
    }
246691
public function repository($name = null)
    {
        $name = $name ?: $this->getDefaultDriver();

        return $this->repositories[$name] = $this->get($name);
    }
723252
func (c *Client) SnapshotGetRepository(repositories ...string) *SnapshotGetRepositoryService {
	return NewSnapshotGetRepositoryService(c).Repository(repositories...)
}
67077
public function createRepo($repo_name, $repo_description)
    {
        return $this->client->request('POST', $this->create_repo_url(),
            [
                "auth" => $this->credentials(),
                "json" => json_decode($this->compileStub($repo_name, $repo_description),true),
            ]
        );
    }
637838
function Snapshot (id, obj) {
  if (!id) {
    var errIdMsg = 'id not injected!';
    debug(errIdMsg);
    throw new Error(errIdMsg);
  }

  if (!obj) {
    var errObjMsg = 'object not injected!';
    debug(errObjMsg);
    throw new Error(errObjMsg);
  }

  if (!obj.aggregateId) {
    var errAggIdMsg = 'object.aggregateId not injected!';
    debug(errAggIdMsg);
    throw new Error(errAggIdMsg);
  }

  if (!obj.data) {
    var errDataMsg = 'object.data not injected!';
    debug(errDataMsg);
    throw new Error(errDataMsg);
  }

  this.id = id;
  this.streamId = obj.aggregateId;
  this.aggregateId = obj.aggregateId;
  this.aggregate = obj.aggregate || null;
  this.context = obj.context || null;
  this.commitStamp = null;
  this.revision = obj.revision;
  this.version = obj.version;
  this.data = obj.data;
}
936058
public RepositoryDTO getOrFindUserRepository(String user, String repositoryName, GitRepoClient repoClient) {
        RepositoryDTO repository = getUserRepository(user, repositoryName);
        if (repository == null) {
            List<RepositoryDTO> repositoryDTOs = repoClient.listRepositories();
            updateUserRepositories(repositoryDTOs);
            repository = getUserRepository(user, repositoryName);
        }
        return repository;
    }
944170
public function all($username, $repository, $pullRequest, array $params = [])
    {
        return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', $params);
    }
992362
def create_snapshot(self, name, tag):
        
        source = self.local_location
        logger.debug("Create Snapshot: %s -> %s" % (source, name))
        # FIXME: actually create the snapshot via clone command
        if name and tag:
            output_tag = "{}:{}".format(name, tag)
        else:
            output_tag = name or tag
        return self.__class__(repository=source, tag=output_tag)
303819
public Repositories.Repository getRepository( String name ) {
        JSONRestClient.Response response = jsonRestClient.doGet();
        if (!response.isOK()) {
            throw new RuntimeException(JdbcI18n.invalidServerResponse.text(jsonRestClient.url(), response.asString()));
        }
        return new Repositories(response.json()).getRepository(name);
    }
1334946
public Repository addRepository(String name,
                                    String url) {
        Repository repository = new Repository(name, url);
        repositories.add(repository);
        return repository;
    }
1202585
public function find($uuid, $max_version = null): ?Snapshot
    {
        $criteria = new Criteria();
        $criteria->where(Criteria::expr()->eq('uuid', $uuid));

        if (null !== $max_version) {
            $criteria->andWhere(Criteria::expr()->lte('version', $max_version));
        }

        $criteria->orderBy(['version' => Criteria::DESC]);
        $snapshot = $this->em->getRepository(Snapshot::class)->matching($criteria)->first();

        return $snapshot instanceof Snapshot ? $snapshot : null;
    }
343892
@Override
    protected File cloneRepository(File dest) {
        BaseRepository repo = Repository.clone(RepositoryConfiguration.DEFAULT, dest, getUrl());

        // set branch name
        String branchName = MASTER;;
        String branch = getBranch();
        if (StringUtils.isNotBlank(branch)) {
            branchName = branch;
        }
        String tag = getTag();
        if (StringUtils.isNotBlank(tag)) {
            branchName = tag;
        }
        BranchCommand.on(repo).set(branchName);
        return dest;
    }
280097
public function unlock($username, $repository, $id)
    {
        return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id).'/lock');
    }
664735
public Response restoreRepository( ServletContext context, 
                                       HttpServletRequest request, 
                                       String repositoryName,
                                       String backupName, 
                                       RestoreOptions options ) throws RepositoryException {
        if (StringUtil.isBlank(backupName)) {
            throw new IllegalArgumentException("The name of the backup cannot be null");
        }
        File backup = resolveBackup(context, backupName);
        logger.debug("Restoring repository '{0}' from backup '{1}' using '{2}'", repositoryName, backup, options);
        Session session = getSession(request, repositoryName, null);
        RepositoryManager repositoryManager = ((org.modeshape.jcr.api.Workspace)session.getWorkspace()).getRepositoryManager();
        final Problems problems = repositoryManager.restoreRepository(backup, options);
        if (!problems.hasProblems()) {
            return Response.ok().build();
        }
        List<JSONAble> response = new ArrayList<JSONAble>(problems.size());
        for (Problem problem : problems) {
            RestException exception = problem.getThrowable() != null ? 
                                      new RestException(problem.getMessage(), problem.getThrowable()) : 
                                      new RestException(problem.getMessage());
            response.add(exception);
        }
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(response).build();
    }
158288
public function repository($name, $method, array $parameters = [])
    {
        return call_user_func_array(
            [ $this->getRepository($name), $method ],
            $parameters
        );
    }