gogs/internal/osutil/osutil.go
ᴜɴᴋɴᴡᴏɴ 41f56ad05d
login_source: migrate to GORM and add tests (#6090)
* Use GORM in all write paths

* Migrate to GORM

* Fix lint errors

* Use GORM  to init table

* dbutil: make writer detect error

* Add more tests

* Rename to clearTables

* db: finish adding tests

* osutil: add tests

* Fix load source files path
2020-04-11 20:18:05 +08:00

45 lines
972 B
Go

// Copyright 2020 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package osutil
import (
"os"
)
// IsFile returns true if given path exists as a file (i.e. not a directory).
func IsFile(path string) bool {
f, e := os.Stat(path)
if e != nil {
return false
}
return !f.IsDir()
}
// IsDir returns true if given path is a directory, and returns false when it's
// a file or does not exist.
func IsDir(dir string) bool {
f, e := os.Stat(dir)
if e != nil {
return false
}
return f.IsDir()
}
// IsExist returns true if a file or directory exists.
func IsExist(path string) bool {
_, err := os.Stat(path)
return err == nil || os.IsExist(err)
}
// CurrentUsername returns the current system user via environment variables.
func CurrentUsername() string {
username := os.Getenv("USER")
if len(username) > 0 {
return username
}
return os.Getenv("USERNAME")
}