aboutsummaryrefslogtreecommitdiff
path: root/nvdmirror/sync.go
blob: 8cdd4c721770035d7c578af3ee927e20269b3f79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package nvdmirror

// Sync to destination directory based on given sync configuration and
// cache.  Returns an array of file names which have been updated in the
// destination directory.
//
// This function does the following:
//
// 1. Fetch the contents of the source meta URLs for CVE feeds and
//    CPE matches.  All source URLs are fetched concurrently.
//
// 2. Check the size and hash from meta files against the existing
//    CVE feed and CPE match files in the destination directory.  All
//    file sizes and hashes are checked concurrently.
//
// 3. Fetch the contents of the changed CVE feeds, CPE match files, and
//    the CPE dictionary.
//
// All HTTP requests are made with the following request headers:
//
// * if-modified-since (if the URL was queried previously and the
//   previous successful response had a "last-modified" header).
// * if-none-match (if the URL was queried previously and the
//   previous successful response had an "etag" header).
// * user-agent
//
func Sync(config SyncConfig, cache Cache, dstDir string) []string {
  // build sync context
  ctx := newSyncContext(config, cache, dstDir)

  // fetch updated meta files
  checks := ctx.fetchMetas()

  // get syncable URLs
  urls := append(ctx.checkMetas(checks), config.GetCpeDictUrl())

  // sync urls and return changed files
  return ctx.syncUrls(urls)
}