Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tmpnet] Avoid calling Stat in advance of Read/Open #3356

Merged
merged 2 commits into from
Sep 4, 2024
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
8 changes: 3 additions & 5 deletions tests/fixture/tmpnet/node_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@ func (p *NodeProcess) setProcessContext(processContext node.NodeProcessContext)

func (p *NodeProcess) readState() error {
path := p.getProcessContextPath()
if _, err := os.Stat(path); errors.Is(err, fs.ErrNotExist) {
bytes, err := os.ReadFile(path)
if errors.Is(err, fs.ErrNotExist) {
// The absence of the process context file indicates the node is not running
p.setProcessContext(node.NodeProcessContext{})
return nil
}

bytes, err := os.ReadFile(path)
if err != nil {
} else if err != nil {
return fmt.Errorf("failed to read node process context: %w", err)
}
processContext := node.NodeProcessContext{}
Expand Down
9 changes: 3 additions & 6 deletions tests/fixture/tmpnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package tmpnet
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -339,14 +340,10 @@ func WaitForActiveValidators(

// Reads subnets from [network dir]/subnets/[subnet name].json
func readSubnets(subnetDir string) ([]*Subnet, error) {
if _, err := os.Stat(subnetDir); os.IsNotExist(err) {
entries, err := os.ReadDir(subnetDir)
if errors.Is(err, os.ErrNotExist) {
return nil, nil
} else if err != nil {
return nil, err
}

entries, err := os.ReadDir(subnetDir)
if err != nil {
return nil, fmt.Errorf("failed to read subnet dir: %w", err)
}

Expand Down
Loading