From 85012df038b1bc8d27ea7372a9ee051ab9a86103 Mon Sep 17 00:00:00 2001 From: Tedi Mitiku Date: Wed, 23 Oct 2024 00:33:54 +0900 Subject: [PATCH] simplify get all log filepaths and add cmt --- .../log_file_manager/log_file_manager.go | 17 +++++++++-------- .../persistent_volume_helpers.go | 5 ++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/engine/server/engine/centralized_logs/client_implementations/persistent_volume/log_file_manager/log_file_manager.go b/engine/server/engine/centralized_logs/client_implementations/persistent_volume/log_file_manager/log_file_manager.go index 38c71cdeb9..67293a3d7f 100644 --- a/engine/server/engine/centralized_logs/client_implementations/persistent_volume/log_file_manager/log_file_manager.go +++ b/engine/server/engine/centralized_logs/client_implementations/persistent_volume/log_file_manager/log_file_manager.go @@ -264,17 +264,18 @@ func (manager *LogFileManager) createSymlinkLogFile(targetLogFilePath, symlinkLo return nil } +// if [enclaveUuid] is empty, gets log file paths from all enclaves func (manager *LogFileManager) getAllLogFilePaths(enclaveUuid string) ([]string, error) { var paths []string walkFunc := func(path string, info fs.FileInfo, err error) error { - if enclaveUuid != emptyEnclaveUuid { - if strings.Contains(path, enclaveUuid) && !info.IsDir() { - paths = append(paths, path) - } - } else { - if !info.IsDir() { - paths = append(paths, path) - } + if err != nil { + return err + } + if info.IsDir() { + return nil + } + if enclaveUuid == emptyEnclaveUuid || strings.Contains(path, enclaveUuid) { + paths = append(paths, path) } return nil } diff --git a/engine/server/engine/centralized_logs/client_implementations/persistent_volume/persistent_volume_helpers/persistent_volume_helpers.go b/engine/server/engine/centralized_logs/client_implementations/persistent_volume/persistent_volume_helpers/persistent_volume_helpers.go index ca20762862..c6b9d483fb 100644 --- a/engine/server/engine/centralized_logs/client_implementations/persistent_volume/persistent_volume_helpers/persistent_volume_helpers.go +++ b/engine/server/engine/centralized_logs/client_implementations/persistent_volume/persistent_volume_helpers/persistent_volume_helpers.go @@ -2,7 +2,10 @@ package persistent_volume_helpers import "time" +const ( + hoursInWeek = 7 * 24 +) + func ConvertWeeksToDuration(weeks int) time.Duration { - hoursInWeek := 7 * 24 return time.Duration(weeks*hoursInWeek) * time.Hour }