| 1 | //go:build linux |
| 2 | |
| 3 | package osfsscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/ |
| 4 | |
| 5 | import ( |
| 6 | "bufioscip-go gomod github.com/golang/go/src go1.25.0 bufio/" |
| 7 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 8 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 9 | "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/" |
| 10 | "runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/" |
| 11 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 12 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 13 | |
| 14 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/" |
| 15 | ) |
| 16 | |
| 17 | func TestRootOSMmapCleanupscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/TestRootOSMmapCleanup().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 18 | dir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() |
| 19 | path := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(dir, "data") |
| 20 | _ = writePatternscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/writePattern().(t, path, 64*1024) |
| 21 | |
| 22 | fs := newTestBoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/newTestBoundOS().(t, dir, WithMmapscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/WithMmap().()) |
| 23 | f, err := fs.Openscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#Open().("data") |
| 24 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 25 | |
| 26 | ok, err := isFileMappedscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/isFileMapped().(path) |
| 27 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 28 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Truescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/True().(t, ok) |
| 29 | |
| 30 | _ = f.Namescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/File#Name.() |
| 31 | f = nil |
| 32 | _ = f |
| 33 | |
| 34 | for range 10 { |
| 35 | runtimescip-go gomod github.com/golang/go/src go1.25.0 runtime/.GCscip-go gomod github.com/golang/go/src go1.25.0 runtime/GC().() |
| 36 | |
| 37 | ok, err = isFileMappedscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/isFileMapped().(path) |
| 38 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 39 | if !ok { |
| 40 | break |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | ok, err = isFileMappedscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/isFileMapped().(path) |
| 45 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 46 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Falsescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/False().(t, ok) |
| 47 | } |
| 48 | |
| 49 | // isFileMapped checks if a path appears in the proc maps file. Only tested |
| 50 | // in Linux. |
| 51 | func isFileMappedscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/isFileMapped().(path string) (bool, error) { |
| 52 | pid := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Getpidscip-go gomod github.com/golang/go/src go1.25.0 os/Getpid().() |
| 53 | |
| 54 | mapsPath := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("/proc/%d/maps", pid) |
| 55 | f, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Openscip-go gomod github.com/golang/go/src go1.25.0 os/Open().(mapsPath) |
| 56 | if err != nil { |
| 57 | return false, err |
| 58 | } |
| 59 | defer f.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().() |
| 60 | |
| 61 | s := bufioscip-go gomod github.com/golang/go/src go1.25.0 bufio/.NewScannerscip-go gomod github.com/golang/go/src go1.25.0 bufio/NewScanner().(f) |
| 62 | for s.Scanscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner#Scan().() { |
| 63 | l := s.Textscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner#Text().() |
| 64 | if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(l, path) { |
| 65 | return true, nil |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return false, s.Errscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner#Err().() |
| 70 | } |