1
0
Fork 0
mirror of https://github.com/Luzifer/password.git synced 2024-12-20 21:01:17 +00:00
password/vendor/github.com/tredoe/osutil/user/util.go
Knut Ahlers 8af625be60
Fix: Vendor new dependencies
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2017-10-06 22:59:38 +02:00

43 lines
885 B
Go

// Copyright 2010 Jonas mg
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package user
import "os"
var isRoot bool
func init() {
// Root's user ID is 0.
if os.Getuid() == 0 {
isRoot = true
}
}
// checkRoot checks if the user is root.
func checkRoot() {
if !isRoot {
panic("you have to be Root")
}
}
// exist checks if the file exists.
func exist(file string) (bool, error) {
_, err := os.Stat(file)
if err != nil {
if err == os.ErrNotExist {
return false, nil
}
return false, err
}
return true, nil
}
// _SEC_PER_DAY is the number of secons that a day has.
const _SEC_PER_DAY = 24 * 60 * 60
// secToDay converts from secons to days.
func secToDay(sec int64) int { return int(sec / _SEC_PER_DAY) }