run gofumpt

This commit is contained in:
Matthew Penner
2021-11-15 10:37:56 -07:00
parent 43d66d14b2
commit 04b9ef69a1
17 changed files with 34 additions and 36 deletions

View File

@@ -12,8 +12,7 @@ var (
ErrServerIsRestoring = errors.New("server is currently being restored")
)
type crashTooFrequent struct {
}
type crashTooFrequent struct{}
func (e *crashTooFrequent) Error() string {
return "server has crashed too soon after the last detected crash"
@@ -25,8 +24,7 @@ func IsTooFrequentCrashError(err error) bool {
return ok
}
type serverDoesNotExist struct {
}
type serverDoesNotExist struct{}
func (e *serverDoesNotExist) Error() string {
return "server does not exist on remote system"

View File

@@ -45,7 +45,7 @@ type Archive struct {
// Create creates an archive at dst with all of the files defined in the
// included files struct.
func (a *Archive) Create(dst string) error {
f, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
f, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
return err
}

View File

@@ -85,7 +85,7 @@ func (fs *Filesystem) Touch(p string, flag int) (*os.File, error) {
if err != nil {
return nil, err
}
f, err := os.OpenFile(cleaned, flag, 0644)
f, err := os.OpenFile(cleaned, flag, 0o644)
if err == nil {
return f, nil
}
@@ -97,7 +97,7 @@ func (fs *Filesystem) Touch(p string, flag int) (*os.File, error) {
if _, err := os.Stat(filepath.Dir(cleaned)); errors.Is(err, os.ErrNotExist) {
// Create the path leading up to the file we're trying to create, setting the final perms
// on it as we go.
if err := os.MkdirAll(filepath.Dir(cleaned), 0755); err != nil {
if err := os.MkdirAll(filepath.Dir(cleaned), 0o755); err != nil {
return nil, errors.Wrap(err, "server/filesystem: touch: failed to create directory tree")
}
if err := fs.Chown(filepath.Dir(cleaned)); err != nil {
@@ -107,7 +107,7 @@ func (fs *Filesystem) Touch(p string, flag int) (*os.File, error) {
o := &fileOpener{}
// Try to open the file now that we have created the pathing necessary for it, and then
// Chown that file so that the permissions don't mess with things.
f, err = o.open(cleaned, flag, 0644)
f, err = o.open(cleaned, flag, 0o644)
if err != nil {
return nil, errors.Wrap(err, "server/filesystem: touch: failed to open file with wait")
}
@@ -181,7 +181,7 @@ func (fs *Filesystem) CreateDirectory(name string, p string) error {
if err != nil {
return err
}
return os.MkdirAll(cleaned, 0755)
return os.MkdirAll(cleaned, 0o755)
}
// Moves (or renames) a file or directory.
@@ -210,7 +210,7 @@ func (fs *Filesystem) Rename(from string, to string) error {
// Ensure that the directory we're moving into exists correctly on the system. Only do this if
// we're not at the root directory level.
if d != fs.Path() {
if mkerr := os.MkdirAll(d, 0755); mkerr != nil {
if mkerr := os.MkdirAll(d, 0o755); mkerr != nil {
return errors.WithMessage(mkerr, "failed to create directory structure for file rename")
}
}
@@ -377,7 +377,7 @@ func (fs *Filesystem) TruncateRootDirectory() error {
if err := os.RemoveAll(fs.Path()); err != nil {
return err
}
if err := os.Mkdir(fs.Path(), 0755); err != nil {
if err := os.Mkdir(fs.Path(), 0o755); err != nil {
return err
}
atomic.StoreInt64(&fs.diskUsed, 0)
@@ -485,7 +485,7 @@ func (fs *Filesystem) ListDirectory(p string) ([]Stat, error) {
defer wg.Done()
var m *mimetype.MIME
var d = "inode/directory"
d := "inode/directory"
if !f.IsDir() {
cleanedp := filepath.Join(cleaned, f.Name())
if f.Mode()&os.ModeSymlink != 0 {

View File

@@ -115,8 +115,8 @@ func (fs *Filesystem) ParallelSafePath(paths []string) ([]string, error) {
var cleaned []string
// Simple locker function to avoid racy appends to the array of cleaned paths.
var m = new(sync.Mutex)
var push = func(c string) {
m := new(sync.Mutex)
push := func(c string) {
m.Lock()
cleaned = append(cleaned, c)
m.Unlock()

View File

@@ -107,7 +107,7 @@ func TestFilesystem_Blocks_Symlinks(t *testing.T) {
panic(err)
}
if err := os.Mkdir(filepath.Join(rfs.root, "/malicious_dir"), 0777); err != nil {
if err := os.Mkdir(filepath.Join(rfs.root, "/malicious_dir"), 0o777); err != nil {
panic(err)
}

View File

@@ -215,11 +215,11 @@ func (ip *InstallationProcess) tempDir() string {
func (ip *InstallationProcess) writeScriptToDisk() error {
// Make sure the temp directory root exists before trying to make a directory within it. The
// ioutil.TempDir call expects this base to exist, it won't create it for you.
if err := os.MkdirAll(ip.tempDir(), 0700); err != nil {
if err := os.MkdirAll(ip.tempDir(), 0o700); err != nil {
return errors.WithMessage(err, "could not create temporary directory for install process")
}
f, err := os.OpenFile(filepath.Join(ip.tempDir(), "install.sh"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
f, err := os.OpenFile(filepath.Join(ip.tempDir(), "install.sh"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644)
if err != nil {
return errors.WithMessage(err, "failed to write server installation script to disk before mount")
}
@@ -350,7 +350,7 @@ func (ip *InstallationProcess) AfterExecute(containerId string) error {
return err
}
f, err := os.OpenFile(ip.GetLogPath(), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
f, err := os.OpenFile(ip.GetLogPath(), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
return err
}
@@ -516,7 +516,6 @@ func (ip *InstallationProcess) StreamOutput(ctx context.Context, id string) erro
ShowStderr: true,
Follow: true,
})
if err != nil {
return err
}

View File

@@ -59,7 +59,6 @@ func (s *Server) StartEventListeners() {
err := t.Increment(func() {
s.PublishConsoleOutputFromDaemon("Your server is outputting too much data and is being throttled.")
})
// An error is only returned if the server has breached the thresholds set.
if err != nil {
// If the process is already stopping, just let it continue with that action rather than attempting