refactor(archive): use shared zddc.ParseTransmittalFolder
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) <noreply@anthropic.com>
This commit is contained in:
parent
9f97bfab3e
commit
b7e1a4310b
2 changed files with 6 additions and 9 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue