photoprism/pkg/fs/copy.go
Michael Mayer 26ca084699 Videos: Cache embedded media to allow streaming and transcoding #3764
This is a follow-up improvement for the following feature requests that
have already shipped with our stable release:

- Live Photos: Add support for Samsung Motion Photos #439
- Live Photos: Add support for Google Camera Motion Photos #1739

Signed-off-by: Michael Mayer <michael@photoprism.app>
2023-09-24 17:13:06 +02:00

46 lines
633 B
Go

package fs
import (
"fmt"
"io"
"os"
"path/filepath"
)
// Copy copies a file to a destination.
func Copy(src, dest string) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("copy: %s (panic)", r)
}
}()
if err := os.MkdirAll(filepath.Dir(dest), ModeDir); err != nil {
return err
}
thisFile, err := os.Open(src)
if err != nil {
return err
}
defer thisFile.Close()
destFile, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE, ModeFile)
if err != nil {
return err
}
defer destFile.Close()
_, err = io.Copy(destFile, thisFile)
if err != nil {
return err
}
return nil
}