github.com/lalkh/containerd@v1.4.3/archive/tar_opts.go (about) 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 17 package archive 18 19 import ( 20 "archive/tar" 21 "context" 22 ) 23 24 // ApplyOptions provides additional options for an Apply operation 25 type ApplyOptions struct { 26 Filter Filter // Filter tar headers 27 ConvertWhiteout ConvertWhiteout // Convert whiteout files 28 Parents []string // Parent directories to handle inherited attributes without CoW 29 30 applyFunc func(context.Context, string, *tar.Reader, ApplyOptions) (int64, error) 31 } 32 33 // ApplyOpt allows setting mutable archive apply properties on creation 34 type ApplyOpt func(options *ApplyOptions) error 35 36 // Filter specific files from the archive 37 type Filter func(*tar.Header) (bool, error) 38 39 // ConvertWhiteout converts whiteout files from the archive 40 type ConvertWhiteout func(*tar.Header, string) (bool, error) 41 42 // all allows all files 43 func all(_ *tar.Header) (bool, error) { 44 return true, nil 45 } 46 47 // WithFilter uses the filter to select which files are to be extracted. 48 func WithFilter(f Filter) ApplyOpt { 49 return func(options *ApplyOptions) error { 50 options.Filter = f 51 return nil 52 } 53 } 54 55 // WithConvertWhiteout uses the convert function to convert the whiteout files. 56 func WithConvertWhiteout(c ConvertWhiteout) ApplyOpt { 57 return func(options *ApplyOptions) error { 58 options.ConvertWhiteout = c 59 return nil 60 } 61 } 62 63 // WithParents provides parent directories for resolving inherited attributes 64 // directory from the filesystem. 65 // Inherited attributes are searched from first to last, making the first 66 // element in the list the most immediate parent directory. 67 // NOTE: When applying to a filesystem which supports CoW, file attributes 68 // should be inherited by the filesystem. 69 func WithParents(p []string) ApplyOpt { 70 return func(options *ApplyOptions) error { 71 options.Parents = p 72 return nil 73 } 74 }