[archiver] Add support for extensions stripping

This commit is contained in:
Ciprian Dorin Craciun 2018-11-17 15:49:17 +02:00
parent 0cd82ecb44
commit 62b2c891fa
2 changed files with 38 additions and 13 deletions

View file

@ -15,6 +15,7 @@ import "net/http"
import "path/filepath"
import "os"
import "sort"
import "strings"
import "syscall"
// import "github.com/colinmarc/cdb"
@ -61,28 +62,46 @@ func archiveFile (_context *context, _pathResolved string, _pathInArchive string
}
_fingerprint, _wasStored := _context.storedFiles[_fileId]
if _wasStored {
if _error := archiveReference (_context, NamespaceFilesContent, _pathInArchive, _fingerprint); _error != nil {
return _error
}
return nil
}
var _data []byte
var _dataMeta map[string]string
if ! _wasStored {
if _data_0, _error := ioutil.ReadAll (_file); _error == nil {
_data = _data_0
} else {
return _error
}
if _fingerprint_0, _error := archiveReferenceAndData (_context, NamespaceFilesContent, _pathResolved, _pathInArchive, _name, _data, ""); _error != nil {
if _fingerprint_0, _data_0, _dataMeta_0, _error := prepareData (_context, _pathResolved, _pathInArchive, _name, _data, ""); _error != nil {
return _error
} else {
_fingerprint = _fingerprint_0
_data = _data_0
_dataMeta = _dataMeta_0
}
}
for _, _extension := range StripExtensions {
if strings.HasSuffix (_pathInArchive, _extension) {
_pathInArchive := _pathInArchive [: len (_pathInArchive) - len (_extension)]
if _error := archiveReference (_context, NamespaceFilesContent, _pathInArchive, _fingerprint); _error != nil {
return _error
}
break
}
}
if _error := archiveReference (_context, NamespaceFilesContent, _pathInArchive, _fingerprint); _error != nil {
return _error
}
if ! _wasStored {
if _error := archiveData (_context, _fingerprint, _data, _dataMeta); _error != nil {
return _error
}
_context.storedFiles[_fileId] = _fingerprint
}
return nil
}

View file

@ -11,3 +11,9 @@ var IndexNames = []string {
"index.xml",
}
var StripExtensions = []string {
".html", ".htm",
".xhtml", ".xht",
".txt",
}