github.com/mgoltzsche/ctnr@v0.7.1-alpha/pkg/fs/writertypes.go (about)

     1  package fs
     2  
     3  type Writer interface {
     4  	Lazy(path, name string, src LazySource, written map[Source]string) error
     5  	File(path string, src FileSource) (Source, error)
     6  	Link(path, target string) error
     7  	Symlink(path string, attrs FileAttrs) error
     8  	Dir(path, base string, attrs FileAttrs) error
     9  	Mkdir(path string) error
    10  	Fifo(path string, attrs DeviceAttrs) error
    11  	Device(path string, attrs DeviceAttrs) error
    12  	Remove(path string) error
    13  	LowerNode(path, name string, a *NodeAttrs) error
    14  	LowerLink(path, target string, a *NodeAttrs) error
    15  	Parent() error
    16  }
    17  
    18  func HashingNilWriter() Writer {
    19  	return nilWriter
    20  }
    21  
    22  type hashingNilWriter string
    23  
    24  func (_ hashingNilWriter) Parent() error { return nil }
    25  func (_ hashingNilWriter) Lazy(path, name string, src LazySource, written map[Source]string) error {
    26  	_, err := src.DeriveAttrs()
    27  	return err
    28  }
    29  func (_ hashingNilWriter) File(path string, src FileSource) (Source, error) {
    30  	_, err := src.DeriveAttrs()
    31  	return src, err
    32  }
    33  func (_ hashingNilWriter) Link(path, target string) error                    { return nil }
    34  func (_ hashingNilWriter) Symlink(path string, attrs FileAttrs) error        { return nil }
    35  func (_ hashingNilWriter) Dir(path, name string, attrs FileAttrs) error      { return nil }
    36  func (_ hashingNilWriter) Mkdir(path string) error                           { return nil }
    37  func (_ hashingNilWriter) Fifo(path string, attrs DeviceAttrs) error         { return nil }
    38  func (_ hashingNilWriter) Device(path string, attrs DeviceAttrs) error       { return nil }
    39  func (_ hashingNilWriter) Remove(path string) error                          { return nil }
    40  func (_ hashingNilWriter) LowerNode(path, name string, a *NodeAttrs) error   { return nil }
    41  func (_ hashingNilWriter) LowerLink(path, target string, a *NodeAttrs) error { return nil }
    42  
    43  // Writer that expands lazy resources
    44  type ExpandingWriter struct {
    45  	Writer
    46  }
    47  
    48  func (w *ExpandingWriter) Lazy(path, name string, src LazySource, written map[Source]string) (err error) {
    49  	return src.Expand(path, w, written)
    50  }