1/* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15*/ 16 17package archive 18 19import ( 20 "archive/tar" 21 "context" 22 "io" 23) 24 25// ApplyOptions provides additional options for an Apply operation 26type ApplyOptions struct { 27 Filter Filter // Filter tar headers 28 ConvertWhiteout ConvertWhiteout // Convert whiteout files 29 Parents []string // Parent directories to handle inherited attributes without CoW 30 31 applyFunc func(context.Context, string, io.Reader, ApplyOptions) (int64, error) 32} 33 34// ApplyOpt allows setting mutable archive apply properties on creation 35type ApplyOpt func(options *ApplyOptions) error 36 37// Filter specific files from the archive 38type Filter func(*tar.Header) (bool, error) 39 40// ConvertWhiteout converts whiteout files from the archive 41type ConvertWhiteout func(*tar.Header, string) (bool, error) 42 43// all allows all files 44func all(_ *tar.Header) (bool, error) { 45 return true, nil 46} 47 48// WithFilter uses the filter to select which files are to be extracted. 49func WithFilter(f Filter) ApplyOpt { 50 return func(options *ApplyOptions) error { 51 options.Filter = f 52 return nil 53 } 54} 55 56// WithConvertWhiteout uses the convert function to convert the whiteout files. 57func WithConvertWhiteout(c ConvertWhiteout) ApplyOpt { 58 return func(options *ApplyOptions) error { 59 options.ConvertWhiteout = c 60 return nil 61 } 62} 63 64// WithParents provides parent directories for resolving inherited attributes 65// directory from the filesystem. 66// Inherited attributes are searched from first to last, making the first 67// element in the list the most immediate parent directory. 68// NOTE: When applying to a filesystem which supports CoW, file attributes 69// should be inherited by the filesystem. 70func WithParents(p []string) ApplyOpt { 71 return func(options *ApplyOptions) error { 72 options.Parents = p 73 return nil 74 } 75} 76 77// WriteDiffOptions provides additional options for a WriteDiff operation 78type WriteDiffOptions struct { 79 ParentLayers []string // Windows needs the full list of parent layers 80 81 writeDiffFunc func(context.Context, io.Writer, string, string, WriteDiffOptions) error 82} 83 84// WriteDiffOpt allows setting mutable archive write properties on creation 85type WriteDiffOpt func(options *WriteDiffOptions) error 86