Merge "pkg/index: ignore unset msdos time when possible"

This commit is contained in:
Brad Fitzpatrick 2018-01-03 06:18:09 +00:00 committed by Gerrit Code Review
commit eb0024f164
3 changed files with 25 additions and 5 deletions

View File

@ -327,7 +327,7 @@ var corpusMergeFunc = map[string]func(c *Corpus, k, v []byte) error{
"signerkeyid": (*Corpus).mergeSignerKeyIdRow, "signerkeyid": (*Corpus).mergeSignerKeyIdRow,
"claim": (*Corpus).mergeClaimRow, "claim": (*Corpus).mergeClaimRow,
"fileinfo": (*Corpus).mergeFileInfoRow, "fileinfo": (*Corpus).mergeFileInfoRow,
"filetimes": (*Corpus).mergeFileTimesRow, keyFileTimes.name: (*Corpus).mergeFileTimesRow,
"imagesize": (*Corpus).mergeImageSizeRow, "imagesize": (*Corpus).mergeImageSizeRow,
"wholetofile": (*Corpus).mergeWholeToFileRow, "wholetofile": (*Corpus).mergeWholeToFileRow,
"exifgps": (*Corpus).mergeEXIFGPSRow, "exifgps": (*Corpus).mergeEXIFGPSRow,
@ -350,7 +350,7 @@ var slurpPrefixes = []string{
"signerkeyid:", "signerkeyid:",
"claim|", "claim|",
"fileinfo|", "fileinfo|",
"filetimes|", keyFileTimes.name + "|",
"imagesize|", "imagesize|",
"wholetofile|", "wholetofile|",
"exifgps|", "exifgps|",

View File

@ -1229,7 +1229,7 @@ func (x *Index) GetFileInfo(ctx context.Context, fileRef blob.Ref) (camtypes.Fil
return x.corpus.GetFileInfo(ctx, fileRef) return x.corpus.GetFileInfo(ctx, fileRef)
} }
ikey := "fileinfo|" + fileRef.String() ikey := "fileinfo|" + fileRef.String()
tkey := "filetimes|" + fileRef.String() tkey := keyFileTimes.name + "|" + fileRef.String()
// TODO: switch this to use syncutil.Group // TODO: switch this to use syncutil.Group
wg := new(sync.WaitGroup) wg := new(sync.WaitGroup)
wg.Add(2) wg.Add(2)

View File

@ -50,6 +50,14 @@ import (
"perkeep.org/pkg/schema" "perkeep.org/pkg/schema"
) )
func init() {
t, err := time.Parse(time.RFC3339, msdosEpoch)
if err != nil {
panic(fmt.Sprintf("Cannot parse MSDOS epoch: %v", err))
}
msdosEpochTime = t
}
type mutationMap struct { type mutationMap struct {
kv map[string]string // the keys and values we populate kv map[string]string // the keys and values we populate
@ -424,7 +432,12 @@ func readPrefixOrFile(prefix []byte, fetcher blob.Fetcher, b *schema.Blob, fn fu
return err return err
} }
var exifDebug, _ = strconv.ParseBool(os.Getenv("CAMLI_DEBUG_IMAGES")) const msdosEpoch = "1980-01-01T00:00:00Z"
var (
exifDebug, _ = strconv.ParseBool(os.Getenv("CAMLI_DEBUG_IMAGES"))
msdosEpochTime time.Time
)
// b: the parsed file schema blob // b: the parsed file schema blob
// mm: keys to populate // mm: keys to populate
@ -506,7 +519,14 @@ func (ix *Index) populateFile(fetcher blob.Fetcher, b *schema.Blob, mm *mutation
time3339s = types.Time3339(sortTimes[0]).String() time3339s = types.Time3339(sortTimes[0]).String()
case len(sortTimes) >= 2: case len(sortTimes) >= 2:
oldest, newest := sortTimes[0], sortTimes[len(sortTimes)-1] oldest, newest := sortTimes[0], sortTimes[len(sortTimes)-1]
time3339s = types.Time3339(oldest).String() + "," + types.Time3339(newest).String() // Common enough exception: unset creation time from an MSDOS
// system (which is the default in zip files). So if we have
// another time to use, just ignore the MSDOS epoch one.
if oldest.After(msdosEpochTime) {
time3339s = types.Time3339(oldest).String() + "," + types.Time3339(newest).String()
} else {
time3339s = types.Time3339(newest).String()
}
} }
mm.Set(keyWholeToFileRef.Key(wholeRef, blobRef), "1") mm.Set(keyWholeToFileRef.Key(wholeRef, blobRef), "1")