mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-19 03:25:16 +00:00
wip
This commit is contained in:
parent
2a77eb54ee
commit
7009cf1111
@ -462,11 +462,10 @@ func (f *folder) scanSubdirs(subDirs []string) error {
|
|||||||
}
|
}
|
||||||
defer f.ioLimiter.Give(1)
|
defer f.ioLimiter.Give(1)
|
||||||
|
|
||||||
t0 := time.Now()
|
metricFolderScans.WithLabelValues(f.ID).Inc()
|
||||||
defer func() {
|
ctx, cancel := context.WithCancel(f.ctx)
|
||||||
metricFolderScans.WithLabelValues(f.ID).Inc()
|
defer cancel()
|
||||||
metricFolderScanSeconds.WithLabelValues(f.ID).Add(time.Since(t0).Seconds())
|
go addTimeUntilCancelled(ctx, metricFolderScanSeconds.WithLabelValues(f.ID))
|
||||||
}()
|
|
||||||
|
|
||||||
for i := range subDirs {
|
for i := range subDirs {
|
||||||
sub := osutil.NativeFilename(subDirs[i])
|
sub := osutil.NativeFilename(subDirs[i])
|
||||||
|
@ -8,6 +8,7 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -163,13 +164,10 @@ func (f *sendReceiveFolder) pull() (bool, error) {
|
|||||||
scanChan := make(chan string)
|
scanChan := make(chan string)
|
||||||
go f.pullScannerRoutine(scanChan)
|
go f.pullScannerRoutine(scanChan)
|
||||||
|
|
||||||
t0 := time.Now()
|
metricFolderPulls.WithLabelValues(f.ID).Inc()
|
||||||
defer func() {
|
ctx, cancel := context.WithCancel(f.ctx)
|
||||||
close(scanChan)
|
defer cancel()
|
||||||
f.setState(FolderIdle)
|
go addTimeUntilCancelled(ctx, metricFolderPullSeconds.WithLabelValues(f.ID))
|
||||||
metricFolderPulls.WithLabelValues(f.ID).Inc()
|
|
||||||
metricFolderPullSeconds.WithLabelValues(f.ID).Add(time.Since(t0).Seconds())
|
|
||||||
}()
|
|
||||||
|
|
||||||
changed := 0
|
changed := 0
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -14,6 +15,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/syncthing/syncthing/lib/events"
|
"github.com/syncthing/syncthing/lib/events"
|
||||||
"github.com/syncthing/syncthing/lib/fs"
|
"github.com/syncthing/syncthing/lib/fs"
|
||||||
"github.com/syncthing/syncthing/lib/ur"
|
"github.com/syncthing/syncthing/lib/ur"
|
||||||
@ -117,11 +119,11 @@ func inWritableDir(fn func(string) error, targetFs fs.Filesystem, path string, i
|
|||||||
|
|
||||||
const permBits = fs.ModePerm | fs.ModeSetuid | fs.ModeSetgid | fs.ModeSticky
|
const permBits = fs.ModePerm | fs.ModeSetuid | fs.ModeSetgid | fs.ModeSticky
|
||||||
var parentErr error
|
var parentErr error
|
||||||
if mode := info.Mode() & permBits; mode&0200 == 0 {
|
if mode := info.Mode() & permBits; mode&0o200 == 0 {
|
||||||
// A non-writeable directory (for this user; we assume that's the
|
// A non-writeable directory (for this user; we assume that's the
|
||||||
// relevant part). Temporarily change the mode so we can delete the
|
// relevant part). Temporarily change the mode so we can delete the
|
||||||
// file or directory inside it.
|
// file or directory inside it.
|
||||||
parentErr = targetFs.Chmod(dir, mode|0700)
|
parentErr = targetFs.Chmod(dir, mode|0o700)
|
||||||
if parentErr != nil {
|
if parentErr != nil {
|
||||||
l.Debugf("Failed to make parent directory writable: %v", parentErr)
|
l.Debugf("Failed to make parent directory writable: %v", parentErr)
|
||||||
} else {
|
} else {
|
||||||
@ -148,3 +150,23 @@ func inWritableDir(fn func(string) error, targetFs fs.Filesystem, path string, i
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// addTimeUntilCancelled adds time to the counter for the duration of the
|
||||||
|
// Context. We do this piecemeal so that polling the counter during a long
|
||||||
|
// operation shows a relevant value, instead of the counter just increasing
|
||||||
|
// by a large amount at the end of the operation.
|
||||||
|
func addTimeUntilCancelled(ctx context.Context, counter prometheus.Counter) {
|
||||||
|
t0 := time.Now()
|
||||||
|
ticker := time.NewTicker(time.Second)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
|
t1 := time.Now()
|
||||||
|
counter.Add(t1.Sub(t0).Seconds())
|
||||||
|
t0 = t1
|
||||||
|
case <-ctx.Done():
|
||||||
|
counter.Add(time.Since(t0).Seconds())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user