Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type NodeDevice struct {
type ArchiveDecoder struct {
d FormatDecoder
dir string
last interface{}
last any
}

// NewArchiveDecoder initializes a decoder for a catar archive.
Expand All @@ -73,15 +73,15 @@ func NewArchiveDecoder(r io.Reader) ArchiveDecoder {
// Next returns a node from an archive, or nil if the end is reached. If NodeFile
// is returned, the caller should read the file body before calling Next() again
// as that invalidates the reader.
func (a *ArchiveDecoder) Next() (interface{}, error) {
func (a *ArchiveDecoder) Next() (any, error) {
var (
entry *FormatEntry
payload *FormatPayload
symlink *FormatSymlink
device *FormatDevice
xattrs map[string]string
name string
c interface{}
c any
err error
)

Expand Down
4 changes: 2 additions & 2 deletions archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestArchiveDecoderTypes(t *testing.T) {
d := NewArchiveDecoder(f)

// Define an array of what is expected in the test file
expected := []interface{}{
expected := []any{
NodeDirectory{},
NodeDevice{},
NodeFile{},
Expand Down Expand Up @@ -48,7 +48,7 @@ func TestArchiveDecoderNesting(t *testing.T) {

// Define an array of what is expected in the test file
expected := []struct {
Type interface{}
Type any
Name string
UID int
GID int
Expand Down
4 changes: 2 additions & 2 deletions assemble_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestExtract(t *testing.T) {
if err != nil {
t.Fatal(err)
}
for i := 0; i < 4; i++ { // Replicate it a few times to make sure we get dupes
for range 4 { // Replicate it a few times to make sure we get dupes
b = append(b, b...)
}
b = append(b, make([]byte, 2*ChunkSizeMaxDefault)...) // want to have at least one null-chunk in the input
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestSelfSeedInPlace(t *testing.T) {
numChunks := 10
chunks := make([]rawChunk, numChunks)

for i := 0; i < numChunks; i++ {
for i := range numChunks {
b := make([]byte, size)
rand.Read(b)
chunk := NewChunk(b)
Expand Down
1 change: 1 addition & 0 deletions blocksize.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package desync
Expand Down
2 changes: 1 addition & 1 deletion chop.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func ChopFile(ctx context.Context, name string, chunks []IndexChunk, ws WriteSto
s := NewChunkStorage(ws)

// Start the workers, each having its own filehandle to read concurrently
for i := 0; i < n; i++ {
for range n {
f, err := os.Open(name)
if err != nil {
return fmt.Errorf("unable to open file %s, %s", name, err)
Expand Down
17 changes: 7 additions & 10 deletions chunker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ func discriminatorFromAvg(avg uint64) uint32 {
// modulo 2^32 using Newton's method. This is used for Lemire's fast
// divisibility test which replaces expensive hardware division.
func modInverse32(d uint32) uint32 {
x := d // d is odd, so d*d ≡ 1 (mod 4) is a valid start
x *= 2 - d*x // 3 bits
x *= 2 - d*x // 6 bits
x *= 2 - d*x // 12 bits
x *= 2 - d*x // 24 bits
x *= 2 - d*x // 48 bits → full 32-bit precision
x := d // d is odd, so d*d ≡ 1 (mod 4) is a valid start
x *= 2 - d*x // 3 bits
x *= 2 - d*x // 6 bits
x *= 2 - d*x // 12 bits
x *= 2 - d*x // 24 bits
x *= 2 - d*x // 48 bits → full 32-bit precision
return x
}

Expand Down Expand Up @@ -218,10 +218,7 @@ func (c *Chunker) Next() (uint64, []byte, error) {

// m is the upper boundary for the current chunk. It's either c.max if we have
// enough bytes in the buffer, or len(c.buf)
m := int(c.max)
if len(c.buf) < int(c.max) {
m = len(c.buf)
}
m := min(len(c.buf), int(c.max))

// Initialize the rolling hash window with the ChunkerWindowSize bytes
// immediately prior to min size
Expand Down
2 changes: 1 addition & 1 deletion cmd/desync/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// Builds the shared config file path based on the OS's platform.
//
// - Linux/Unix: $HOME/.aws/credentials
// - Windows %USERPROFILE%\.aws\credentials
// - Windows %USERPROFILE%\.aws\credentials
func SharedCredentialsFilename() (string, error) {
homeDir, err := os.UserHomeDir()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/desync/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestInfoCommand(t *testing.T) {
}`)},
} {
t.Run(test.name, func(t *testing.T) {
exp := make(map[string]interface{})
exp := make(map[string]any)
err := json.Unmarshal(test.expectedOutput, &exp)
require.NoError(t, err)

Expand All @@ -118,7 +118,7 @@ func TestInfoCommand(t *testing.T) {
require.NoError(t, err)

// Decode the output and compare to what's expected
got := make(map[string]interface{})
got := make(map[string]any)
err = json.Unmarshal(b.Bytes(), &got)
require.NoError(t, err)
require.Equal(t, exp, got)
Expand Down
2 changes: 1 addition & 1 deletion cmd/desync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func main() {
}
}

func printJSON(w io.Writer, v interface{}) error {
func printJSON(w io.Writer, v any) error {
b, err := json.MarshalIndent(v, "", " ")
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cmd/desync/mount-index.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package main
Expand Down
4 changes: 2 additions & 2 deletions cmd/desync/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func storeGroup(location string, cmdOpt cmdStoreOptions) (desync.Store, error) {
return storeFromLocation(location, cmdOpt)
}
var stores []desync.Store
members := strings.Split(location, "|")
for _, m := range members {
members := strings.SplitSeq(location, "|")
for m := range members {
s, err := storeFromLocation(m, cmdOpt)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions cmd/desync/tar_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package main
Expand Down
1 change: 0 additions & 1 deletion cmd/desync/untar_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows

package main

Expand Down
1 change: 1 addition & 0 deletions compress.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !datadog
// +build !datadog

package desync
Expand Down
1 change: 1 addition & 0 deletions compress_datadog.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build datadog
// +build datadog

package desync
Expand Down
2 changes: 1 addition & 1 deletion copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Copy(ctx context.Context, ids []ChunkID, src Store, dst WriteStore, n int,
defer pb.Finish()

// Start the workers
for i := 0; i < n; i++ {
for range n {
g.Go(func() error {
for id := range in {
pb.Increment()
Expand Down
2 changes: 1 addition & 1 deletion coverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s Converters) equal(c Converters) bool {
if len(s) != len(c) {
return false
}
for i := 0; i < len(s); i++ {
for i := range s {
if !s[i].equal(c[i]) {
return false
}
Expand Down
6 changes: 3 additions & 3 deletions dedupqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (q *queue) delete(id ChunkID) {
// queueRequests is used to dedup requests for GetChunk() or HasChunk() with the data
// being either the chunk itself or a bool in case of HasChunk().
type request struct {
data interface{}
data any
err error
done chan struct{}
}
Expand All @@ -121,13 +121,13 @@ func newRequest() *request {
}

// Wait for the request to complete. Returns the data as well as the error from the request.
func (r *request) wait() (interface{}, error) {
func (r *request) wait() (any, error) {
<-r.done
return r.data, r.err
}

// Set the result data and marks this request as complete.
func (r *request) markDone(data interface{}, err error) {
func (r *request) markDone(data any, err error) {
r.data = data
r.err = err
close(r.done)
Expand Down
2 changes: 1 addition & 1 deletion dedupqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestDedupQueueParallel(t *testing.T) {
)

// Start several goroutines all asking for the same chunk from the store
for i := 0; i < 10; i++ {
for range 10 {
wg.Add(1)
go func() {
<-start
Expand Down
2 changes: 1 addition & 1 deletion failover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestFailoverMutliple(t *testing.T) {
defer cancel()

// Run several goroutines querying the group in a tight loop
for i := 0; i < 16; i++ {
for range 16 {
eg.Go(func() error {
var id ChunkID
for {
Expand Down
6 changes: 3 additions & 3 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func NewFormatDecoder(r io.Reader) FormatDecoder {
// Next returns the next format element from the stream. If an element
// contains a reader, that reader should be used before any subsequent calls as
// it'll be invalidated then. Returns nil when the end is reached.
func (d *FormatDecoder) Next() (interface{}, error) {
func (d *FormatDecoder) Next() (any, error) {
// If we previously returned a reader, make sure we advance all the way in
// case the caller didn't read it all.
if d.advance != nil {
Expand Down Expand Up @@ -347,7 +347,7 @@ func (d *FormatDecoder) Next() (interface{}, error) {
n := (hdr.Size - 16) / 24
items := make([]FormatGoodbyeItem, n)
e := FormatGoodbye{FormatHeader: hdr, Items: items}
for i := uint64(0); i < n; i++ {
for i := range n {
items[i].Offset, err = d.r.ReadUint64()
if err != nil {
return nil, err
Expand Down Expand Up @@ -448,7 +448,7 @@ func NewFormatEncoder(w io.Writer) FormatEncoder {
return FormatEncoder{w: writer{w}}
}

func (e *FormatEncoder) Encode(v interface{}) (int64, error) {
func (e *FormatEncoder) Encode(v any) (int64, error) {
switch t := v.(type) {
case FormatEntry:
return e.w.WriteUint64(
Expand Down
2 changes: 1 addition & 1 deletion format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestFormatDecoder(t *testing.T) {
d := NewFormatDecoder(f)

// Define an array of what is expected in the test file
expected := []interface{}{
expected := []any{
FormatEntry{},
FormatUser{},
FormatGroup{},
Expand Down
2 changes: 1 addition & 1 deletion index.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func ChunkStream(ctx context.Context, c Chunker, ws WriteStore, n int) (Index, e

// Start the workers responsible for checksum calculation, compression and
// storage (if required). Each job comes with a chunk number for sorting later
for i := 0; i < n; i++ {
for range n {
g.Go(func() error {
for c := range in {
// Create a chunk object, needed to calculate the checksum
Expand Down
1 change: 0 additions & 1 deletion ioctl_linux.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux
// +build linux

package desync

Expand Down
1 change: 1 addition & 0 deletions ioctl_nonlinux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !linux
// +build !linux

package desync
Expand Down
2 changes: 1 addition & 1 deletion local.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s LocalStore) Verify(ctx context.Context, n int, repair bool, w io.Writer)
ids := make(chan ChunkID)

// Start the workers
for i := 0; i < n; i++ {
for range n {
wg.Add(1)
go func() {
for id := range ids {
Expand Down
1 change: 1 addition & 0 deletions localfs_other.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package desync
Expand Down
2 changes: 1 addition & 1 deletion make.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (c *pChunker) start(ctx context.Context) {
return
}
nc := chunk
for i := 0; i < numNullChunks; i++ {
for range numNullChunks {
nc = IndexChunk{Start: nc.Start + nc.Size, Size: uint64(len(c.nullChunk.Data)), ID: c.nullChunk.ID}
c.results <- nc
zeroes -= uint64(len(c.nullChunk.Data))
Expand Down
1 change: 1 addition & 0 deletions mount-index.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package desync
Expand Down
1 change: 1 addition & 0 deletions mount-sparse.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package desync
Expand Down
2 changes: 1 addition & 1 deletion selfseed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestSelfSeed(t *testing.T) {
numChunks := 10
chunks := make([]rawChunk, numChunks)

for i := 0; i < numChunks; i++ {
for i := range numChunks {
b := make([]byte, size)
rand.Read(b)
chunk := NewChunk(b)
Expand Down
4 changes: 2 additions & 2 deletions sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (r *SeedSequencer) Rewind() {
r.current = 0
}

//isFileSeed returns true if this segment is pointing to a fileSeed
// isFileSeed returns true if this segment is pointing to a fileSeed
func (s SeedSegmentCandidate) isFileSeed() bool {
// We expect an empty filename when using nullSeeds
return s.source != nil && s.source.FileName() != ""
Expand Down Expand Up @@ -145,7 +145,7 @@ func (p Plan) Validate(ctx context.Context, n int, pb ProgressBar) (err error) {
}
g, ctx := errgroup.WithContext(ctx)
// Concurrently validate all the chunks in this plan
for i := 0; i < n; i++ {
for range n {
g.Go(func() error {
for job := range in {
if err := job.candidate.source.Validate(job.file); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion sparse-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (l *sparseFileLoader) preloadChunksFromState(r io.Reader, n int) error {

// Start the workers for parallel pre-loading
ch := make(chan int)
for i := 0; i < n; i++ {
for range n {
go func() {
for chunkIdx := range ch {
_ = l.loadChunk(chunkIdx)
Expand Down
2 changes: 1 addition & 1 deletion sparse-file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestSparseFileRead(t *testing.T) {
defer h.Close()

// Read a few random ranges and compare to the expected blob content
for i := 0; i < 1000; i++ {
for range 1000 {
length := rand.Intn(int(index.Index.ChunkSizeMax))
offset := rand.Intn(int(index.Length()) - length - 1)

Expand Down
5 changes: 2 additions & 3 deletions tar_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows

package desync

Expand Down Expand Up @@ -34,7 +33,7 @@ func TestTar(t *testing.T) {
"dir1/sub11/f12",
}
for i, name := range files {
os.WriteFile(filepath.Join(base, name), []byte(fmt.Sprintf("filecontent%d", i)), 0644)
os.WriteFile(filepath.Join(base, name), fmt.Appendf(nil, "filecontent%d", i), 0644)
}

if err := os.Symlink("dir1", filepath.Join(base, "symlink")); err != nil {
Expand All @@ -52,7 +51,7 @@ func TestTar(t *testing.T) {
d := NewFormatDecoder(b)

// Define an array of what is expected in the test file
expected := []interface{}{
expected := []any{
FormatEntry{},
FormatFilename{}, // "dir1"
FormatEntry{},
Expand Down
Loading