From ce4600f7b35e21f03c584a54ff0d92d9e3fc411b Mon Sep 17 00:00:00 2001 From: Nick Sanford Date: Wed, 9 Oct 2024 16:57:31 -0400 Subject: [PATCH] wip --- data/capture_buffer_test.go | 6 ++--- data/capture_file.go | 26 +++++++++---------- .../datamanager/builtin/builtin_sync_test.go | 2 +- .../datamanager/builtin/capture/capture.go | 2 +- services/datamanager/builtin/sync/sync.go | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/data/capture_buffer_test.go b/data/capture_buffer_test.go index 0cfdddac1a4..b0c48cf66ef 100644 --- a/data/capture_buffer_test.go +++ b/data/capture_buffer_test.go @@ -620,7 +620,7 @@ func TestCaptureBufferReader(t *testing.T) { // Path() is the same as the first paramenter passed to NewCaptureBuffer test.That(t, b.Path(), test.ShouldResemble, tmpDir) - test.That(t, b.MetaData, test.ShouldResemble, readImageCaptureMetadata) + test.That(t, b.metaData, test.ShouldResemble, readImageCaptureMetadata) now := time.Now() timeRequested := timestamppb.New(now.UTC()) @@ -689,7 +689,7 @@ func NickTest(t *testing.T) { // Path() is the same as the first paramenter passed to NewCaptureBuffer test.That(t, b.Path(), test.ShouldResemble, tmpDir) - test.That(t, b.MetaData, test.ShouldResemble, readImageCaptureMetadata) + test.That(t, b.metaData, test.ShouldResemble, readImageCaptureMetadata) now := time.Now() timeRequested := timestamppb.New(now.UTC()) @@ -725,7 +725,7 @@ func NickTest(t *testing.T) { test.That(t, err, test.ShouldBeError, io.EOF) } -// nolint +//nolint func getCaptureFiles(dir string) (dcFiles, progFiles []string) { _ = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { if err != nil { diff --git a/data/capture_file.go b/data/capture_file.go index 97a9c915343..914a2f97eb5 100644 --- a/data/capture_file.go +++ b/data/capture_file.go @@ -194,19 +194,19 @@ func getDataType(methodName string) v1.DataType { // SensorDataFromCaptureFilePath returns all readings in the file at filePath. // NOTE: (Nick S) At time of writing this is only used in tests. -//func SensorDataFromCaptureFilePath(filePath string) ([]*v1.SensorData, error) { -// //nolint:gosec -// f, err := os.Open(filePath) -// if err != nil { -// return nil, err -// } -// dcFile, err := NewCaptureFile(f) -// if err != nil { -// return nil, err -// } - -// return SensorDataFromCaptureFile(dcFile) -//} +func SensorDataFromCaptureFilePath(filePath string) ([]*v1.SensorData, error) { + //nolint:gosec + f, err := os.Open(filePath) + if err != nil { + return nil, err + } + dcFile, err := NewCaptureFile(f) + if err != nil { + return nil, err + } + + return SensorDataFromCaptureFile(dcFile) +} // SensorDataFromCaptureFile returns all readings in f. func SensorDataFromCaptureFile(f *CaptureFile) ([]*v1.SensorData, error) { diff --git a/services/datamanager/builtin/builtin_sync_test.go b/services/datamanager/builtin/builtin_sync_test.go index 844b8772095..4b33cf466f3 100644 --- a/services/datamanager/builtin/builtin_sync_test.go +++ b/services/datamanager/builtin/builtin_sync_test.go @@ -1055,7 +1055,7 @@ func getCapturedData(filePaths []string) (int, []*v1.SensorData, error) { if err != nil { return 0, nil, err } - dcFile, err := data.ReadCaptureFile(osFile) + dcFile, err := data.NewCaptureFile(osFile) if err != nil { return 0, nil, err } diff --git a/services/datamanager/builtin/capture/capture.go b/services/datamanager/builtin/capture/capture.go index df81cdc3a75..c2c1abf613b 100644 --- a/services/datamanager/builtin/capture/capture.go +++ b/services/datamanager/builtin/capture/capture.go @@ -269,7 +269,7 @@ func collectorConfigDescription( } func targetDir(captureDir string, collectorConfig datamanager.DataCaptureConfig) string { - return data.CaptureFilePathWithReplacedReservedChars( + return data.FilePathWithReplacedReservedChars( filepath.Join(captureDir, collectorConfig.Name.API.String(), collectorConfig.Name.ShortName(), collectorConfig.Method)) } diff --git a/services/datamanager/builtin/sync/sync.go b/services/datamanager/builtin/sync/sync.go index d99d7097fd2..80568551462 100644 --- a/services/datamanager/builtin/sync/sync.go +++ b/services/datamanager/builtin/sync/sync.go @@ -367,7 +367,7 @@ func (s *Sync) syncFile(config Config, filePath string) { } func (s *Sync) syncDataCaptureFile(f *os.File, captureDir string, logger logging.Logger) { - captureFile, err := data.ReadCaptureFile(f) + captureFile, err := data.NewCaptureFile(f) // if you can't read the capture file's metadata field, close & move it to the failed directory if err != nil { cause := errors.Wrap(err, "ReadCaptureFile failed")