mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
40 lines
653 B
Go
40 lines
653 B
Go
// Copyright (C) 2022, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package binutils
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/luxfi/cli/v2/pkg/constants"
|
|
)
|
|
|
|
func CopyFile(src, dest string) error {
|
|
in, err := os.Open(src)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer in.Close()
|
|
out, err := os.Create(dest)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer func() {
|
|
cerr := out.Close()
|
|
if err == nil {
|
|
err = cerr
|
|
}
|
|
}()
|
|
if _, err = io.Copy(out, in); err != nil {
|
|
return err
|
|
}
|
|
if err = out.Sync(); err != nil {
|
|
return err
|
|
}
|
|
if err = out.Chmod(constants.DefaultPerms755); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|