You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
722 B

  1. package util
  2. import (
  3. "errors"
  4. "os"
  5. "github.com/chrislusf/seaweedfs/weed/glog"
  6. )
  7. func TestFolderWritable(folder string) (err error) {
  8. fileInfo, err := os.Stat(folder)
  9. if err != nil {
  10. return err
  11. }
  12. if !fileInfo.IsDir() {
  13. return errors.New("Not a valid folder!")
  14. }
  15. perm := fileInfo.Mode().Perm()
  16. glog.V(0).Infoln("Folder", folder, "Permission:", perm)
  17. if 0200&perm != 0 {
  18. return nil
  19. }
  20. return errors.New("Not writable!")
  21. }
  22. func GetFileSize(file *os.File) (size int64, err error) {
  23. var fi os.FileInfo
  24. if fi, err = file.Stat(); err == nil {
  25. size = fi.Size()
  26. }
  27. return
  28. }
  29. func FileExists(filename string) bool {
  30. _, err := os.Stat(filename)
  31. if os.IsNotExist(err) {
  32. return false
  33. }
  34. return true
  35. }