From b7e1a4310bb3507bb4aac68e7831c28fdfb48140 Mon Sep 17 00:00:00 2001 From: ZDDC Date: Thu, 7 May 2026 08:54:53 -0500 Subject: [PATCH] refactor(archive): use shared zddc.ParseTransmittalFolder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The transmittal-folder grammar was duplicated as a private regex inside the archive package. Replace the local regex with calls to the shared parser in zddc/internal/zddc/folder.go so the grammar lives in one place and the upcoming staging→working mirror logic can reuse it. Co-Authored-By: Claude Opus 4.7 (1M context) --- zddc/internal/archive/index.go | 13 +++++-------- zddc/internal/archive/watcher.go | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/zddc/internal/archive/index.go b/zddc/internal/archive/index.go index dafb238..e3ba666 100644 --- a/zddc/internal/archive/index.go +++ b/zddc/internal/archive/index.go @@ -9,6 +9,8 @@ import ( "strings" "sync" "time" + + "codeberg.org/VARASYS/ZDDC/zddc/internal/zddc" ) // RevisionEntry holds the resolved file paths for one base revision. @@ -49,9 +51,6 @@ func NewIndex() *Index { } } -// transmittalFolderRE matches: YYYY-MM-DD_anything (anything) - anything -var transmittalFolderRE = regexp.MustCompile(`^(\d{4}-\d{2}-\d{2})_[^_\s]+\s*\([^)]+\)\s*-\s*.+$`) - // zddc filename: trackingNumber_revision (status) - title.ext // trackingNumber: no spaces or underscores // revision: ~?[A-Z0-9]+(+[CBNQ][0-9]+)? @@ -101,9 +100,8 @@ func walkAndIndex(idx *Index, fsRoot, dirAbs, serverDir string) error { } childAbs := filepath.Join(dirAbs, name) - if m := transmittalFolderRE.FindStringSubmatch(name); m != nil { + if date, _, _, _, ok := zddc.ParseTransmittalFolder(name); ok { // This is a transmittal folder — index its files - date := m[1] if err := indexTransmittalFolder(idx, fsRoot, childAbs, childServerDir, date); err != nil { // Non-fatal: log and continue continue @@ -340,11 +338,10 @@ func (idx *Index) Rebuild(fsRoot string) (time.Duration, int, int, error) { func (idx *Index) UpdateFromDir(fsRoot, transmittalDirPath string) error { // Determine the date from the folder name folderName := filepath.Base(transmittalDirPath) - m := transmittalFolderRE.FindStringSubmatch(folderName) - if m == nil { + date, _, _, _, ok := zddc.ParseTransmittalFolder(folderName) + if !ok { return nil // not a transmittal folder } - date := m[1] // Compute server-relative path for this folder rel, err := filepath.Rel(fsRoot, transmittalDirPath) diff --git a/zddc/internal/archive/watcher.go b/zddc/internal/archive/watcher.go index b455275..49d2172 100644 --- a/zddc/internal/archive/watcher.go +++ b/zddc/internal/archive/watcher.go @@ -109,7 +109,7 @@ func (w *Watcher) handleEvent(event fsnotify.Event) { // For transmittal folder events, schedule a debounced index update dirPath := filepath.Dir(path) dirName := filepath.Base(dirPath) - if transmittalFolderRE.MatchString(dirName) { + if _, _, _, _, ok := zddc.ParseTransmittalFolder(dirName); ok { w.scheduleIndexUpdate(dirPath) } }