cmd/server/util.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
package main
import (
"fmt"
"io"
"os"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func copyFile(src, dst string) error {
// Open the source file
sourceFile, err := os.Open(src)
if err != nil {
return fmt.Errorf("failed to open source file: %w", err)
}
defer sourceFile.Close()
// Create the destination file
destinationFile, err := os.Create(dst)
if err != nil {
return fmt.Errorf("failed to create destination file: %w", err)
}
defer destinationFile.Close()
// Copy the content
_, err = io.Copy(destinationFile, sourceFile)
if err != nil {
return fmt.Errorf("failed to copy file: %w", err)
}
// Flush file metadata to disk
err = destinationFile.Sync()
if err != nil {
return fmt.Errorf("failed to sync destination file: %w", err)
}
return nil
}
|