mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 06:47:20 +08:00
fix: lint
This commit is contained in:
@@ -3,6 +3,7 @@ package phpmyadmin
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
@@ -32,7 +33,7 @@ func (s *App) Route(r chi.Router) {
|
||||
}
|
||||
|
||||
func (s *App) Info(w http.ResponseWriter, r *http.Request) {
|
||||
files, err := io.ReadDir(fmt.Sprintf("%s/server/phpmyadmin", app.Root))
|
||||
files, err := os.ReadDir(fmt.Sprintf("%s/server/phpmyadmin", app.Root))
|
||||
if err != nil {
|
||||
service.Error(w, http.StatusInternalServerError, "找不到 phpMyAdmin 目录")
|
||||
return
|
||||
|
||||
@@ -3,6 +3,7 @@ package s3fs
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -70,7 +71,7 @@ func (s *App) Create(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// 检查挂载目录是否存在且为空
|
||||
if !io.Exists(req.Path) {
|
||||
if err = io.Mkdir(req.Path, 0755); err != nil {
|
||||
if err = os.MkdirAll(req.Path, 0755); err != nil {
|
||||
service.Error(w, http.StatusUnprocessableEntity, "failed to create mount path: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func (r *backupRepo) List(typ biz.BackupType) ([]*types.BackupFile, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
files, err := io.ReadDir(path)
|
||||
files, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -149,7 +149,7 @@ func (r *backupRepo) CutoffLog(path, target string) error {
|
||||
// prefix 目标文件前缀
|
||||
// save 保存份数
|
||||
func (r *backupRepo) ClearExpired(path, prefix string, save int) error {
|
||||
files, err := io.ReadDir(path)
|
||||
files, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -210,7 +210,7 @@ func (r *backupRepo) GetPath(typ biz.BackupType) (string, error) {
|
||||
|
||||
backupPath = filepath.Join(backupPath, string(typ))
|
||||
if !io.Exists(backupPath) {
|
||||
if err = io.Mkdir(backupPath, 0644); err != nil {
|
||||
if err = os.MkdirAll(backupPath, 0644); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
@@ -338,7 +338,7 @@ func (r *backupRepo) createPanel(to string) error {
|
||||
|
||||
start := time.Now()
|
||||
|
||||
temp, err := io.TempDir("panel-backup")
|
||||
temp, err := os.MkdirTemp("", "panel-backup")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -533,7 +533,7 @@ func (r *backupRepo) preCheckDB(to string, size int64) error {
|
||||
|
||||
// autoUnCompressSQL 自动处理压缩文件
|
||||
func (r *backupRepo) autoUnCompressSQL(backup string) (string, error) {
|
||||
temp, err := io.TempDir("sql-uncompress")
|
||||
temp, err := os.MkdirTemp("", "sql-uncompress")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -543,7 +543,7 @@ func (r *backupRepo) autoUnCompressSQL(backup string) (string, error) {
|
||||
}
|
||||
|
||||
backup = "" // 置空,防止干扰后续判断
|
||||
if files, err := io.ReadDir(temp); err == nil {
|
||||
if files, err := os.ReadDir(temp); err == nil {
|
||||
if len(files) != 1 {
|
||||
return "", fmt.Errorf("压缩文件中包含的文件数量不为1,实际为%d", len(files))
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -266,7 +267,7 @@ func (r *websiteRepo) Create(req *request.WebsiteCreate) (*biz.Website, error) {
|
||||
}
|
||||
|
||||
// 初始化网站目录
|
||||
if err = io.Mkdir(req.Path, 0755); err != nil {
|
||||
if err = os.MkdirAll(req.Path, 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
index, err := embed.WebsiteFS.ReadFile(filepath.Join("website", "index.html"))
|
||||
|
||||
@@ -72,7 +72,7 @@ func (s *BackupService) Upload(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if !io.Exists(filepath.Dir(path)) {
|
||||
if err = io.Mkdir(filepath.Dir(path), 0755); err != nil {
|
||||
if err = os.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||
Error(w, http.StatusInternalServerError, "创建文件夹失败:%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func (s *FileService) Create(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if err = io.Mkdir(req.Path, 0755); err != nil {
|
||||
if err = stdos.MkdirAll(req.Path, 0755); err != nil {
|
||||
Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
}
|
||||
@@ -159,7 +159,7 @@ func (s *FileService) Upload(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if !io.Exists(filepath.Dir(path)) {
|
||||
if err = io.Mkdir(filepath.Dir(path), 0755); err != nil {
|
||||
if err = stdos.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||
Error(w, http.StatusInternalServerError, "create directory error: %v", err)
|
||||
return
|
||||
}
|
||||
@@ -420,7 +420,7 @@ func (s *FileService) List(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
list, err := io.ReadDir(req.Path)
|
||||
list, err := stdos.ReadDir(req.Path)
|
||||
if err != nil {
|
||||
Error(w, http.StatusInternalServerError, "%v", err)
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package io
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -59,7 +60,7 @@ func UnCompress(src string, dst string) error {
|
||||
return errors.New("src and dst must be absolute path")
|
||||
}
|
||||
if !Exists(dst) {
|
||||
if err := Mkdir(dst, 0755); err != nil {
|
||||
if err := os.MkdirAll(dst, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,19 +214,13 @@ func (s *IOTestSuite) TestListCompress() {
|
||||
|
||||
func (s *IOTestSuite) TestRemoveDeletesFileOrDirectory() {
|
||||
path := "testdata/remove_test"
|
||||
s.NoError(Mkdir(path, 0755))
|
||||
s.NoError(os.MkdirAll(path, 0755))
|
||||
s.DirExists(path)
|
||||
|
||||
s.NoError(Remove(path))
|
||||
s.NoDirExists(path)
|
||||
}
|
||||
|
||||
func (s *IOTestSuite) TestMkdirCreatesDirectory() {
|
||||
path := "testdata/mkdir_test"
|
||||
s.NoError(Mkdir(path, 0755))
|
||||
s.DirExists(path)
|
||||
}
|
||||
|
||||
func (s *IOTestSuite) TestChmodChangesPermissions() {
|
||||
if env.IsWindows() {
|
||||
s.T().Skip("Skipping on Windows")
|
||||
@@ -263,13 +257,13 @@ func (s *IOTestSuite) TestExistsReturnsFalseForNonExistingPath() {
|
||||
|
||||
func (s *IOTestSuite) TestEmptyReturnsTrueForEmptyDirectory() {
|
||||
path := "testdata/empty_test"
|
||||
s.NoError(Mkdir(path, 0755))
|
||||
s.NoError(os.MkdirAll(path, 0755))
|
||||
s.True(Empty(path))
|
||||
}
|
||||
|
||||
func (s *IOTestSuite) TestEmptyReturnsFalseForNonEmptyDirectory() {
|
||||
path := "testdata/nonempty_test"
|
||||
s.NoError(Mkdir(path, 0755))
|
||||
s.NoError(os.MkdirAll(path, 0755))
|
||||
s.NoError(Write(filepath.Join(path, "file.txt"), "test", 0644))
|
||||
s.False(Empty(path))
|
||||
}
|
||||
@@ -304,27 +298,9 @@ func (s *IOTestSuite) TestSizeReturnsCorrectSize() {
|
||||
s.Equal(int64(len(data)), size)
|
||||
}
|
||||
|
||||
func (s *IOTestSuite) TestTempDirCreatesTemporaryDirectory() {
|
||||
dir, err := TempDir("tempdir_test")
|
||||
s.NoError(err)
|
||||
s.DirExists(dir)
|
||||
s.NoError(Remove(dir))
|
||||
}
|
||||
|
||||
func (s *IOTestSuite) TestReadDirReturnsDirectoryEntries() {
|
||||
path := "testdata/readdir_test"
|
||||
s.NoError(Mkdir(path, 0755))
|
||||
s.NoError(Write(filepath.Join(path, "file1.txt"), "test", 0644))
|
||||
s.NoError(Write(filepath.Join(path, "file2.txt"), "test", 0644))
|
||||
|
||||
entries, err := ReadDir(path)
|
||||
s.NoError(err)
|
||||
s.Len(entries, 2)
|
||||
}
|
||||
|
||||
func (s *IOTestSuite) TestIsDirReturnsTrueForDirectory() {
|
||||
path := "testdata/isdir_test"
|
||||
s.NoError(Mkdir(path, 0755))
|
||||
s.NoError(os.MkdirAll(path, 0755))
|
||||
s.True(IsDir(path))
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,6 @@ func Remove(path string) error {
|
||||
return os.RemoveAll(path)
|
||||
}
|
||||
|
||||
// Mkdir 创建目录
|
||||
func Mkdir(path string, permission os.FileMode) error {
|
||||
return os.MkdirAll(path, permission)
|
||||
}
|
||||
|
||||
// Chmod 修改文件/目录权限
|
||||
func Chmod(path string, permission os.FileMode) error {
|
||||
_, err := shell.Execf("chmod -R '%o' '%s'", permission, path)
|
||||
@@ -75,16 +70,6 @@ func Size(path string) (int64, error) {
|
||||
return size, err
|
||||
}
|
||||
|
||||
// TempDir 创建临时目录
|
||||
func TempDir(prefix string) (string, error) {
|
||||
return os.MkdirTemp("", prefix)
|
||||
}
|
||||
|
||||
// ReadDir 读取目录
|
||||
func ReadDir(path string) ([]os.DirEntry, error) {
|
||||
return os.ReadDir(path)
|
||||
}
|
||||
|
||||
// IsDir 判断是否为目录
|
||||
func IsDir(path string) bool {
|
||||
info, err := os.Stat(path)
|
||||
|
||||
Reference in New Issue
Block a user