[archiver] Add support for skipping files based on prefixes, suffixes, infixes and whole names
This commit is contained in:
parent
62b2c891fa
commit
bb01349a9f
2 changed files with 71 additions and 5 deletions
|
@ -82,9 +82,9 @@ func archiveFile (_context *context, _pathResolved string, _pathInArchive string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, _extension := range StripExtensions {
|
for _, _suffix := range StripSuffixes {
|
||||||
if strings.HasSuffix (_pathInArchive, _extension) {
|
if strings.HasSuffix (_pathInArchive, _suffix) {
|
||||||
_pathInArchive := _pathInArchive [: len (_pathInArchive) - len (_extension)]
|
_pathInArchive := _pathInArchive [: len (_pathInArchive) - len (_suffix)]
|
||||||
if _error := archiveReference (_context, NamespaceFilesContent, _pathInArchive, _fingerprint); _error != nil {
|
if _error := archiveReference (_context, NamespaceFilesContent, _pathInArchive, _fingerprint); _error != nil {
|
||||||
return _error
|
return _error
|
||||||
}
|
}
|
||||||
|
@ -96,10 +96,13 @@ func archiveFile (_context *context, _pathResolved string, _pathInArchive string
|
||||||
return _error
|
return _error
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! _wasStored {
|
if (_data != nil) && (_dataMeta != nil) {
|
||||||
if _error := archiveData (_context, _fingerprint, _data, _dataMeta); _error != nil {
|
if _error := archiveData (_context, _fingerprint, _data, _dataMeta); _error != nil {
|
||||||
return _error
|
return _error
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! _wasStored {
|
||||||
_context.storedFiles[_fileId] = _fingerprint
|
_context.storedFiles[_fileId] = _fingerprint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,6 +443,12 @@ func walkPath (_context *context, _path string, _prefix string, _name string, _r
|
||||||
case nil :
|
case nil :
|
||||||
for _, _stat := range _buffer {
|
for _, _stat := range _buffer {
|
||||||
_name := _stat.Name ()
|
_name := _stat.Name ()
|
||||||
|
if ShouldSkipName (_name) {
|
||||||
|
if _context.debug {
|
||||||
|
log.Printf ("[ ] skip !! `%s`\n", filepath.Join (_prefix, _name))
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
_names = append (_names, _name)
|
_names = append (_names, _name)
|
||||||
if _stat, _error := walkPath (_context, filepath.Join (_path, _name), _prefix, _name, _recursed, false); _error == nil {
|
if _stat, _error := walkPath (_context, filepath.Join (_path, _name), _prefix, _name, _recursed, false); _error == nil {
|
||||||
_stats[_name] = _stat
|
_stats[_name] = _stat
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
package archiver
|
package archiver
|
||||||
|
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var IndexNames = []string {
|
var IndexNames = []string {
|
||||||
"index.html", "index.htm",
|
"index.html", "index.htm",
|
||||||
"index.xhtml", "index.xht",
|
"index.xhtml", "index.xht",
|
||||||
|
@ -11,9 +16,61 @@ var IndexNames = []string {
|
||||||
"index.xml",
|
"index.xml",
|
||||||
}
|
}
|
||||||
|
|
||||||
var StripExtensions = []string {
|
|
||||||
|
var StripSuffixes = []string {
|
||||||
".html", ".htm",
|
".html", ".htm",
|
||||||
".xhtml", ".xht",
|
".xhtml", ".xht",
|
||||||
".txt",
|
".txt",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var SkipPrefixes = []string {
|
||||||
|
".",
|
||||||
|
"#",
|
||||||
|
}
|
||||||
|
|
||||||
|
var SkipSuffixes = []string {
|
||||||
|
"~",
|
||||||
|
"#",
|
||||||
|
".log",
|
||||||
|
".tmp",
|
||||||
|
".temp",
|
||||||
|
".lock",
|
||||||
|
}
|
||||||
|
|
||||||
|
var SkipInfixes = []string {
|
||||||
|
"#",
|
||||||
|
}
|
||||||
|
|
||||||
|
var SkipNames = []string {
|
||||||
|
"Thumbs.db",
|
||||||
|
".DS_Store",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func ShouldSkipName (_name string) (bool) {
|
||||||
|
for _, _skipName := range SkipNames {
|
||||||
|
if _skipName == _name {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, _skipPrefix := range SkipPrefixes {
|
||||||
|
if strings.HasPrefix (_name, _skipPrefix) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, _skipSuffix := range SkipSuffixes {
|
||||||
|
if strings.HasSuffix (_name, _skipSuffix) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, _skipInfix := range SkipInfixes {
|
||||||
|
if strings.Contains (_name, _skipInfix) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue