示例#1
0
        private void _insertNodeIntoLeafsQueue(IList <DockerImageNode> leafs, DockerImageNode node)
        {
            var index = leafs.Count;

            for (int i = 0; i < leafs.Count; i++)
            {
                if (ImageDeletionOrder is ImageDeletionOrderType.ByImageCreationDate)
                {
                    if (node.InspectResponse.Created < leafs[i].InspectResponse.Created)
                    {
                        index = i;
                        break;
                    }
                }
                else if (ImageDeletionOrder is ImageDeletionOrderType.ByImageLastTouchDate)
                {
                    if (node.GetImageLastTouchDate(this._imageLastTouchDate) < leafs[i].GetImageLastTouchDate(this._imageLastTouchDate))
                    {
                        index = i;
                        break;
                    }
                }
            }
            leafs.Insert(index, node);
        }
示例#2
0
        // Returns true when all child images can be deleted, meaning all child images have no running containers (all dead or exited)
        // and they are old enough to be safely deleted.
        private bool _canDelete(DockerImageNode image, List <DockerImageNode> imagesToBeRecycledInOrder)
        {
            var canDelete = true;

            foreach (var child in image.Children)
            {
                if (!_canDelete(child, imagesToBeRecycledInOrder))
                {
                    canDelete = false;
                }
                else
                {
                    imagesToBeRecycledInOrder.Add(child);
                }
            }

            if (ImageDeletionOrder is ImageDeletionOrderType.ByImageCreationDate)
            {
                if (image.InspectResponse.Created >= DateTime.UtcNow.AddDays(-this.DaysBeforeDeletion))
                {
                    return(false);
                }
            }
            else if (ImageDeletionOrder is ImageDeletionOrderType.ByImageLastTouchDate)
            {
                var imageLastTouchDate = image.GetImageLastTouchDate(this._imageLastTouchDate);

                if (imageLastTouchDate >= DateTime.UtcNow.AddDays(-this.DaysBeforeDeletion))
                {
                    return(false);
                }
            }

            if (!base.CanDelete(image))
            {
                canDelete = false;
            }

            return(canDelete);
        }