// Given a filepath, get it's permission bits
346444
func Stat(filepath string) (PermissionBits, error) {
	fi, err := os.Stat(filepath)
	if err != nil {
		return 0, err
	}
	return FileMode(fi.Mode()), nil
}
22964
func (client *Client) GetPermissions(ctx context.Context, tablet *topodatapb.Tablet) (*tabletmanagerdatapb.Permissions, error) {
	cc, c, err := client.dial(tablet)
	if err != nil {
		return nil, err
	}
	defer cc.Close()
	response, err := c.GetPermissions(ctx, &tabletmanagerdatapb.GetPermissionsRequest{})
	if err != nil {
		return nil, err
	}
	return response.Permissions, nil
}
466593
func (agent *ActionAgent) GetPermissions(ctx context.Context) (*tabletmanagerdatapb.Permissions, error) {
	return mysqlctl.GetPermissions(agent.MysqlDaemon)
}
544579
func (quobyteVolume *quobyte) GetPath() string {
	user := quobyteVolume.user
	if len(user) == 0 {
		user = "root"
	}

	group := quobyteVolume.group
	if len(group) == 0 {
		group = "nfsnobody"
	}

	// Quobyte has only one mount in the PluginDir where all Volumes are mounted
	// The Quobyte client does a fixed-user mapping
	pluginDir := quobyteVolume.plugin.host.GetPluginDir(utilstrings.EscapeQualifiedName(quobytePluginName))
	return filepath.Join(pluginDir, fmt.Sprintf("%s#%s@%s", user, group, quobyteVolume.volume))
}
59282
func (p *ProjectPermissionLevel) GetPermission() string {
	if p == nil || p.Permission == nil {
		return ""
	}
	return *p.Permission
}
516870
func GetFileContents(path string) (*string, error) {
	if _, err := os.Stat(path); os.IsNotExist(err) {
		return nil, err
	}

	contents, err := ioutil.ReadFile(path)
	if err != nil {
		return nil, err
	}

	strContents := string(contents)
	//If file is empty, return nil
	if strContents == "" {
		return nil, nil
	}
	return &strContents, nil
}
1250520
func (t *TeamProjectOptions) GetPermission() string {
	if t == nil || t.Permission == nil {
		return ""
	}
	return *t.Permission
}
805522
func (fd *FileData) GetIndirectFileBlockInfos(ctx context.Context) (
	[]BlockInfo, error) {
	return fd.tree.getIndirectBlockInfos(ctx)
}
906933
func (u *User) GetPermissions() map[string]bool {
	if u == nil || u.Permissions == nil {
		return map[string]bool{}
	}
	return *u.Permissions
}
98521
func getFileOwnerAndMode(path string) (int, int, os.FileMode) {
	finfo, err := os.Stat(path)
	if err != nil {
		return 0, 0, 0
	}
	return int(finfo.Sys().(*syscall.Stat_t).Uid), int(finfo.Sys().(*syscall.Stat_t).Gid), finfo.Mode()
}
587664
func (s *FileSystemStorage) SaveWithPermissions(filepath string, file File, perm os.FileMode) error {
	_, err := os.Stat(s.Location)

	if err != nil {
		return err
	}

	location := s.Path(filepath)

	basename := location[:strings.LastIndex(location, "/")+1]

	err = os.MkdirAll(basename, perm)

	if err != nil {
		return err
	}

	content, err := file.ReadAll()

	if err != nil {
		return err
	}

	err = ioutil.WriteFile(location, content, perm)

	return err
}
244389
func VerifyPermissions(ctx context.Context, ps []influxdb.Permission) error {
	for _, p := range ps {
		if err := IsAllowed(ctx, p); err != nil {
			return &influxdb.Error{
				Err:  err,
				Msg:  fmt.Sprintf("permission %s is not allowed", p),
				Code: influxdb.EForbidden,
			}
		}
	}

	return nil
}
402345
func (o *NSGateway) Permissions(info *bambou.FetchingInfo) (PermissionsList, *bambou.Error) {

	var list PermissionsList
	err := bambou.CurrentSession().FetchChildren(o, PermissionIdentity, &list, info)
	return list, err
}
570787
func (f *fsClient) GetAccess() (access string, policyJSON string, err *probe.Error) {
	// For windows this feature is not implemented.
	if runtime.GOOS == "windows" {
		return "", "", probe.NewError(APINotImplemented{API: "GetAccess", APIType: "filesystem"})
	}
	st, err := f.fsStat(false)
	if err != nil {
		return "", "", err.Trace(f.PathURL.String())
	}
	if !st.Mode().IsDir() {
		return "", "", probe.NewError(APINotImplemented{API: "GetAccess", APIType: "filesystem"})
	}
	// Mask with os.ModePerm to get only inode permissions
	switch st.Mode() & os.ModePerm {
	case os.FileMode(0777):
		return "readwrite", "", nil
	case os.FileMode(0555):
		return "readonly", "", nil
	case os.FileMode(0333):
		return "writeonly", "", nil
	}
	return "none", "", nil
}
445689
func NewFilePermission(Action *FileAction, Allow bool) *FilePermission {
	s := new(FilePermission)
	s.Action = Action
	s.Allow = Allow
	return s
}
1170870
func (r *Repository) GetPermissions() map[string]bool {
	if r == nil || r.Permissions == nil {
		return map[string]bool{}
	}
	return *r.Permissions
}
547636
func GetInventoryFilePath(inventoryPath string) (string, error) {
	if inventoryPath == "" {
		log.Debugln("[BITRISE_CLI] - Inventory path not defined, searching for " + DefaultSecretsFileName + " in current folder...")
		inventoryPath = filepath.Join(configs.CurrentDir, DefaultSecretsFileName)

		if exist, err := pathutil.IsPathExists(inventoryPath); err != nil {
			return "", err
		} else if !exist {
			inventoryPath = ""
		}
	}

	return inventoryPath, nil
}