utils.go 566 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // utils
  2. package main
  3. import (
  4. "io"
  5. "os"
  6. "os/user"
  7. "path"
  8. )
  9. func gethomedir() string {
  10. u, _ := user.Current()
  11. return u.HomeDir
  12. }
  13. func gethistfile() string {
  14. const fname = ".bash_history"
  15. return path.Join(gethomedir(), fname)
  16. }
  17. func mktmpfile() string {
  18. const fname = ".bash_history"
  19. return path.Join("/tmp", fname)
  20. }
  21. func CopyFile(src, dst string) (int64, error) {
  22. sf, err := os.Open(src)
  23. if err != nil {
  24. return 0, err
  25. }
  26. defer sf.Close()
  27. df, err := os.Create(dst)
  28. if err != nil {
  29. return 0, err
  30. }
  31. defer df.Close()
  32. return io.Copy(df, sf)
  33. }