/
tar_ball_composer.go
63 lines (53 loc) · 1.68 KB
/
tar_ball_composer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package postgres
import (
"archive/tar"
"errors"
"os"
"github.com/jackc/pgx"
)
// TarBallComposer is used to compose files into tarballs.
type TarBallComposer interface {
AddFile(info *ComposeFileInfo)
AddHeader(header *tar.Header, fileInfo os.FileInfo) error
SkipFile(tarHeader *tar.Header, fileInfo os.FileInfo)
PackTarballs() (TarFileSets, error)
GetFiles() BundleFiles
}
// ComposeFileInfo holds data which is required to pack a file to some tarball
type ComposeFileInfo struct {
path string
fileInfo os.FileInfo
wasInBase bool
header *tar.Header
isIncremented bool
}
type TarFileSets map[string][]string
func NewComposeFileInfo(path string, fileInfo os.FileInfo, wasInBase, isIncremented bool,
header *tar.Header) *ComposeFileInfo {
return &ComposeFileInfo{path: path, fileInfo: fileInfo,
wasInBase: wasInBase, header: header, isIncremented: isIncremented}
}
type TarBallComposerType int
const (
RegularComposer TarBallComposerType = iota + 1
RatingComposer
)
// TarBallComposerMaker is used to make an instance of TarBallComposer
type TarBallComposerMaker interface {
Make(bundle *Bundle) (TarBallComposer, error)
}
func NewTarBallComposerMaker(composerType TarBallComposerType, conn *pgx.Conn,
filePackOptions TarBallFilePackerOptions) (TarBallComposerMaker, error) {
switch composerType {
case RegularComposer:
return NewRegularTarBallComposerMaker(filePackOptions), nil
case RatingComposer:
relFileStats, err := newRelFileStatistics(conn)
if err != nil {
return nil, err
}
return NewRatingTarBallComposerMaker(relFileStats, filePackOptions)
default:
return nil, errors.New("NewTarBallComposerMaker: Unknown TarBallComposerType")
}
}