コード例 #1
0
        public async Task DeleteRepositoryAsync(string repository)
        {
            // there is no official Docker Distribution API to delete an entire repo. Instead, we
            // delete all tags from the repo via the API, then remove the (now empty) local folder

            var scope = AuthHandler.RepoAdminScope(repository);

            if (await AuthHandler.AuthorizeAsync(scope))
            {
                var key = RepoTagsKey(repository);

                // coerce to list before deleting to avoid deleting a tag out from under ourselves
                var tags         = GetTags(repository).ToAsyncEnumerable();
                var imageDigests = await tags.SelectAwait(async t => await GetTagDigestAsync(repository, t)).Distinct().ToListAsync();

                if (imageDigests.Any(d => d == null))
                {
                    //Logger.LogError($"Encountered at least one unreadable tag in {repository}, aborting");
                    return;
                }

                foreach (var digest in imageDigests)
                {
                    await DeleteImageAsync(repository, digest);
                }

                await localClient.DeleteRepositoryAsync(repository);
            }
            else
            {
                throw new UnauthorizedAccessException();
            }
        }