Skip to content

Commit

Permalink
Move IsFileExists into shadowsocks package as utility.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Dec 23, 2012
1 parent 3ae3646 commit 50bbdc3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
16 changes: 1 addition & 15 deletions cmd/shadowsocks-local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,6 @@ func enoughOptions(config *ss.Config) bool {
config.LocalPort != 0 && config.Password != ""
}

func isFileExists(path string) (bool, error) {
stat, err := os.Stat(path)
if err == nil {
if stat.Mode()&os.ModeType == 0 {
return true, nil
}
return false, errors.New(path + " exists but is not regular file")
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}

func main() {
var configFile string
var cmdConfig ss.Config
Expand All @@ -223,7 +209,7 @@ func main() {

flag.Parse()

exists, err := isFileExists(configFile)
exists, err := ss.IsFileExists(configFile)
// If no config file in current directory, try search it in the binary directory
// Note there's no portable way to detect the binary directory.
binDir := path.Dir(os.Args[0])
Expand Down
20 changes: 20 additions & 0 deletions shadowsocks/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package shadowsocks

import (
"errors"
"os"
)

func IsFileExists(path string) (bool, error) {
stat, err := os.Stat(path)
if err == nil {
if stat.Mode()&os.ModeType == 0 {
return true, nil
}
return false, errors.New(path + " exists but is not regular file")
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}

0 comments on commit 50bbdc3

Please sign in to comment.