2018-11-09 00:47:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
|
|
import "crypto/sha256"
|
|
|
|
import "encoding/hex"
|
|
|
|
import "encoding/json"
|
|
|
|
import "flag"
|
|
|
|
import "fmt"
|
|
|
|
import "io"
|
|
|
|
import "io/ioutil"
|
|
|
|
import "log"
|
|
|
|
import "net/http"
|
|
|
|
import "path/filepath"
|
|
|
|
import "os"
|
|
|
|
import "sort"
|
2018-11-17 13:49:17 +00:00
|
|
|
import "strings"
|
2018-11-14 17:01:08 +00:00
|
|
|
import "syscall"
|
2018-11-09 00:47:14 +00:00
|
|
|
|
2019-08-10 16:35:25 +00:00
|
|
|
import "github.com/colinmarc/cdb"
|
2018-11-09 00:47:14 +00:00
|
|
|
|
2018-11-18 16:11:36 +00:00
|
|
|
import . "github.com/volution/kawipiko/lib/common"
|
|
|
|
import . "github.com/volution/kawipiko/lib/archiver"
|
2018-11-09 00:47:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-09 13:54:47 +00:00
|
|
|
type context struct {
|
|
|
|
cdbWriter *cdb.Writer
|
2018-11-20 12:21:22 +00:00
|
|
|
storedFilePaths []string
|
|
|
|
storedFolderPaths []string
|
|
|
|
storedDataMeta map[string]bool
|
|
|
|
storedDataContent map[string]bool
|
|
|
|
storedDataContentMeta map[string]map[string]string
|
|
|
|
storedFiles map[[2]uint64][2]string
|
2018-11-09 13:54:47 +00:00
|
|
|
compress string
|
2018-11-15 18:46:38 +00:00
|
|
|
includeIndex bool
|
2018-11-20 12:49:43 +00:00
|
|
|
includeStripped bool
|
2018-11-20 07:07:21 +00:00
|
|
|
includeEtag bool
|
2018-11-20 12:21:22 +00:00
|
|
|
includeFileListing bool
|
|
|
|
includeFolderListing bool
|
2018-11-09 13:54:47 +00:00
|
|
|
debug bool
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-14 19:28:25 +00:00
|
|
|
func archiveFile (_context *context, _pathResolved string, _pathInArchive string, _name string) (error) {
|
2018-11-09 00:47:14 +00:00
|
|
|
|
2018-11-14 17:01:08 +00:00
|
|
|
var _file *os.File
|
|
|
|
if _file_0, _error := os.Open (_pathResolved); _error == nil {
|
|
|
|
_file = _file_0
|
2018-11-09 00:47:14 +00:00
|
|
|
} else {
|
|
|
|
return _error
|
|
|
|
}
|
|
|
|
|
2018-11-14 17:01:08 +00:00
|
|
|
defer _file.Close ()
|
|
|
|
|
|
|
|
var _fileId [2]uint64
|
|
|
|
if _stat, _error := _file.Stat (); _error == nil {
|
|
|
|
_stat := _stat.Sys()
|
|
|
|
if _stat, _ok := _stat.(*syscall.Stat_t); _ok {
|
|
|
|
_fileId = [2]uint64 { _stat.Dev, _stat.Ino }
|
|
|
|
} else {
|
2018-11-16 14:18:27 +00:00
|
|
|
return fmt.Errorf ("[6578d2d7] failed `stat`-ing: `%s`!", _pathResolved)
|
2018-11-14 17:01:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
var _wasStored bool
|
|
|
|
var _fingerprintContent string
|
|
|
|
var _fingerprintMeta string
|
|
|
|
if _fingerprints, _wasStored_0 := _context.storedFiles[_fileId]; _wasStored_0 {
|
|
|
|
_fingerprintContent = _fingerprints[0]
|
|
|
|
_fingerprintMeta = _fingerprints[1]
|
|
|
|
_wasStored = true
|
|
|
|
}
|
|
|
|
|
|
|
|
var _dataContent []byte
|
2018-11-17 13:49:17 +00:00
|
|
|
var _dataMeta map[string]string
|
2018-11-20 12:21:22 +00:00
|
|
|
var _dataMetaRaw []byte
|
2018-11-14 17:01:08 +00:00
|
|
|
|
2018-11-17 13:49:17 +00:00
|
|
|
if ! _wasStored {
|
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
if _dataContent_0, _error := ioutil.ReadAll (_file); _error == nil {
|
|
|
|
_dataContent = _dataContent_0
|
2018-11-17 13:49:17 +00:00
|
|
|
} else {
|
2018-11-14 17:01:08 +00:00
|
|
|
return _error
|
|
|
|
}
|
2018-11-17 13:49:17 +00:00
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
if _fingerprintContent_0, _dataContent_0, _dataMeta_0, _error := prepareDataContent (_context, _pathResolved, _pathInArchive, _name, _dataContent, ""); _error != nil {
|
2018-11-17 13:49:17 +00:00
|
|
|
return _error
|
|
|
|
} else {
|
2018-11-20 12:21:22 +00:00
|
|
|
_fingerprintContent = _fingerprintContent_0
|
|
|
|
_dataContent = _dataContent_0
|
2018-11-17 13:49:17 +00:00
|
|
|
_dataMeta = _dataMeta_0
|
|
|
|
}
|
2018-11-20 12:21:22 +00:00
|
|
|
if _fingerprintMeta_0, _dataMetaRaw_0, _error := prepareDataMeta (_context, _dataMeta); _error != nil {
|
|
|
|
return _error
|
|
|
|
} else {
|
|
|
|
_fingerprintMeta = _fingerprintMeta_0
|
|
|
|
_dataMetaRaw = _dataMetaRaw_0
|
|
|
|
}
|
2018-11-16 14:18:27 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 12:49:43 +00:00
|
|
|
if _context.includeStripped {
|
|
|
|
for _, _suffix := range StripSuffixes {
|
|
|
|
if strings.HasSuffix (_pathInArchive, _suffix) {
|
|
|
|
_pathInArchive := _pathInArchive [: len (_pathInArchive) - len (_suffix)]
|
|
|
|
if _error := archiveReference (_context, NamespaceFilesContent, _pathInArchive, _fingerprintContent, _fingerprintMeta); _error != nil {
|
|
|
|
return _error
|
|
|
|
}
|
|
|
|
break
|
2018-11-17 13:49:17 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-09 13:54:47 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
if _error := archiveReference (_context, NamespaceFilesContent, _pathInArchive, _fingerprintContent, _fingerprintMeta); _error != nil {
|
2018-11-16 14:18:27 +00:00
|
|
|
return _error
|
|
|
|
}
|
2018-11-20 12:21:22 +00:00
|
|
|
if _dataMetaRaw != nil {
|
|
|
|
if _error := archiveDataMeta (_context, _fingerprintMeta, _dataMetaRaw); _error != nil {
|
|
|
|
return _error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _dataContent != nil {
|
|
|
|
if _error := archiveDataContent (_context, _fingerprintContent, _dataContent); _error != nil {
|
2018-11-17 13:49:17 +00:00
|
|
|
return _error
|
|
|
|
}
|
2018-11-17 14:56:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ! _wasStored {
|
2018-11-20 12:21:22 +00:00
|
|
|
_context.storedFiles[_fileId] = [2]string { _fingerprintContent, _fingerprintMeta }
|
2018-11-17 13:49:17 +00:00
|
|
|
}
|
2018-11-16 14:18:27 +00:00
|
|
|
|
2018-11-09 13:54:47 +00:00
|
|
|
return nil
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-09 13:54:47 +00:00
|
|
|
func archiveFolder (_context *context, _pathResolved string, _pathInArchive string, _names []string, _stats map[string]os.FileInfo) (error) {
|
2018-11-09 00:47:14 +00:00
|
|
|
|
|
|
|
type Entry struct {
|
|
|
|
Name string `json:"name",omitempty`
|
|
|
|
Type string `json:"type",omitempty`
|
|
|
|
Size uint64 `json:"size",omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Folder struct {
|
2018-11-14 19:28:25 +00:00
|
|
|
Entries []Entry `json:"entries",omitempty`
|
|
|
|
Indices []string `json:"indices",omitempty`
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_entries := make ([]Entry, 0, len (_names))
|
2018-11-20 12:21:22 +00:00
|
|
|
if _context.includeFolderListing {
|
2018-11-15 18:46:38 +00:00
|
|
|
for _, _name := range _names {
|
|
|
|
_entry := Entry {
|
|
|
|
Name : _name,
|
|
|
|
Type : "unknown",
|
|
|
|
}
|
|
|
|
_stat := _stats[_name]
|
|
|
|
_statMode := _stat.Mode ()
|
|
|
|
if _statMode.IsRegular () {
|
|
|
|
_entry.Type = "file"
|
|
|
|
_entry.Size = uint64 (_stat.Size ())
|
|
|
|
} else if _statMode.IsDir () {
|
|
|
|
_entry.Type = "folder"
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
2018-11-15 18:46:38 +00:00
|
|
|
_entries = append (_entries, _entry)
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-14 19:28:25 +00:00
|
|
|
_indexNames := make ([]string, 0, 4)
|
2018-11-15 18:46:38 +00:00
|
|
|
if _context.includeIndex {
|
|
|
|
var _indexNameFirst string
|
|
|
|
for _, _indexName := range IndexNames {
|
|
|
|
_indexNameFound := sort.SearchStrings (_names, _indexName)
|
|
|
|
if _indexNameFound == len (_names) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if _names[_indexNameFound] != _indexName {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
_stat := _stats[_indexName]
|
|
|
|
_statMode := _stat.Mode ()
|
|
|
|
if ! _statMode.IsRegular () {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if _indexNameFirst == "" {
|
|
|
|
_indexNameFirst = _indexName
|
|
|
|
}
|
|
|
|
_indexNames = append (_indexNames, _indexName)
|
2018-11-14 19:28:25 +00:00
|
|
|
}
|
2018-11-15 18:46:38 +00:00
|
|
|
if _indexNameFirst != "" {
|
|
|
|
_indexPathResolved := filepath.Join (_pathResolved, _indexNameFirst)
|
|
|
|
_indexPathInArchive := _pathInArchive + "/"
|
|
|
|
if _pathInArchive == "/" {
|
|
|
|
_indexPathInArchive = "/"
|
|
|
|
}
|
|
|
|
archiveFile (_context, _indexPathResolved, _indexPathInArchive, _indexNameFirst)
|
2018-11-14 19:28:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
if ! _context.includeFolderListing {
|
2018-11-16 14:18:27 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
_folder := Folder {
|
|
|
|
Entries : _entries,
|
|
|
|
Indices : _indexNames,
|
|
|
|
}
|
|
|
|
|
|
|
|
var _data []byte
|
|
|
|
if _data_0, _error := json.Marshal (&_folder); _error == nil {
|
|
|
|
_data = _data_0
|
|
|
|
} else {
|
|
|
|
return _error
|
|
|
|
}
|
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
if _, _, _error := archiveReferenceAndData (_context, NamespaceFoldersContent, _pathResolved, _pathInArchive, "", _data, MimeTypeJson); _error != nil {
|
2018-11-16 14:18:27 +00:00
|
|
|
return _error
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
func archiveReferenceAndData (_context *context, _namespace string, _pathResolved string, _pathInArchive string, _name string, _dataContent []byte, _dataType string) (string, string, error) {
|
2018-11-16 14:18:27 +00:00
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
var _fingerprintContent string
|
|
|
|
var _fingerprintMeta string
|
2018-11-16 14:18:27 +00:00
|
|
|
var _dataMeta map[string]string
|
2018-11-20 12:21:22 +00:00
|
|
|
var _dataMetaRaw []byte
|
|
|
|
|
|
|
|
if _fingerprintContent_0, _dataContent_0, _dataMeta_0, _error := prepareDataContent (_context, _pathResolved, _pathInArchive, _name, _dataContent, _dataType); _error != nil {
|
|
|
|
return "", "", _error
|
2018-11-16 14:18:27 +00:00
|
|
|
} else {
|
2018-11-20 12:21:22 +00:00
|
|
|
_fingerprintContent = _fingerprintContent_0
|
|
|
|
_dataContent = _dataContent_0
|
2018-11-16 14:18:27 +00:00
|
|
|
_dataMeta = _dataMeta_0
|
|
|
|
}
|
2018-11-20 12:21:22 +00:00
|
|
|
if _fingerprintMeta_0, _dataMetaRaw_0, _error := prepareDataMeta (_context, _dataMeta); _error != nil {
|
|
|
|
return "", "", _error
|
|
|
|
} else {
|
|
|
|
_fingerprintMeta = _fingerprintMeta_0
|
|
|
|
_dataMetaRaw = _dataMetaRaw_0
|
2018-11-16 14:18:27 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
if _error := archiveReference (_context, _namespace, _pathInArchive, _fingerprintContent, _fingerprintMeta); _error != nil {
|
|
|
|
return "", "", _error
|
|
|
|
}
|
|
|
|
if _dataMetaRaw != nil {
|
|
|
|
if _error := archiveDataMeta (_context, _fingerprintMeta, _dataMetaRaw); _error != nil {
|
|
|
|
return "", "", _error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _dataContent != nil {
|
|
|
|
if _error := archiveDataContent (_context, _fingerprintContent, _dataContent); _error != nil {
|
|
|
|
return "", "", _error
|
2018-11-16 14:18:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
return _fingerprintContent, _fingerprintMeta, nil
|
2018-11-16 14:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
|
|
|
|
func archiveDataContent (_context *context, _fingerprintContent string, _dataContent []byte) (error) {
|
2018-11-16 14:18:27 +00:00
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
if _wasStored, _ := _context.storedDataContent[_fingerprintContent]; _wasStored {
|
|
|
|
return fmt.Errorf ("[256cde78] data content already stored: `%s`!", _fingerprintContent)
|
2018-11-16 14:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-11-20 12:21:22 +00:00
|
|
|
_key := fmt.Sprintf ("%s:%s", NamespaceDataContent, _fingerprintContent)
|
2018-11-16 14:18:27 +00:00
|
|
|
if _context.debug {
|
2018-11-20 12:21:22 +00:00
|
|
|
log.Printf ("[ ] data-content ++ `%s`\n", _key)
|
2018-11-16 14:18:27 +00:00
|
|
|
}
|
2018-11-20 12:21:22 +00:00
|
|
|
if _error := _context.cdbWriter.Put ([]byte (_key), _dataContent); _error != nil {
|
2018-11-16 14:18:27 +00:00
|
|
|
return _error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
_context.storedDataContent[_fingerprintContent] = true
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func archiveDataMeta (_context *context, _fingerprintMeta string, _dataMeta []byte) (error) {
|
|
|
|
|
|
|
|
if _wasStored, _ := _context.storedDataMeta[_fingerprintMeta]; _wasStored {
|
|
|
|
return fmt.Errorf ("[2918c4e2] data meta already stored: `%s`!", _fingerprintMeta)
|
|
|
|
}
|
|
|
|
|
2018-11-16 14:18:27 +00:00
|
|
|
{
|
2018-11-20 12:21:22 +00:00
|
|
|
_key := fmt.Sprintf ("%s:%s", NamespaceDataMetadata, _fingerprintMeta)
|
2018-11-16 14:18:27 +00:00
|
|
|
if _context.debug {
|
2018-11-20 12:21:22 +00:00
|
|
|
log.Printf ("[ ] data-meta ++ `%s`\n", _key)
|
2018-11-16 14:18:27 +00:00
|
|
|
}
|
2018-11-20 12:21:22 +00:00
|
|
|
if _error := _context.cdbWriter.Put ([]byte (_key), _dataMeta); _error != nil {
|
2018-11-09 13:54:47 +00:00
|
|
|
return _error
|
|
|
|
}
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
_context.storedDataMeta[_fingerprintMeta] = true
|
2018-11-16 14:18:27 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
func archiveReference (_context *context, _namespace string, _pathInArchive string, _fingerprintContent string, _fingerprintMeta string) (error) {
|
|
|
|
|
|
|
|
switch _namespace {
|
|
|
|
case NamespaceFilesContent :
|
|
|
|
_context.storedFilePaths = append (_context.storedFilePaths, _pathInArchive)
|
|
|
|
case NamespaceFoldersContent :
|
|
|
|
_context.storedFolderPaths = append (_context.storedFolderPaths, _pathInArchive)
|
|
|
|
default :
|
|
|
|
return fmt.Errorf ("[051a102a]")
|
|
|
|
}
|
2018-11-16 14:18:27 +00:00
|
|
|
|
|
|
|
_key := fmt.Sprintf ("%s:%s", _namespace, _pathInArchive)
|
|
|
|
if _context.debug {
|
2018-11-20 12:21:22 +00:00
|
|
|
log.Printf ("[ ] reference ++ `%s` :: `%s` -> `%s` ~ `%s`\n", _namespace, _pathInArchive, _fingerprintContent[:16], _fingerprintMeta[:16])
|
2018-11-16 14:18:27 +00:00
|
|
|
}
|
2018-11-20 12:21:22 +00:00
|
|
|
|
|
|
|
_fingerprints := fmt.Sprintf ("%s:%s", _fingerprintContent, _fingerprintMeta)
|
|
|
|
if _error := _context.cdbWriter.Put ([]byte (_key), []byte (_fingerprints)); _error != nil {
|
2018-11-16 14:18:27 +00:00
|
|
|
return _error
|
|
|
|
}
|
|
|
|
|
2018-11-09 00:47:14 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
func prepareDataContent (_context *context, _pathResolved string, _pathInArchive string, _name string, _dataContent []byte, _dataType string) (string, []byte, map[string]string, error) {
|
2018-11-09 00:47:14 +00:00
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
_fingerprintContentRaw := sha256.Sum256 (_dataContent)
|
|
|
|
_fingerprintContent := hex.EncodeToString (_fingerprintContentRaw[:])
|
2018-11-09 00:47:14 +00:00
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
if _wasStored, _ := _context.storedDataContent[_fingerprintContent]; _wasStored {
|
|
|
|
_dataMeta := _context.storedDataContentMeta[_fingerprintContent]
|
|
|
|
return _fingerprintContent, nil, _dataMeta, nil
|
2018-11-16 14:18:27 +00:00
|
|
|
}
|
2018-11-09 00:47:14 +00:00
|
|
|
|
2018-11-09 13:54:47 +00:00
|
|
|
if (_dataType == "") && (_name != "") {
|
2018-11-14 17:01:08 +00:00
|
|
|
_extension := filepath.Ext (_name)
|
2018-11-09 13:54:47 +00:00
|
|
|
if _extension != "" {
|
|
|
|
_extension = _extension[1:]
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
2018-11-09 13:54:47 +00:00
|
|
|
_dataType, _ = MimeTypesByExtension[_extension]
|
|
|
|
}
|
|
|
|
if _dataType == "" {
|
2018-11-20 12:21:22 +00:00
|
|
|
_dataType = http.DetectContentType (_dataContent)
|
2018-11-09 13:54:47 +00:00
|
|
|
}
|
|
|
|
if _dataType == "" {
|
|
|
|
_dataType = MimeTypeRaw
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
|
2018-11-16 14:18:27 +00:00
|
|
|
_dataEncoding := "identity"
|
2018-11-20 12:21:22 +00:00
|
|
|
_dataUncompressedSize := len (_dataContent)
|
2018-11-16 14:18:27 +00:00
|
|
|
_dataSize := _dataUncompressedSize
|
|
|
|
if _dataSize > 512 {
|
2018-11-20 12:21:22 +00:00
|
|
|
if _dataContent_0, _dataEncoding_0, _error := Compress (_dataContent, _context.compress); _error == nil {
|
2018-11-16 14:18:27 +00:00
|
|
|
if _dataEncoding_0 != "identity" {
|
2018-11-20 12:21:22 +00:00
|
|
|
_dataCompressedSize := len (_dataContent_0)
|
2018-11-16 14:18:27 +00:00
|
|
|
_dataCompressedDelta := _dataUncompressedSize - _dataCompressedSize
|
|
|
|
_dataCompressedRatio := (_dataCompressedDelta * 100) / _dataUncompressedSize
|
|
|
|
_accepted := false
|
|
|
|
_accepted = _accepted || ((_dataUncompressedSize > (1024 * 1024)) && (_dataCompressedRatio >= 5))
|
|
|
|
_accepted = _accepted || ((_dataUncompressedSize > (64 * 1024)) && (_dataCompressedRatio >= 10))
|
|
|
|
_accepted = _accepted || ((_dataUncompressedSize > (32 * 1024)) && (_dataCompressedRatio >= 15))
|
|
|
|
_accepted = _accepted || ((_dataUncompressedSize > (16 * 1024)) && (_dataCompressedRatio >= 20))
|
|
|
|
_accepted = _accepted || ((_dataUncompressedSize > (8 * 1024)) && (_dataCompressedRatio >= 25))
|
|
|
|
_accepted = _accepted || ((_dataUncompressedSize > (4 * 1024)) && (_dataCompressedRatio >= 30))
|
|
|
|
_accepted = _accepted || ((_dataUncompressedSize > (2 * 1024)) && (_dataCompressedRatio >= 35))
|
|
|
|
_accepted = _accepted || ((_dataUncompressedSize > (1 * 1024)) && (_dataCompressedRatio >= 40))
|
|
|
|
_accepted = _accepted || (_dataCompressedRatio >= 90)
|
|
|
|
if _accepted {
|
2018-11-20 12:21:22 +00:00
|
|
|
_dataContent = _dataContent_0
|
2018-11-16 14:18:27 +00:00
|
|
|
_dataEncoding = _dataEncoding_0
|
|
|
|
_dataSize = _dataCompressedSize
|
|
|
|
}
|
|
|
|
if _dataSize < _dataUncompressedSize {
|
|
|
|
if _context.debug {
|
|
|
|
log.Printf ("[ ] compress %02d %8d %8d `%s`\n", _dataCompressedRatio, _dataUncompressedSize, _dataCompressedDelta, _pathInArchive)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if _context.debug {
|
|
|
|
log.Printf ("[ ] compress-NOK %02d %8d %8d `%s`\n", _dataCompressedRatio, _dataUncompressedSize, _dataCompressedDelta, _pathInArchive)
|
|
|
|
}
|
|
|
|
}
|
2018-11-09 13:54:47 +00:00
|
|
|
}
|
2018-11-16 14:18:27 +00:00
|
|
|
} else {
|
|
|
|
return "", nil, nil, _error
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
2018-11-14 17:01:08 +00:00
|
|
|
} else {
|
2018-11-16 14:18:27 +00:00
|
|
|
if _context.debug && (_context.compress != "identity") {
|
|
|
|
log.Printf ("[ ] compress-NOK %8d `%s`\n", _dataUncompressedSize, _pathInArchive)
|
2018-11-14 19:28:25 +00:00
|
|
|
}
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
|
2018-11-16 14:18:27 +00:00
|
|
|
_dataMeta := make (map[string]string, 16)
|
|
|
|
_dataMeta["Content-Length"] = fmt.Sprintf ("%d", _dataSize)
|
|
|
|
_dataMeta["Content-Type"] = _dataType
|
|
|
|
_dataMeta["Content-Encoding"] = _dataEncoding
|
2018-11-20 07:07:21 +00:00
|
|
|
if _context.includeEtag {
|
2018-11-20 12:21:22 +00:00
|
|
|
_dataMeta["ETag"] = _fingerprintContent
|
2018-11-20 07:07:21 +00:00
|
|
|
}
|
2018-11-14 17:01:08 +00:00
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
_context.storedDataContentMeta[_fingerprintContent] = _dataMeta
|
|
|
|
|
|
|
|
return _fingerprintContent, _dataContent, _dataMeta, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func prepareDataMeta (_context *context, _dataMeta map[string]string) (string, []byte, error) {
|
|
|
|
|
|
|
|
var _dataMetaRaw []byte
|
|
|
|
if _dataMetaRaw_0, _error := MetadataEncode (_dataMeta); _error == nil {
|
|
|
|
_dataMetaRaw = _dataMetaRaw_0
|
|
|
|
} else {
|
|
|
|
return "", nil, _error
|
|
|
|
}
|
|
|
|
|
|
|
|
_fingerprintMetaRaw := sha256.Sum256 (_dataMetaRaw)
|
|
|
|
_fingerprintMeta := hex.EncodeToString (_fingerprintMetaRaw[:])
|
|
|
|
|
|
|
|
if _wasStored, _ := _context.storedDataMeta[_fingerprintMeta]; _wasStored {
|
|
|
|
return _fingerprintMeta, nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return _fingerprintMeta, _dataMetaRaw, nil
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-17 15:36:18 +00:00
|
|
|
func walkPath (_context *context, _pathResolved string, _pathInArchive string, _name string, _recursed map[string]uint, _recurse bool) (os.FileInfo, error) {
|
2018-11-09 00:47:14 +00:00
|
|
|
|
|
|
|
if _recursed == nil {
|
|
|
|
_recursed = make (map[string]uint, 128)
|
|
|
|
}
|
|
|
|
|
2018-11-17 15:36:18 +00:00
|
|
|
_pathOriginal := _pathResolved
|
2018-11-09 00:47:14 +00:00
|
|
|
|
|
|
|
var _stat os.FileInfo
|
2018-11-17 15:36:18 +00:00
|
|
|
if _stat_0, _error := os.Lstat (_pathResolved); _error == nil {
|
2018-11-09 00:47:14 +00:00
|
|
|
_stat = _stat_0
|
|
|
|
} else {
|
2018-11-14 19:28:25 +00:00
|
|
|
return nil, _error
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
2018-11-15 19:32:24 +00:00
|
|
|
_statMode := _stat.Mode ()
|
2018-11-09 00:47:14 +00:00
|
|
|
|
|
|
|
_isSymlink := false
|
|
|
|
if (_stat.Mode () & os.ModeSymlink) != 0 {
|
|
|
|
_isSymlink = true
|
2018-11-17 15:36:18 +00:00
|
|
|
if _stat_0, _error := os.Stat (_pathResolved); _error == nil {
|
2018-11-09 00:47:14 +00:00
|
|
|
_stat = _stat_0
|
|
|
|
} else {
|
2018-11-14 19:28:25 +00:00
|
|
|
return nil, _error
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-15 19:32:24 +00:00
|
|
|
_statMode = _stat.Mode ()
|
|
|
|
|
|
|
|
if ! _recurse {
|
|
|
|
return _stat, nil
|
|
|
|
}
|
2018-11-09 00:47:14 +00:00
|
|
|
|
|
|
|
if _isSymlink {
|
2018-11-17 15:36:18 +00:00
|
|
|
if _pathResolved_0, _error := filepath.EvalSymlinks (_pathResolved); _error == nil {
|
|
|
|
_pathResolved = _pathResolved_0
|
2018-11-09 00:47:14 +00:00
|
|
|
} else {
|
2018-11-14 19:28:25 +00:00
|
|
|
return nil, _error
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-09 13:54:47 +00:00
|
|
|
if _isSymlink && _context.debug {
|
2018-11-16 14:18:27 +00:00
|
|
|
log.Printf ("[ ] symlink :: `%s` -> `%s`\n", _pathInArchive, _pathResolved)
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
|
2018-11-15 19:32:24 +00:00
|
|
|
|
|
|
|
if _statMode.IsRegular () {
|
2018-11-09 00:47:14 +00:00
|
|
|
|
2018-11-09 13:54:47 +00:00
|
|
|
if _context.debug {
|
2018-11-16 14:18:27 +00:00
|
|
|
log.Printf ("[ ] file :: `%s`\n", _pathInArchive)
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
2018-11-15 19:32:24 +00:00
|
|
|
if _error := archiveFile (_context, _pathResolved, _pathInArchive, _name); _error != nil {
|
2018-11-17 17:18:45 +00:00
|
|
|
return nil, _error
|
2018-11-15 19:32:24 +00:00
|
|
|
}
|
|
|
|
return _stat, nil
|
2018-11-09 00:47:14 +00:00
|
|
|
|
2018-11-15 19:32:24 +00:00
|
|
|
} else if _statMode.IsDir () {
|
2018-11-09 00:47:14 +00:00
|
|
|
|
|
|
|
_wasRecursed, _ := _recursed[_pathResolved]
|
|
|
|
if _wasRecursed > 0 {
|
2018-11-17 15:36:18 +00:00
|
|
|
log.Printf ("[ww] [2e1744c9] detected directory loop for `%s` resolving to `%s`; ignoring!\n", _pathOriginal, _pathResolved)
|
2018-11-14 19:28:25 +00:00
|
|
|
return _stat, nil
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
_recursed[_pathResolved] = _wasRecursed + 1
|
|
|
|
|
2018-11-17 15:36:18 +00:00
|
|
|
_childsName := make ([]string, 0, 16)
|
|
|
|
_childsPathResolved := make (map[string]string, 16)
|
|
|
|
_childsPathInArchive := make (map[string]string, 16)
|
|
|
|
_childsStat := make (map[string]os.FileInfo, 16)
|
2018-11-09 00:47:14 +00:00
|
|
|
|
2018-11-17 17:18:45 +00:00
|
|
|
var _wildcardName string
|
|
|
|
|
2018-11-15 19:32:24 +00:00
|
|
|
if _context.debug {
|
2018-11-16 14:18:27 +00:00
|
|
|
log.Printf ("[ ] folder >> `%s`\n", _pathInArchive)
|
2018-11-15 19:32:24 +00:00
|
|
|
}
|
2018-11-17 15:36:18 +00:00
|
|
|
if _stream, _error := os.Open (_pathResolved); _error == nil {
|
2018-11-09 00:47:14 +00:00
|
|
|
defer _stream.Close ()
|
|
|
|
_loop : for {
|
|
|
|
switch _buffer, _error := _stream.Readdir (128); _error {
|
|
|
|
case nil :
|
2018-11-17 15:36:18 +00:00
|
|
|
for _, _childStat := range _buffer {
|
2018-11-17 17:18:45 +00:00
|
|
|
|
2018-11-17 15:36:18 +00:00
|
|
|
_childName := _childStat.Name ()
|
|
|
|
_childPathResolved := filepath.Join (_pathResolved, _childName)
|
|
|
|
_childPathInArchive := filepath.Join (_pathInArchive, _childName)
|
2018-11-17 17:18:45 +00:00
|
|
|
|
|
|
|
if _childStat_0, _error := walkPath (_context, _childPathResolved, _childPathInArchive, _childName, _recursed, false); _error == nil {
|
|
|
|
_childStat = _childStat_0
|
|
|
|
} else {
|
|
|
|
return nil, _error
|
|
|
|
}
|
|
|
|
|
|
|
|
_childsPathResolved[_childName] = _childPathResolved
|
|
|
|
_childsPathInArchive[_childName] = _childPathInArchive
|
|
|
|
_childsStat[_childName] = _childStat
|
|
|
|
|
|
|
|
if strings.HasPrefix (_childName, "_wildcard.") {
|
|
|
|
_wildcardName = _childName
|
|
|
|
continue
|
|
|
|
}
|
2018-11-17 15:36:18 +00:00
|
|
|
if ShouldSkipName (_childName) {
|
2018-11-17 14:56:58 +00:00
|
|
|
if _context.debug {
|
2018-11-17 15:36:18 +00:00
|
|
|
log.Printf ("[ ] skip !! `%s`\n", _childPathInArchive)
|
2018-11-17 14:56:58 +00:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
2018-11-17 17:18:45 +00:00
|
|
|
|
2018-11-17 15:36:18 +00:00
|
|
|
_childsName = append (_childsName, _childName)
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
case io.EOF :
|
|
|
|
break _loop
|
|
|
|
default :
|
2018-11-14 19:28:25 +00:00
|
|
|
return nil, _error
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-09 13:54:47 +00:00
|
|
|
if _context.debug {
|
2018-11-16 14:18:27 +00:00
|
|
|
log.Printf ("[ ] folder << `%s`\n", _pathInArchive)
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
|
2018-11-17 15:36:18 +00:00
|
|
|
sort.Strings (_childsName)
|
2018-11-15 19:32:24 +00:00
|
|
|
|
2018-11-09 13:54:47 +00:00
|
|
|
if _context.debug {
|
2018-11-16 14:18:27 +00:00
|
|
|
log.Printf ("[ ] folder :: `%s`\n", _pathInArchive)
|
2018-11-09 18:58:38 +00:00
|
|
|
}
|
2018-11-17 15:36:18 +00:00
|
|
|
if _error := archiveFolder (_context, _pathResolved, _pathInArchive, _childsName, _childsStat); _error != nil {
|
2018-11-14 19:28:25 +00:00
|
|
|
return nil, _error
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
|
2018-11-17 17:18:45 +00:00
|
|
|
if _wildcardName != "" {
|
|
|
|
_childPathInArchive := filepath.Join (_pathInArchive, "*")
|
|
|
|
if _, _error := walkPath (_context, _childsPathResolved[_wildcardName], _childPathInArchive, _wildcardName, _recursed, true); _error != nil {
|
|
|
|
return nil, _error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 19:32:24 +00:00
|
|
|
if _context.debug {
|
2018-11-16 14:18:27 +00:00
|
|
|
log.Printf ("[ ] folder >> `%s`\n", _pathInArchive)
|
2018-11-15 19:32:24 +00:00
|
|
|
}
|
2018-11-17 15:36:18 +00:00
|
|
|
for _, _childName := range _childsName {
|
|
|
|
if _childsStat[_childName] .Mode () .IsRegular () {
|
|
|
|
if _, _error := walkPath (_context, _childsPathResolved[_childName], _childsPathInArchive[_childName], _childName, _recursed, true); _error != nil {
|
2018-11-17 17:18:45 +00:00
|
|
|
return nil, _error
|
2018-11-15 19:32:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-17 15:36:18 +00:00
|
|
|
for _, _childName := range _childsName {
|
|
|
|
if _childsStat[_childName] .Mode () .IsDir () {
|
|
|
|
if _, _error := walkPath (_context, _childsPathResolved[_childName], _childsPathInArchive[_childName], _childName, _recursed, true); _error != nil {
|
2018-11-17 17:18:45 +00:00
|
|
|
return nil, _error
|
2018-11-15 19:32:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-17 15:36:18 +00:00
|
|
|
for _, _childName := range _childsName {
|
|
|
|
if (! _childsStat[_childName] .Mode () .IsRegular ()) && (! _childsStat[_childName] .Mode () .IsDir ()) {
|
|
|
|
if _, _error := walkPath (_context, _childsPathResolved[_childName], _childsPathInArchive[_childName], _childName, _recursed, true); _error != nil {
|
2018-11-17 17:18:45 +00:00
|
|
|
return nil, _error
|
2018-11-15 19:32:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _context.debug {
|
2018-11-16 14:18:27 +00:00
|
|
|
log.Printf ("[ ] folder << `%s`\n", _pathInArchive)
|
2018-11-15 19:32:24 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 00:47:14 +00:00
|
|
|
_recursed[_pathResolved] = _wasRecursed
|
2018-11-14 19:28:25 +00:00
|
|
|
return _stat, nil
|
2018-11-09 00:47:14 +00:00
|
|
|
|
|
|
|
} else {
|
2018-11-17 15:36:18 +00:00
|
|
|
return nil, fmt.Errorf ("[d9b836d7] unexpected file type for `%s`: `%s`!", _pathResolved, _statMode)
|
2018-11-09 00:47:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func main () () {
|
|
|
|
Main (main_0)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main_0 () (error) {
|
|
|
|
|
|
|
|
|
|
|
|
var _sourcesFolder string
|
|
|
|
var _archiveFile string
|
2018-11-09 13:54:47 +00:00
|
|
|
var _compress string
|
2018-11-15 18:46:38 +00:00
|
|
|
var _includeIndex bool
|
2018-11-20 12:49:43 +00:00
|
|
|
var _includeStripped bool
|
2018-11-20 07:07:21 +00:00
|
|
|
var _includeEtag bool
|
2018-11-20 12:21:22 +00:00
|
|
|
var _includeFileListing bool
|
|
|
|
var _includeFolderListing bool
|
2018-11-09 00:47:14 +00:00
|
|
|
var _debug bool
|
|
|
|
|
|
|
|
{
|
2018-11-18 16:11:36 +00:00
|
|
|
_flags := flag.NewFlagSet ("kawipiko-archiver", flag.ContinueOnError)
|
2018-11-09 00:47:14 +00:00
|
|
|
|
2018-11-15 18:17:52 +00:00
|
|
|
_flags.Usage = func () () {
|
|
|
|
fmt.Fprintf (os.Stderr, "%s",
|
|
|
|
`
|
2018-11-18 15:50:08 +00:00
|
|
|
==== kawipiko -- blazingly fast static HTTP server ====
|
|
|
|
|
|
|
|
| Documentation, issues and sources:
|
2018-11-18 16:11:36 +00:00
|
|
|
| * https://github.com/volution/kawipiko
|
2018-11-18 15:50:08 +00:00
|
|
|
| Authors:
|
|
|
|
| * Ciprian Dorin Craciun
|
|
|
|
| ciprian@volution.ro
|
|
|
|
| ciprian.craciun@gmail.com
|
|
|
|
| https://volution.ro/ciprian
|
|
|
|
-----------------------------------------------------------
|
|
|
|
|
2018-11-18 16:11:36 +00:00
|
|
|
kawipiko-archiver
|
2018-11-18 15:50:08 +00:00
|
|
|
|
|
|
|
--sources <path>
|
|
|
|
|
|
|
|
--archive <path>
|
|
|
|
--compress <gzip | brotli | identity>
|
2018-11-20 12:21:22 +00:00
|
|
|
|
2018-11-18 15:50:08 +00:00
|
|
|
--exclude-index
|
2018-11-20 12:49:43 +00:00
|
|
|
--exclude-strip
|
2018-11-20 07:07:21 +00:00
|
|
|
--exclude-etag
|
2018-11-20 12:21:22 +00:00
|
|
|
|
|
|
|
--exclude-file-listing
|
|
|
|
--include-folder-listing
|
2018-11-18 15:50:08 +00:00
|
|
|
|
|
|
|
--debug
|
|
|
|
|
2019-08-11 17:30:27 +00:00
|
|
|
** for details see:
|
|
|
|
https://github.com/volution/kawipiko#kawipiko-archiver
|
|
|
|
|
2018-11-15 18:17:52 +00:00
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
|
|
|
_sourcesFolder_0 := _flags.String ("sources", "", "")
|
|
|
|
_archiveFile_0 := _flags.String ("archive", "", "")
|
|
|
|
_compress_0 := _flags.String ("compress", "", "")
|
2018-11-15 18:46:38 +00:00
|
|
|
_excludeIndex_0 := _flags.Bool ("exclude-index", false, "")
|
2018-11-20 12:49:43 +00:00
|
|
|
_excludeStripped_0 := _flags.Bool ("exclude-strip", false, "")
|
2018-11-20 07:07:21 +00:00
|
|
|
_excludeEtag_0 := _flags.Bool ("exclude-etag", false, "")
|
2019-05-16 19:15:40 +00:00
|
|
|
_excludeFileListing_0 := _flags.Bool ("exclude-file-listing", false, "")
|
|
|
|
_includeFolderListing_0 := _flags.Bool ("include-folder-listing", false, "")
|
2018-11-09 00:47:14 +00:00
|
|
|
_debug_0 := _flags.Bool ("debug", false, "")
|
|
|
|
|
|
|
|
FlagsParse (_flags, 0, 0)
|
|
|
|
|
|
|
|
_sourcesFolder = *_sourcesFolder_0
|
|
|
|
_archiveFile = *_archiveFile_0
|
2018-11-09 13:54:47 +00:00
|
|
|
_compress = *_compress_0
|
2018-11-15 18:46:38 +00:00
|
|
|
_includeIndex = ! *_excludeIndex_0
|
2018-11-20 12:49:43 +00:00
|
|
|
_includeStripped = ! *_excludeStripped_0
|
2018-11-20 07:07:21 +00:00
|
|
|
_includeEtag = ! *_excludeEtag_0
|
2018-11-20 12:21:22 +00:00
|
|
|
_includeFileListing = ! *_excludeFileListing_0
|
|
|
|
_includeFolderListing = *_includeFolderListing_0
|
2018-11-09 00:47:14 +00:00
|
|
|
_debug = *_debug_0
|
|
|
|
|
|
|
|
if _sourcesFolder == "" {
|
|
|
|
AbortError (nil, "[515ee462] expected sources folder argument!")
|
|
|
|
}
|
|
|
|
if _archiveFile == "" {
|
|
|
|
AbortError (nil, "[5e8da985] expected archive file argument!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var _cdbWriter *cdb.Writer
|
|
|
|
if _cdbWriter_0, _error := cdb.Create (_archiveFile); _error == nil {
|
|
|
|
_cdbWriter = _cdbWriter_0
|
|
|
|
} else {
|
|
|
|
AbortError (_error, "[85234ba0] failed creating archive (while opening)!")
|
|
|
|
}
|
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
if _error := _cdbWriter.Put ([]byte (NamespaceSchemaVersion), []byte (CurrentSchemaVersion)); _error != nil {
|
|
|
|
AbortError (_error, "[43228812] failed writing archive!")
|
|
|
|
}
|
|
|
|
|
2018-11-09 13:54:47 +00:00
|
|
|
_context := & context {
|
|
|
|
cdbWriter : _cdbWriter,
|
2018-11-20 12:21:22 +00:00
|
|
|
storedFilePaths : make ([]string, 0, 16 * 1024),
|
|
|
|
storedFolderPaths : make ([]string, 0, 16 * 1024),
|
|
|
|
storedDataMeta : make (map[string]bool, 16 * 1024),
|
|
|
|
storedDataContent : make (map[string]bool, 16 * 1024),
|
|
|
|
storedDataContentMeta : make (map[string]map[string]string, 16 * 1024),
|
|
|
|
storedFiles : make (map[[2]uint64][2]string, 16 * 1024),
|
2018-11-09 13:54:47 +00:00
|
|
|
compress : _compress,
|
2018-11-15 18:46:38 +00:00
|
|
|
includeIndex : _includeIndex,
|
2018-11-20 12:49:43 +00:00
|
|
|
includeStripped : _includeStripped,
|
2018-11-20 07:07:21 +00:00
|
|
|
includeEtag : _includeEtag,
|
2018-11-20 12:21:22 +00:00
|
|
|
includeFileListing : _includeFileListing,
|
|
|
|
includeFolderListing : _includeFolderListing,
|
2018-11-09 13:54:47 +00:00
|
|
|
debug : _debug,
|
|
|
|
}
|
|
|
|
|
2018-11-17 15:36:18 +00:00
|
|
|
if _, _error := walkPath (_context, _sourcesFolder, "/", filepath.Base (_sourcesFolder), nil, true); _error != nil {
|
2018-11-09 00:47:14 +00:00
|
|
|
AbortError (_error, "[b6a19ef4] failed walking folder!")
|
|
|
|
}
|
|
|
|
|
2018-11-20 12:21:22 +00:00
|
|
|
if _includeFileListing {
|
|
|
|
_buffer := make ([]byte, 0, 1024 * 1024)
|
|
|
|
for _, _path := range _context.storedFilePaths {
|
|
|
|
_buffer = append (_buffer, _path ...)
|
|
|
|
_buffer = append (_buffer, '\n')
|
|
|
|
}
|
|
|
|
if _error := _cdbWriter.Put ([]byte (NamespaceFilesIndex), _buffer); _error != nil {
|
|
|
|
AbortError (_error, "[1dbdde05] failed writing archive!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if _includeFolderListing {
|
|
|
|
_buffer := make ([]byte, 0, 1024 * 1024)
|
|
|
|
for _, _path := range _context.storedFolderPaths {
|
|
|
|
_buffer = append (_buffer, _path ...)
|
|
|
|
_buffer = append (_buffer, '\n')
|
|
|
|
}
|
|
|
|
if _error := _cdbWriter.Put ([]byte (NamespaceFoldersIndex), _buffer); _error != nil {
|
|
|
|
AbortError (_error, "[e2dd2de0] failed writing archive!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-09 00:47:14 +00:00
|
|
|
if _error := _cdbWriter.Close (); _error != nil {
|
|
|
|
AbortError (_error, "[bbfb8478] failed creating archive (while closing)!")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|