* migrate to idiomatic handling the Reader method of LocalFileBackend (#9959)
* migrate to idiomatic handling the ReadFile method of LocalFileBackend * migrate to idiomatic handling the ListDirectory method of LocalFileBackend * gofmt done * migrate to idiomatic handling the FileExists method of LocalFileBackend
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
d3c55b8a02
Коммит
56937b0e8b
@@ -35,19 +35,19 @@ func (b *LocalFileBackend) TestConnection() *model.AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *LocalFileBackend) Reader(path string) (io.ReadCloser, *model.AppError) {
|
func (b *LocalFileBackend) Reader(path string) (io.ReadCloser, *model.AppError) {
|
||||||
if f, err := os.Open(filepath.Join(b.directory, path)); err != nil {
|
f, err := os.Open(filepath.Join(b.directory, path))
|
||||||
|
if err != nil {
|
||||||
return nil, model.NewAppError("Reader", "api.file.reader.reading_local.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("Reader", "api.file.reader.reading_local.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
} else {
|
|
||||||
return f, nil
|
|
||||||
}
|
}
|
||||||
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *LocalFileBackend) ReadFile(path string) ([]byte, *model.AppError) {
|
func (b *LocalFileBackend) ReadFile(path string) ([]byte, *model.AppError) {
|
||||||
if f, err := ioutil.ReadFile(filepath.Join(b.directory, path)); err != nil {
|
f, err := ioutil.ReadFile(filepath.Join(b.directory, path))
|
||||||
|
if err != nil {
|
||||||
return nil, model.NewAppError("ReadFile", "api.file.read_file.reading_local.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("ReadFile", "api.file.read_file.reading_local.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
} else {
|
|
||||||
return f, nil
|
|
||||||
}
|
}
|
||||||
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *LocalFileBackend) FileExists(path string) (bool, *model.AppError) {
|
func (b *LocalFileBackend) FileExists(path string) (bool, *model.AppError) {
|
||||||
@@ -55,12 +55,13 @@ func (b *LocalFileBackend) FileExists(path string) (bool, *model.AppError) {
|
|||||||
|
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return false, nil
|
return false, nil
|
||||||
} else if err == nil {
|
|
||||||
return true, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
return false, model.NewAppError("ReadFile", "api.file.file_exists.exists_local.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return false, model.NewAppError("ReadFile", "api.file.file_exists.exists_local.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *LocalFileBackend) CopyFile(oldPath, newPath string) *model.AppError {
|
func (b *LocalFileBackend) CopyFile(oldPath, newPath string) *model.AppError {
|
||||||
if err := utils.CopyFile(filepath.Join(b.directory, oldPath), filepath.Join(b.directory, newPath)); err != nil {
|
if err := utils.CopyFile(filepath.Join(b.directory, oldPath), filepath.Join(b.directory, newPath)); err != nil {
|
||||||
@@ -111,15 +112,15 @@ func (b *LocalFileBackend) RemoveFile(path string) *model.AppError {
|
|||||||
|
|
||||||
func (b *LocalFileBackend) ListDirectory(path string) (*[]string, *model.AppError) {
|
func (b *LocalFileBackend) ListDirectory(path string) (*[]string, *model.AppError) {
|
||||||
var paths []string
|
var paths []string
|
||||||
if fileInfos, err := ioutil.ReadDir(filepath.Join(b.directory, path)); err != nil {
|
fileInfos, err := ioutil.ReadDir(filepath.Join(b.directory, path))
|
||||||
|
if err != nil {
|
||||||
return nil, model.NewAppError("ListDirectory", "utils.file.list_directory.local.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("ListDirectory", "utils.file.list_directory.local.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
} else {
|
}
|
||||||
for _, fileInfo := range fileInfos {
|
for _, fileInfo := range fileInfos {
|
||||||
if fileInfo.IsDir() {
|
if fileInfo.IsDir() {
|
||||||
paths = append(paths, filepath.Join(path, fileInfo.Name()))
|
paths = append(paths, filepath.Join(path, fileInfo.Name()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return &paths, nil
|
return &paths, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user