Some sync changes, graceful shutdwn

This commit is contained in:
Simon Martens
2024-11-10 21:49:36 +01:00
parent bdd4eeab26
commit 49f2243f0e
8 changed files with 54910 additions and 82 deletions

View File

@@ -15,6 +15,7 @@ type Agent struct {
SortName string `xml:"sortiername"`
Life string `xml:"lebensdaten"`
GND string `xml:"gnd"`
Org bool `xml:"org,attr"`
Identifier
AnnotationNote
}

View File

@@ -88,25 +88,28 @@ func (g *GitProvider) Pull() (error, bool) {
return err, false
}
if err := wt.Checkout(&git.CheckoutOptions{
Branch: branch,
Force: true,
}); err != nil {
return err, false
}
if err := wt.Pull(&git.PullOptions{
RemoteName: "origin",
ReferenceName: branch,
Progress: os.Stdout,
}); err != nil && err != git.NoErrAlreadyUpToDate {
}); err != nil {
if err == git.NoErrAlreadyUpToDate {
return nil, false
}
return err, false
} else if err == git.NoErrAlreadyUpToDate {
return nil, false
}
defer wt.Clean(&git.CleanOptions{Dir: true})
return g.setValues(repo), true
oldCommit := g.Commit
if err := g.setValues(repo); err != nil {
return err, false
}
if oldCommit == g.Commit {
return nil, false
}
return nil, true
}
func (g *GitProvider) Clone() error {
@@ -233,6 +236,11 @@ func (g *GitProvider) ValidateBranch(repo *git.Repository) error {
return nil
}
func (g *GitProvider) Wait() {
g.mu.Lock()
defer g.mu.Unlock()
}
func (g *GitProvider) ValidateCommit() error {
if g.Commit == "" || g.Date.IsZero() {
return InvalidStateError

View File

@@ -23,6 +23,7 @@ type Piece struct {
WorkRefs []WorkRef `xml:"werk"`
PieceRefs []PieceRef `xml:"beitrag"`
AdditionalRef []AdditionalRef `xml:"beilage"`
Datum []KGPZDate `xml:"datum"`
Incipit []string `xml:"incipit"`
Title []string `xml:"titel"`
Identifier

View File

@@ -16,10 +16,11 @@ type URL struct {
type AdditionalRef struct {
XMLName xml.Name `xml:"beilage"`
Reference
Datum string `xml:"datum,attr"`
Nr string `xml:"nr,attr"`
Von string `xml:"von,attr"`
Bis string `xml:"bis,attr"`
Datum string `xml:"datum,attr"`
Nr string `xml:"nr,attr"`
AdditionalNo string `xml:"beilage,attr"`
Von string `xml:"von,attr"`
Bis string `xml:"bis,attr"`
}
type IssueRef struct {
@@ -49,6 +50,7 @@ type WorkRef struct {
type PieceRef struct {
XMLName xml.Name `xml:"beitrag"`
Page string `xml:"s,attr"`
Reference
}

View File

@@ -20,22 +20,16 @@ type XMLProvider[T KGPZXML[T]] struct {
}
func (p *XMLProvider[T]) Load() error {
var wg sync.WaitGroup
for _, path := range p.paths {
wg.Add(1)
go func(path string) {
defer wg.Done()
var data T
if err := UnmarshalFile(path, &data); err != nil {
fmt.Println(err)
return
}
p.mu.Lock()
p.Items = p.Items.Append(data)
p.mu.Unlock()
}(path)
var data T
if err := UnmarshalFile(path, &data); err != nil {
fmt.Println(err)
return err
}
p.mu.Lock()
p.Items = p.Items.Append(data)
p.mu.Unlock()
}
wg.Wait()
return nil
}