Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions providers/os/connection/device/linux/device_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/rs/zerolog/log"
"github.com/spf13/afero"
"go.mondoo.com/cnquery/v12/providers/os/connection/snapshot"
"go.mondoo.com/cnquery/v12/providers/os/fs"
"go.mondoo.com/cnquery/v12/providers/os/mountedfs"
"go.mondoo.com/cnquery/v12/providers/os/resources"
)

Expand Down Expand Up @@ -201,7 +201,7 @@ func (d *LinuxDeviceManager) attemptFindFstab(dir string) ([]resources.FstabEntr

mnt, fstab := path.Split(strings.TrimSpace(string(out)))
fstabFile, err := afero.ReadFile(
fs.NewMountedFs(mnt),
mountedfs.NewMountedFs(mnt),
path.Base(fstab))
if err != nil {
log.Error().Err(err).Msg("error reading fstab")
Expand Down
6 changes: 3 additions & 3 deletions providers/os/connection/fs/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"go.mondoo.com/cnquery/v12/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v12/providers-sdk/v1/plugin"
"go.mondoo.com/cnquery/v12/providers/os/connection/shared"
"go.mondoo.com/cnquery/v12/providers/os/fs"
"go.mondoo.com/cnquery/v12/providers/os/mountedfs"
)

var (
Expand All @@ -33,7 +33,7 @@ func NewFileSystemConnectionWithClose(id uint32, conf *inventory.Config, asset *

log.Debug().Str("path", path).Msg("load filesystem")

return NewFileSystemConnectionWithFs(id, conf, asset, path, closeFN, fs.NewMountedFs(path))
return NewFileSystemConnectionWithFs(id, conf, asset, path, closeFN, mountedfs.NewMountedFs(path))
}

func NewFileSystemConnectionWithFs(id uint32, conf *inventory.Config, asset *inventory.Asset, path string, closeFN func(), fs afero.Fs) (*FileSystemConnection, error) {
Expand Down Expand Up @@ -69,7 +69,7 @@ func (c *FileSystemConnection) RunCommand(command string) (*shared.Command, erro

func (c *FileSystemConnection) FileSystem() afero.Fs {
if c.fs == nil {
c.fs = fs.NewMountedFs(c.MountedDir)
c.fs = mountedfs.NewMountedFs(c.MountedDir)
}
return c.fs
}
Expand Down
28 changes: 28 additions & 0 deletions providers/os/connection/local/fs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package local

import (
"regexp"

"github.com/spf13/afero"
"go.mondoo.com/cnquery/v12/providers/os/connection/shared"
"go.mondoo.com/cnquery/v12/providers/os/fsutil"
)

var _ shared.FileSearch = (*FS)(nil)

func NewFs() *FS {
return &FS{}
}

type FS struct {
afero.OsFs
}

// Find searches for files and returns the file info, regex can be nil
func (fs *FS) Find(from string, r *regexp.Regexp, typ string, perm *uint32, depth *int) ([]string, error) {
iofs := afero.NewIOFS(fs)
return fsutil.FindFiles(iofs, from, r, typ, perm, depth)
}
9 changes: 8 additions & 1 deletion providers/os/connection/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package local

import (
"bytes"
"os"
"os/exec"
"runtime"
"strings"
Expand Down Expand Up @@ -65,6 +66,12 @@ func (p *LocalConnection) UpdateAsset(asset *inventory.Asset) {
}

func (p *LocalConnection) Capabilities() shared.Capabilities {
// local fs has experimental local search support that does not require find command
envSearch := os.Getenv("LOCAL_FS_SEARCH")
if envSearch == "1" || strings.ToLower(envSearch) == "true" {
return shared.Capability_File | shared.Capability_RunCommand | shared.Capability_FindFile
}

return shared.Capability_File | shared.Capability_RunCommand
}

Expand All @@ -88,7 +95,7 @@ func (p *LocalConnection) FileSystem() afero.Fs {
if p.Sudo != nil && p.Sudo.Active {
p.fs = cat.New(p)
} else {
p.fs = afero.NewOsFs()
p.fs = NewFs()
}

return p.fs
Expand Down
3 changes: 1 addition & 2 deletions providers/os/connection/tar/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ func (fs *FS) tar(path string, header *tar.Header) (io.ReadCloser, error) {
return tarReader, nil
}

// searches for files and returns the file info
// regex can be nil
// Find searches for files and returns the file info, regex can be nil
func (fs *FS) Find(from string, r *regexp.Regexp, typ string, perm *uint32, depth *int) ([]string, error) {
list := []string{}
for k := range fs.FileMap {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package fs
package fsutil

import (
"io/fs"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package fs
package fsutil

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//go:build linux || darwin || netbsd || openbsd || freebsd
// +build linux darwin netbsd openbsd freebsd

package fs
package fsutil

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//go:build windows
// +build windows

package fs
package fsutil

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion providers/os/fs/file.go → providers/os/mountedfs/file.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package fs
package mountedfs

import (
"os"
Expand Down
5 changes: 3 additions & 2 deletions providers/os/fs/fs.go → providers/os/mountedfs/fs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package fs
package mountedfs

import (
"errors"
Expand All @@ -12,6 +12,7 @@ import (

"github.com/spf13/afero"
"go.mondoo.com/cnquery/v12/providers/os/connection/shared"
"go.mondoo.com/cnquery/v12/providers/os/fsutil"
)

var _ shared.FileSearch = (*MountedFs)(nil)
Expand Down Expand Up @@ -118,5 +119,5 @@ func (t *MountedFs) Chown(name string, uid, gid int) error {

func (t *MountedFs) Find(from string, r *regexp.Regexp, typ string, perm *uint32, depth *int) ([]string, error) {
iofs := afero.NewIOFS(t)
return FindFiles(iofs, from, r, typ, perm, depth)
return fsutil.FindFiles(iofs, from, r, typ, perm, depth)
}
Loading
Loading