From 50cc180084f086ccd2a81034a06c51c0fab36ba2 Mon Sep 17 00:00:00 2001 From: Yawning Angel Date: Thu, 15 May 2014 06:12:31 +0000 Subject: Use os.MkdirAll() for creating the pt state directory. --- obfs4proxy/obfs4proxy.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'obfs4proxy/obfs4proxy.go') diff --git a/obfs4proxy/obfs4proxy.go b/obfs4proxy/obfs4proxy.go index 016a0bb..ff53863 100644 --- a/obfs4proxy/obfs4proxy.go +++ b/obfs4proxy/obfs4proxy.go @@ -297,31 +297,23 @@ func ptIsServer() bool { return env != "" } -func ptGetStateDir() string { - dir := os.Getenv("TOR_PT_STATE_LOCATION") +func ptGetStateDir() (dir string, err error) { + dir = os.Getenv("TOR_PT_STATE_LOCATION") if dir == "" { - return dir + return } - stat, err := os.Stat(dir) + err = os.MkdirAll(dir, 0755) if err != nil { - if !os.IsNotExist(err) { - log.Fatalf("[ERROR] Failed to stat path: %s", err) - } - err = os.Mkdir(dir, 0755) - if err != nil { - log.Fatalf("[ERROR] Failed to create path: %s", err) - } - } else if !stat.IsDir() { - log.Fatalf("[ERROR] Pluggable Transport state location is not a directory") + log.Fatalf("[ERROR] Failed to create path: %s", err) } - return dir + return } func ptInitializeLogging() { - dir := ptGetStateDir() - if dir == "" { + dir, err := ptGetStateDir() + if err != nil || dir == "" { return } -- cgit v1.2.3