Skip to content

Commit

Permalink
fix locking in test
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Oct 13, 2024
1 parent f501b67 commit 80f7bfa
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
19 changes: 9 additions & 10 deletions internal/logstore/logstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,23 +409,22 @@ func (w *writer) Close() error {
defer w.ls.mu.Unlock(w.id)
defer w.ls.notify(w.id)

if e := w.ls.finalizeLogFile(w.id, w.fname); e != nil {
err = multierror.Append(err, fmt.Errorf("finalize %v: %w", w.fname, e))
} else {
w.ls.refcount[w.id]--
}

// manually close all subscribers and delete the subscriber entry from the map; there are no more writes coming.
w.ls.trackingMu.Lock()
if w.ls.refcount[w.id] == 0 {
delete(w.ls.refcount, w.id)
}
subs := w.ls.subscribers[w.id]
for _, ch := range subs {
close(ch)
}
delete(w.ls.subscribers, w.id)

// try to finalize the log file
if e := w.ls.finalizeLogFile(w.id, w.fname); e != nil {
err = multierror.Append(err, fmt.Errorf("finalize %v: %w", w.fname, e))
} else {
w.ls.refcount[w.id]--
if w.ls.refcount[w.id] == 0 {
delete(w.ls.refcount, w.id)
}
}
w.ls.trackingMu.Unlock()
w.ls.maybeReleaseTempFile(w.id, w.fname)
})
Expand Down
1 change: 1 addition & 0 deletions internal/orchestrator/tasks/taskcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (t *CheckTask) Run(ctx context.Context, st ScheduledTask, runner TaskRunner
if err != nil {
return fmt.Errorf("create logref writer: %w", err)
}
defer writer.Close()
opCheck.OperationCheck.OutputLogref = liveID

if err := runner.UpdateOperation(op); err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/orchestrator/tasks/taskprune.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (t *PruneTask) Run(ctx context.Context, st ScheduledTask, runner TaskRunner
if err != nil {
return fmt.Errorf("create logref writer: %w", err)
}
defer writer.Close()
opPrune.OperationPrune.OutputLogref = liveID

if err := runner.UpdateOperation(op); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/orchestrator/tasks/taskruncommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func runCommandHelper(ctx context.Context, st ScheduledTask, taskRunner TaskRunn
if err != nil {
return fmt.Errorf("get logref writer: %w", err)
}
defer writer.Close()

st.Op.GetOperationRunCommand().OutputLogref = id
if err := taskRunner.UpdateOperation(st.Op); err != nil {
return fmt.Errorf("update operation: %w", err)
Expand Down
6 changes: 5 additions & 1 deletion internal/resticinstaller/resticinstaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func downloadFile(url string, downloadPath string) (string, error) {
}

func installResticIfNotExists(resticInstallPath string) error {
lock := flock.New(filepath.Join(env.DataDir(), "install.lock"))
lock := flock.New(filepath.Join(filepath.Dir(resticInstallPath), "install.lock"))
if err := lock.Lock(); err != nil {
return fmt.Errorf("lock %v: %w", lock.Path(), err)
}
Expand Down Expand Up @@ -254,6 +254,10 @@ func FindOrInstallResticBinary() (string, error) {
resticInstallPath, _ = filepath.Abs(path.Join(path.Dir(os.Args[0]), resticBinName))
}

if err := os.MkdirAll(path.Dir(resticInstallPath), 0700); err != nil {
return "", fmt.Errorf("create restic install directory %v: %w", path.Dir(resticInstallPath), err)
}

// Install restic if not found.
if _, err := os.Stat(resticInstallPath); err != nil {
if !errors.Is(err, os.ErrNotExist) {
Expand Down
6 changes: 1 addition & 5 deletions webui/src/components/OperationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ export const OperationList = ({
/>
);
}}
pagination={
operationsForDisplay.length > 25
? { position: "both", align: "center", defaultPageSize: 25 }
: undefined
}
pagination={{ position: "both", align: "center", defaultPageSize: 25 }}
/>
);
};

0 comments on commit 80f7bfa

Please sign in to comment.