Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ai3
tools
tabacco
Commits
ad361dfa
Commit
ad361dfa
authored
Jun 18, 2019
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a few locks to prevent data races
parent
f01658f1
Pipeline
#3478
failed with stage
in 37 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
15 deletions
+24
-15
config.go
config.go
+2
-0
manager_test.go
manager_test.go
+8
-0
repository_restic.go
repository_restic.go
+14
-15
No files found.
config.go
View file @
ad361dfa
...
...
@@ -269,12 +269,14 @@ func NewConfigManager(config *Config) (*ConfigManager, error) {
}
go
func
()
{
for
range
m
.
notifyCh
{
m
.
mx
.
Lock
()
for
_
,
lch
:=
range
m
.
listeners
{
select
{
case
lch
<-
struct
{}{}
:
default
:
}
}
m
.
mx
.
Unlock
()
}
}()
return
m
,
nil
...
...
manager_test.go
View file @
ad361dfa
...
...
@@ -4,6 +4,7 @@ import (
"context"
"log"
"path/filepath"
"sync"
"testing"
"time"
...
...
@@ -48,6 +49,7 @@ func (e dummyMetadataEntry) toBackup() *Backup {
}
type
dummyMetadataStore
struct
{
mx
sync
.
Mutex
log
[]
dummyMetadataEntry
}
...
...
@@ -118,6 +120,9 @@ func groupByBackup(dbAtoms []dummyMetadataEntry) []*Backup {
}
func
(
d
*
dummyMetadataStore
)
FindAtoms
(
_
context
.
Context
,
req
*
FindRequest
)
([]
*
Backup
,
error
)
{
d
.
mx
.
Lock
()
defer
d
.
mx
.
Unlock
()
var
tmp
[]
dummyMetadataEntry
for
_
,
l
:=
range
d
.
log
{
if
!
l
.
match
(
req
)
{
...
...
@@ -130,6 +135,9 @@ func (d *dummyMetadataStore) FindAtoms(_ context.Context, req *FindRequest) ([]*
}
func
(
d
*
dummyMetadataStore
)
AddDataset
(
_
context
.
Context
,
backup
*
Backup
,
ds
*
Dataset
)
error
{
d
.
mx
.
Lock
()
defer
d
.
mx
.
Unlock
()
log
.
Printf
(
"AddDataset: %+v"
,
*
ds
)
for
_
,
atom
:=
range
ds
.
Atoms
{
path
:=
filepath
.
Join
(
ds
.
Source
,
ds
.
Name
,
atom
.
Name
)
...
...
repository_restic.go
View file @
ad361dfa
...
...
@@ -7,11 +7,13 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"sync"
"time"
"github.com/hashicorp/go-version"
...
...
@@ -25,7 +27,7 @@ type resticRepository struct {
excludeFiles
[]
string
autoPrune
bool
initialized
bool
initialized
sync
.
Once
}
func
(
r
*
resticRepository
)
resticCmd
()
string
{
...
...
@@ -122,20 +124,17 @@ func (r *resticRepository) Close() error {
}
func
(
r
*
resticRepository
)
Init
(
ctx
context
.
Context
,
rctx
RuntimeContext
)
error
{
if
r
.
initialized
{
return
nil
}
// Restic init will fail the second time we run it, ignore
// errors.
err
:=
rctx
.
Shell
()
.
Run
(
ctx
,
fmt
.
Sprintf
(
"%s init --quiet || true"
,
r
.
resticCmd
(),
))
if
err
==
nil
{
r
.
initialized
=
true
}
return
err
r
.
initialized
.
Do
(
func
()
{
// Restic init will fail if the repository is already
// initialized, ignore errors (but log them).
if
err
:=
rctx
.
Shell
()
.
Run
(
ctx
,
fmt
.
Sprintf
(
"%s init --quiet || true"
,
r
.
resticCmd
(),
));
err
!=
nil
{
log
.
Printf
(
"restic repository init failed (likely harmless): %v"
,
err
)
}
})
return
nil
}
func
(
r
*
resticRepository
)
Prepare
(
ctx
context
.
Context
,
rctx
RuntimeContext
,
backup
*
Backup
)
error
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment