From c83d762a75aebaf075bfc454e3d0485b1fe1e4c9 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 23 Feb 2022 22:13:21 -0500 Subject: nvdmirror: add nvdmirror/util.go --- nvdmirror/nvdmirror.go | 23 ----------------------- nvdmirror/util.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 23 deletions(-) create mode 100644 nvdmirror/util.go diff --git a/nvdmirror/nvdmirror.go b/nvdmirror/nvdmirror.go index aeb5c24..546a0ed 100644 --- a/nvdmirror/nvdmirror.go +++ b/nvdmirror/nvdmirror.go @@ -8,7 +8,6 @@ import ( "fmt" "github.com/pablotron/cvez/atomictemp" "github.com/pablotron/cvez/feed" - "github.com/rs/zerolog" "github.com/rs/zerolog/log" "io" "io/fs" @@ -195,16 +194,6 @@ func (me syncContext) getFileHash(path string) ([32]byte, error) { return r, nil } -// Get file size, in bytes. -func getFileSize(path string) (uint64, error) { - // verify that full path exists - if st, err := os.Stat(path); err != nil { - return 0, err - } else { - return uint64(st.Size()), err - } -} - // Check the size and hash in the metadata file against the full file. // // Note: This method is called from a goroutine and returns it's value @@ -260,18 +249,6 @@ func (me syncContext) check(metaUrl, fullUrl string) { me.ch <- r } -// log array of strings -func logArray(key string, strs []string) { - // populate array - a := zerolog.Arr() - for _, v := range(strs) { - a.Str(v) - } - - // log array - log.Info().Array(key, a).Send() -} - // Sync to destination directory and return an array of updated files. func Sync(config SyncConfig, cache Cache, dstDir string) []string { // log.Debug().Str("dstDir", dstDir).Msg("Sync") diff --git a/nvdmirror/util.go b/nvdmirror/util.go new file mode 100644 index 0000000..9cf7d3a --- /dev/null +++ b/nvdmirror/util.go @@ -0,0 +1,29 @@ +package nvdmirror + +import ( + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" + "os" +) + +// Get file size, in bytes. +func getFileSize(path string) (uint64, error) { + // verify that full path exists + if st, err := os.Stat(path); err != nil { + return 0, err + } else { + return uint64(st.Size()), err + } +} + +// log array of strings +func logArray(key string, strs []string) { + // populate array + a := zerolog.Arr() + for _, v := range(strs) { + a.Str(v) + } + + // log array + log.Info().Array(key, a).Send() +} -- cgit v1.2.3