~vladh/fotografiska2

8b4a7475a13bb08a7312b52fc74dd94eb3fa6746 — Vlad-Stefan Harbuz 1 year, 8 months ago f73e741
improve file copying strategy
1 files changed, 5 insertions(+), 10 deletions(-)

M main.go
M main.go => main.go +5 -10
@@ 6,8 6,8 @@ package main
import (
	"flag"
	"fmt"
	"io"
	"os"
	"os/exec"
	"path/filepath"
	"regexp"
	"strings"


@@ 328,18 328,13 @@ func validateDir(dirPath string) string {


func copyFile(srcPath string, dstPath string) int64 {
	srcFile, err := os.Open(srcPath)
	cmd := exec.Command("cp", "--preserve=timestamps", srcPath, dstPath)
	err := cmd.Run()
	if err != nil { panic(err) }
	defer srcFile.Close()

	dstFile, err := os.Create(dstPath)
	filestat, err := os.Stat(dstPath)
	if err != nil { panic(err) }
	defer dstFile.Close()

	bytesCopied, err := io.Copy(dstFile, srcFile)
	if err != nil { panic(err) }

	return bytesCopied
	return filestat.Size()
}