forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profilelist.go
59 lines (51 loc) · 1.56 KB
/
profilelist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
package libdokan
import (
"runtime/pprof"
"github.com/keybase/kbfs/dokan"
"github.com/keybase/kbfs/libfs"
"golang.org/x/net/context"
)
// TODO: Also have a file for CPU profiles.
// ProfileList is a node that can list all of the available profiles.
type ProfileList struct {
fs *FS
emptyFile
}
// GetFileInformation for dokan.
func (ProfileList) GetFileInformation(ctx context.Context, fi *dokan.FileInfo) (st *dokan.Stat, err error) {
return defaultDirectoryInformation()
}
// open tries to open a file.
func (pl ProfileList) open(ctx context.Context, oc *openContext, path []string) (dokan.File, bool, error) {
if len(path) == 0 {
return oc.returnDirNoCleanup(ProfileList{})
}
if len(path) > 1 || !libfs.IsSupportedProfileName(path[0]) {
return nil, false, dokan.ErrObjectNameNotFound
}
f := libfs.ProfileGet(path[0])
if f == nil {
return nil, false, dokan.ErrObjectNameNotFound
}
return oc.returnFileNoCleanup(&SpecialReadFile{read: f, fs: pl.fs})
}
// FindFiles does readdir for dokan.
func (ProfileList) FindFiles(ctx context.Context, fi *dokan.FileInfo, ignored string, callback func(*dokan.NamedStat) error) (err error) {
profiles := pprof.Profiles()
var ns dokan.NamedStat
ns.FileAttributes = dokan.FileAttributeReadonly
for _, p := range profiles {
ns.Name = p.Name()
if !libfs.IsSupportedProfileName(ns.Name) {
continue
}
err := callback(&ns)
if err != nil {
return err
}
}
return nil
}