From 62b2c891fa3cc848236e55676baca51238b01129 Mon Sep 17 00:00:00 2001 From: Ciprian Dorin Craciun Date: Sat, 17 Nov 2018 15:49:17 +0200 Subject: [PATCH] [archiver] Add support for extensions stripping --- sources/cmd/archiver.go | 45 +++++++++++++++++++++++++---------- sources/lib/archiver/index.go | 6 +++++ 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/sources/cmd/archiver.go b/sources/cmd/archiver.go index ceea959..255e216 100644 --- a/sources/cmd/archiver.go +++ b/sources/cmd/archiver.go @@ -15,6 +15,7 @@ import "net/http" import "path/filepath" import "os" import "sort" +import "strings" import "syscall" // import "github.com/colinmarc/cdb" @@ -61,29 +62,47 @@ func archiveFile (_context *context, _pathResolved string, _pathInArchive string } _fingerprint, _wasStored := _context.storedFiles[_fileId] + var _data []byte + var _dataMeta map[string]string - if _wasStored { - if _error := archiveReference (_context, NamespaceFilesContent, _pathInArchive, _fingerprint); _error != nil { + if ! _wasStored { + + if _data_0, _error := ioutil.ReadAll (_file); _error == nil { + _data = _data_0 + } else { return _error } - return 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 + } } - var _data []byte - if _data_0, _error := ioutil.ReadAll (_file); _error == nil { - _data = _data_0 - } else { + 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 _fingerprint_0, _error := archiveReferenceAndData (_context, NamespaceFilesContent, _pathResolved, _pathInArchive, _name, _data, ""); _error != nil { - return _error - } else { - _fingerprint = _fingerprint_0 + if ! _wasStored { + if _error := archiveData (_context, _fingerprint, _data, _dataMeta); _error != nil { + return _error + } + _context.storedFiles[_fileId] = _fingerprint } - _context.storedFiles[_fileId] = _fingerprint - return nil } diff --git a/sources/lib/archiver/index.go b/sources/lib/archiver/index.go index cc46b35..eac4012 100644 --- a/sources/lib/archiver/index.go +++ b/sources/lib/archiver/index.go @@ -11,3 +11,9 @@ var IndexNames = []string { "index.xml", } +var StripExtensions = []string { + ".html", ".htm", + ".xhtml", ".xht", + ".txt", + } +