disksync.go raw

   1  package wallet
   2  
   3  import (
   4  	"fmt"
   5  	"os"
   6  )
   7  
   8  // checkCreateDir checks that the path exists and is a directory. If path does not exist, it is created.
   9  func checkCreateDir(path string) (e error) {
  10  	var fi os.FileInfo
  11  	if fi, e = os.Stat(path); E.Chk(e) {
  12  		if os.IsNotExist(e) {
  13  			// Attempt data directory creation
  14  			if e = os.MkdirAll(path, 0700); E.Chk(e) {
  15  				return fmt.Errorf("cannot create directory: %s", e)
  16  			}
  17  		} else {
  18  			return fmt.Errorf("error checking directory: %s", e)
  19  		}
  20  	} else {
  21  		if !fi.IsDir() {
  22  			return fmt.Errorf("path '%s' is not a directory", path)
  23  		}
  24  	}
  25  	return nil
  26  }
  27