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.

38 lines
676 B

  1. package util
  2. import (
  3. "bufio"
  4. "errors"
  5. "os"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. )
  8. func TestFolderWritable(folder string) (err error) {
  9. fileInfo, err := os.Stat(folder)
  10. if err != nil {
  11. return err
  12. }
  13. if !fileInfo.IsDir() {
  14. return errors.New("Not a valid folder!")
  15. }
  16. perm := fileInfo.Mode().Perm()
  17. glog.V(0).Infoln("Folder", folder, "Permission:", perm)
  18. if 0200&perm != 0 {
  19. return nil
  20. }
  21. return errors.New("Not writable!")
  22. }
  23. func Readln(r *bufio.Reader) ([]byte, error) {
  24. var (
  25. isPrefix = true
  26. err error
  27. line, ln []byte
  28. )
  29. for isPrefix && err == nil {
  30. line, isPrefix, err = r.ReadLine()
  31. ln = append(ln, line...)
  32. }
  33. return ln, err
  34. }