Merge pull request #2305 from kolyshkin/for-range
Use for range over integers
This commit is contained in:
commit
6f4bc1fa7c
|
|
@ -458,7 +458,7 @@ func (r *containerStore) load(lockedForWriting bool) (bool, error) {
|
|||
|
||||
ids := make(map[string]*Container)
|
||||
|
||||
for locationIndex := 0; locationIndex < numContainerLocationIndex; locationIndex++ {
|
||||
for locationIndex := range numContainerLocationIndex {
|
||||
location := containerLocationFromIndex(locationIndex)
|
||||
rpath := r.jsonPath[locationIndex]
|
||||
|
||||
|
|
@ -531,7 +531,7 @@ func (r *containerStore) save(saveLocations containerLocations) error {
|
|||
return err
|
||||
}
|
||||
r.lastWrite = lw
|
||||
for locationIndex := 0; locationIndex < numContainerLocationIndex; locationIndex++ {
|
||||
for locationIndex := range numContainerLocationIndex {
|
||||
location := containerLocationFromIndex(locationIndex)
|
||||
if location&saveLocations == 0 {
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ func TestCopyDir(t *testing.T) {
|
|||
}
|
||||
|
||||
func randomMode(baseMode int) os.FileMode {
|
||||
for i := 0; i < 7; i++ {
|
||||
for i := range 7 {
|
||||
baseMode = baseMode | (1&rand.Intn(2))<<uint(i)
|
||||
}
|
||||
return os.FileMode(baseMode)
|
||||
|
|
@ -94,7 +94,7 @@ func populateSrcDir(t *testing.T, srcDir string, remainingDepth int) {
|
|||
aTime := time.Unix(rand.Int63(), 0)
|
||||
mTime := time.Unix(rand.Int63(), 0)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := range 10 {
|
||||
dirName := filepath.Join(srcDir, fmt.Sprintf("srcdir-%d", i))
|
||||
// Owner all bits set
|
||||
assert.NilError(t, os.Mkdir(dirName, randomMode(0o700)))
|
||||
|
|
@ -102,7 +102,7 @@ func populateSrcDir(t *testing.T, srcDir string, remainingDepth int) {
|
|||
assert.NilError(t, system.Chtimes(dirName, aTime, mTime))
|
||||
}
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := range 10 {
|
||||
fileName := filepath.Join(srcDir, fmt.Sprintf("srcfile-%d", i))
|
||||
// Owner read bit set
|
||||
assert.NilError(t, os.WriteFile(fileName, []byte{}, randomMode(0o400)))
|
||||
|
|
|
|||
|
|
@ -468,7 +468,7 @@ func DriverTestEcho(t testing.TB, drivername string, driverOptions ...string) {
|
|||
var root string
|
||||
components := 10
|
||||
|
||||
for depth := 0; depth < components; depth++ {
|
||||
for depth := range components {
|
||||
base := stringid.GenerateRandomID()
|
||||
second := stringid.GenerateRandomID()
|
||||
third := stringid.GenerateRandomID()
|
||||
|
|
@ -486,7 +486,7 @@ func DriverTestEcho(t testing.TB, drivername string, driverOptions ...string) {
|
|||
}
|
||||
paths := []string{}
|
||||
path := "/"
|
||||
for i := 0; i < components-1; i++ {
|
||||
for i := range components - 1 {
|
||||
path = filepath.Join(path, fmt.Sprintf("subdir%d", i+1))
|
||||
paths = append(paths, path)
|
||||
if err = os.Mkdir(filepath.Join(root, path), 0o700); err != nil {
|
||||
|
|
@ -520,7 +520,7 @@ func DriverTestEcho(t testing.TB, drivername string, driverOptions ...string) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
expectedChanges = []archive.Change{}
|
||||
for i := 0; i < depth; i++ {
|
||||
for i := range depth {
|
||||
expectedChanges = append(expectedChanges, archive.Change{Kind: archive.ChangeModify, Path: paths[i]})
|
||||
}
|
||||
expectedChanges = append(expectedChanges, archive.Change{Kind: archive.ChangeDelete, Path: paths[depth]})
|
||||
|
|
@ -541,7 +541,7 @@ func DriverTestEcho(t testing.TB, drivername string, driverOptions ...string) {
|
|||
}
|
||||
|
||||
expectedChanges = []archive.Change{}
|
||||
for i := 0; i < depth; i++ {
|
||||
for i := range depth {
|
||||
expectedChanges = append(expectedChanges, archive.Change{Kind: archive.ChangeModify, Path: paths[i]})
|
||||
}
|
||||
for i := depth; i < components-1; i++ {
|
||||
|
|
|
|||
|
|
@ -656,7 +656,7 @@ func (r *layerStore) layersModified() (lockfile.LastWrite, bool, error) {
|
|||
// If the layers.json file or container-layers.json has been
|
||||
// modified manually, then we have to reload the storage in
|
||||
// any case.
|
||||
for locationIndex := 0; locationIndex < numLayerLocationIndex; locationIndex++ {
|
||||
for locationIndex := range numLayerLocationIndex {
|
||||
rpath := r.jsonPath[locationIndex]
|
||||
if rpath == "" {
|
||||
continue
|
||||
|
|
@ -794,7 +794,7 @@ func (r *layerStore) load(lockedForWriting bool) (bool, error) {
|
|||
layers := []*Layer{}
|
||||
ids := make(map[string]*Layer)
|
||||
|
||||
for locationIndex := 0; locationIndex < numLayerLocationIndex; locationIndex++ {
|
||||
for locationIndex := range numLayerLocationIndex {
|
||||
location := layerLocationFromIndex(locationIndex)
|
||||
rpath := r.jsonPath[locationIndex]
|
||||
if rpath == "" {
|
||||
|
|
@ -1031,7 +1031,7 @@ func (r *layerStore) saveLayers(saveLocations layerLocations) error {
|
|||
}
|
||||
r.lastWrite = lw
|
||||
|
||||
for locationIndex := 0; locationIndex < numLayerLocationIndex; locationIndex++ {
|
||||
for locationIndex := range numLayerLocationIndex {
|
||||
location := layerLocationFromIndex(locationIndex)
|
||||
if location&saveLocations == 0 {
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ func TestLayerLocationFromIndex(t *testing.T) {
|
|||
|
||||
func TestLayerLocationFromIndexAndToIndex(t *testing.T) {
|
||||
var l layerLocations
|
||||
for i := 0; i < int(unsafe.Sizeof(l)*8); i++ {
|
||||
for i := range int(unsafe.Sizeof(l) * 8) {
|
||||
location := layerLocationFromIndex(i)
|
||||
index := indexFromLayerLocation(location)
|
||||
require.Equal(t, i, index)
|
||||
|
|
|
|||
|
|
@ -786,7 +786,7 @@ func TestUntarUstarGnuConflict(t *testing.T) {
|
|||
|
||||
func prepareUntarSourceDirectory(numberOfFiles int, targetPath string, makeLinks bool) (int, error) {
|
||||
fileData := []byte("fooo")
|
||||
for n := 0; n < numberOfFiles; n++ {
|
||||
for n := range numberOfFiles {
|
||||
fileName := fmt.Sprintf("file-%d", n)
|
||||
if err := os.WriteFile(filepath.Join(targetPath, fileName), fileData, 0o700); err != nil {
|
||||
return 0, err
|
||||
|
|
@ -1113,7 +1113,7 @@ func TestTempArchiveCloseMultipleTimes(t *testing.T) {
|
|||
if n != 5 {
|
||||
t.Fatalf("Expected to read 5 bytes. Read %d instead", n)
|
||||
}
|
||||
for i := 0; i < 3; i++ {
|
||||
for i := range 3 {
|
||||
if err = tempArchive.Close(); err != nil {
|
||||
t.Fatalf("i=%d. Unexpected error closing temp archive: %v", i, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ func parseDirent(buf []byte, names []nameIno) (consumed int, newnames []nameIno)
|
|||
continue
|
||||
}
|
||||
builder := make([]byte, 0, dirent.Reclen)
|
||||
for i := 0; i < len(dirent.Name); i++ {
|
||||
for i := range len(dirent.Name) {
|
||||
if dirent.Name[i] == 0 {
|
||||
break
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ func TestHardLinkOrder(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
for _, name := range names {
|
||||
for i := 0; i < 5; i++ {
|
||||
for i := range 5 {
|
||||
if err := os.Link(path.Join(dest, name), path.Join(dest, fmt.Sprintf("%s.link%d", name, i))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -357,7 +357,7 @@ func TestChangesDirsMutated(t *testing.T) {
|
|||
{"/symlinknew", ChangeAdd},
|
||||
}
|
||||
|
||||
for i := 0; i < max(len(changes), len(expectedChanges)); i++ {
|
||||
for i := range max(len(changes), len(expectedChanges)) {
|
||||
if i >= len(expectedChanges) {
|
||||
t.Fatalf("unexpected change %s\n", changes[i].String())
|
||||
}
|
||||
|
|
@ -470,7 +470,7 @@ func TestChangesSize(t *testing.T) {
|
|||
func checkChanges(t *testing.T, expectedChanges, changes []Change) {
|
||||
sort.Sort(changesByPath(expectedChanges))
|
||||
sort.Sort(changesByPath(changes))
|
||||
for i := 0; i < max(len(changes), len(expectedChanges)); i++ {
|
||||
for i := range max(len(changes), len(expectedChanges)) {
|
||||
if i >= len(expectedChanges) {
|
||||
t.Fatalf("unexpected change %s\n", changes[i].String())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ func TestChrootUntarWithHugeExcludesList(t *testing.T) {
|
|||
// 65534 entries of 64-byte strings ~= 4MB of environment space which should overflow
|
||||
// on most systems when passed via environment or command line arguments
|
||||
excludes := make([]string, 65534)
|
||||
for i := 0; i < 65534; i++ {
|
||||
for i := range 65534 {
|
||||
excludes[i] = strings.Repeat(fmt.Sprintf("%d", i), 64)
|
||||
}
|
||||
options.ExcludePatterns = excludes
|
||||
|
|
@ -112,7 +112,7 @@ func TestChrootUntarEmptyArchive(t *testing.T) {
|
|||
|
||||
func prepareSourceDirectory(numberOfFiles int, targetPath string, makeSymLinks bool) (int, error) {
|
||||
fileData := []byte("fooo")
|
||||
for n := 0; n < numberOfFiles; n++ {
|
||||
for n := range numberOfFiles {
|
||||
fileName := fmt.Sprintf("file-%d", n)
|
||||
if err := os.WriteFile(filepath.Join(targetPath, fileName), fileData, 0o700); err != nil {
|
||||
return 0, err
|
||||
|
|
@ -497,7 +497,7 @@ type slowEmptyTarReader struct {
|
|||
func (s *slowEmptyTarReader) Read(p []byte) (int, error) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
count := min(len(p), s.chunkSize)
|
||||
for i := 0; i < count; i++ {
|
||||
for i := range count {
|
||||
p[i] = 0
|
||||
}
|
||||
s.offset += count
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ func (rc *rollingChecksumReader) Read(b []byte) (bool, int, error) {
|
|||
return false, 0, io.EOF
|
||||
}
|
||||
|
||||
for i := 0; i < len(b); i++ {
|
||||
for i := range b {
|
||||
holeLen, n, err := rc.reader.readByte()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ func TestSum(t *testing.T) {
|
|||
|
||||
end := 500
|
||||
rs := roll(0, windowSize)
|
||||
for i := 0; i < end; i++ {
|
||||
for i := range end {
|
||||
sumRoll := rs.Digest()
|
||||
newRoll := roll(i, i+windowSize).Digest()
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ func TestBytesPipeWriteRandomChunks(t *testing.T) {
|
|||
for _, c := range cases {
|
||||
// first pass: write directly to hash
|
||||
hash := sha1.New()
|
||||
for i := 0; i < c.iterations*c.writesPerLoop; i++ {
|
||||
for i := range c.iterations * c.writesPerLoop {
|
||||
if _, err := hash.Write(testMessage[:writeChunks[i%len(writeChunks)]]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -118,8 +118,8 @@ func TestBytesPipeWriteRandomChunks(t *testing.T) {
|
|||
close(done)
|
||||
}()
|
||||
|
||||
for i := 0; i < c.iterations; i++ {
|
||||
for w := 0; w < c.writesPerLoop; w++ {
|
||||
for i := range c.iterations {
|
||||
for w := range c.writesPerLoop {
|
||||
_, err := buf.Write(testMessage[:writeChunks[(i*c.writesPerLoop+w)%len(writeChunks)]])
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -521,7 +521,7 @@ func TestLockfileMixedConcurrent(t *testing.T) {
|
|||
done <- true
|
||||
}
|
||||
|
||||
for i := 0; i < numReaders; i++ {
|
||||
for i := range numReaders {
|
||||
go reader(&counter)
|
||||
// schedule a writer every 2nd iteration
|
||||
if i%2 == 1 {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ func GenerateRandomASCIIString(n int) string {
|
|||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
|
||||
"~!@#$%^&*()-_+={}[]\\|<,>.?/\"';:` "
|
||||
res := make([]byte, n)
|
||||
for i := 0; i < n; i++ {
|
||||
for i := range n {
|
||||
res[i] = chars[rand.IntN(len(chars))]
|
||||
}
|
||||
return string(res)
|
||||
|
|
@ -83,7 +83,7 @@ func quote(word string, buf *bytes.Buffer) {
|
|||
|
||||
buf.WriteString("'")
|
||||
|
||||
for i := 0; i < len(word); i++ {
|
||||
for i := range len(word) {
|
||||
b := word[i]
|
||||
if b == '\'' {
|
||||
// Replace literal ' with a close ', a \', and an open '
|
||||
|
|
|
|||
Loading…
Reference in New Issue