package main /* * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): * wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return * ---------------------------------------------------------------------------- */ import ( "io" "os" ) /** clone copies the contents of cloneSource to cloneTarget @param cloneBs int is the block size used for the cloning @param cloneSource string is the source file / volume for the clone @param cloneTarget string is the target file / volume for the clone */ func clone(cloneBs int, cloneSource string, cloneTarget string) { p := make([]byte, cloneBs) fSource, err := os.Open(cloneSource) defer fSource.Close() errorHandler(err) //todo add file not found handling fTarget, err := os.OpenFile(cloneTarget, os.O_WRONLY, 0644) defer fTarget.Close() errorHandler(err) //todo progress indicator for { n, err := fSource.Read(p) if err == io.EOF { _, err = fTarget.Write(p[:n]) errorHandler(err) break } errorHandler(err) _, err = fTarget.Write(p[:n]) errorHandler(err) } fTarget.Sync() }