1
0
mirror of https://github.com/gogs/gogs.git synced 2025-05-06 23:51:15 +00:00
ᴜɴᴋɴᴡᴏɴ 8796df8218
conf: add unit tests ()
* conf: add tests for utils.go

* conf: add tests for static.go

* mock os/exec

* Run tests on Windows

* appveyor: fix gcc not found

* computed: add unit tests

* log: add unit tests

* log: fix tests on Windows

* conf: add some tests

* Finish adding tests

* Cover more cases

* Add tests for testutil

* Add more tests
2020-02-29 22:24:20 +08:00

35 lines
757 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()
}
// 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")
}