first
This commit is contained in:
63
DCIManager6/dci6-support/platform-conf.go
Normal file
63
DCIManager6/dci6-support/platform-conf.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
func copyFiles(src, dst string) error {
|
||||
isSrcExist, err := os.Stat(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !isSrcExist.Mode().IsRegular() {
|
||||
return &os.PathError{
|
||||
Op: "copy",
|
||||
Path: src,
|
||||
Err: errors.New("не является обычным файлом"),
|
||||
}
|
||||
}
|
||||
|
||||
source, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer source.Close()
|
||||
|
||||
destination, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer destination.Close()
|
||||
_, err = io.Copy(destination, source)
|
||||
return err
|
||||
}
|
||||
|
||||
func getIspFileNames(dirName string) ([]string, []error) {
|
||||
var fileList []string
|
||||
var errs []error
|
||||
|
||||
ispList, err := os.ReadDir(dirName)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Ошибка при получении содержимого директории %s : %s", dirName, err)
|
||||
errs = append(errs, err)
|
||||
err = nil
|
||||
}
|
||||
for _, entry := range ispList {
|
||||
dirPath := dirName + "/" + entry.Name()
|
||||
if entry.IsDir() {
|
||||
interList, interErrs := getIspFileNames(dirPath)
|
||||
for _, ie := range interErrs {
|
||||
errs = append(errs, ie)
|
||||
}
|
||||
for _, il := range interList {
|
||||
fileList = append(fileList, il)
|
||||
}
|
||||
}
|
||||
fileList = append(fileList, dirPath)
|
||||
}
|
||||
|
||||
return fileList, errs
|
||||
}
|
||||
Reference in New Issue
Block a user