Skip to content

Commit 1f91050

Browse files
committed
🧹 refactor packages for filesystem handling
1 parent 953f530 commit 1f91050

File tree

10 files changed

+16
-16
lines changed

10 files changed

+16
-16
lines changed

providers/os/connection/device/linux/device_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/rs/zerolog/log"
2020
"github.com/spf13/afero"
2121
"go.mondoo.com/cnquery/v12/providers/os/connection/snapshot"
22-
"go.mondoo.com/cnquery/v12/providers/os/fs"
22+
"go.mondoo.com/cnquery/v12/providers/os/mountedfs"
2323
"go.mondoo.com/cnquery/v12/providers/os/resources"
2424
)
2525

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

202202
mnt, fstab := path.Split(strings.TrimSpace(string(out)))
203203
fstabFile, err := afero.ReadFile(
204-
fs.NewMountedFs(mnt),
204+
mountedfs.NewMountedFs(mnt),
205205
path.Base(fstab))
206206
if err != nil {
207207
log.Error().Err(err).Msg("error reading fstab")

providers/os/connection/fs/filesystem.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"go.mondoo.com/cnquery/v12/providers-sdk/v1/inventory"
1313
"go.mondoo.com/cnquery/v12/providers-sdk/v1/plugin"
1414
"go.mondoo.com/cnquery/v12/providers/os/connection/shared"
15-
"go.mondoo.com/cnquery/v12/providers/os/fs"
15+
"go.mondoo.com/cnquery/v12/providers/os/mountedfs"
1616
)
1717

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

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

36-
return NewFileSystemConnectionWithFs(id, conf, asset, path, closeFN, fs.NewMountedFs(path))
36+
return NewFileSystemConnectionWithFs(id, conf, asset, path, closeFN, mountedfs.NewMountedFs(path))
3737
}
3838

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

7070
func (c *FileSystemConnection) FileSystem() afero.Fs {
7171
if c.fs == nil {
72-
c.fs = fs.NewMountedFs(c.MountedDir)
72+
c.fs = mountedfs.NewMountedFs(c.MountedDir)
7373
}
7474
return c.fs
7575
}

providers/os/connection/tar/fs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ func (fs *FS) tar(path string, header *tar.Header) (io.ReadCloser, error) {
193193
return tarReader, nil
194194
}
195195

196-
// searches for files and returns the file info
197-
// regex can be nil
196+
// Find searches for files and returns the file info, regex can be nil
198197
func (fs *FS) Find(from string, r *regexp.Regexp, typ string, perm *uint32, depth *int) ([]string, error) {
199198
list := []string{}
200199
for k := range fs.FileMap {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Mondoo, Inc.
22
// SPDX-License-Identifier: BUSL-1.1
33

4-
package fs
4+
package fsutil
55

66
import (
77
"io/fs"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Mondoo, Inc.
22
// SPDX-License-Identifier: BUSL-1.1
33

4-
package fs
4+
package fsutil
55

66
import (
77
"fmt"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//go:build linux || darwin || netbsd || openbsd || freebsd
55
// +build linux darwin netbsd openbsd freebsd
66

7-
package fs
7+
package fsutil
88

99
import (
1010
"errors"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//go:build windows
55
// +build windows
66

7-
package fs
7+
package fsutil
88

99
import (
1010
"errors"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Mondoo, Inc.
22
// SPDX-License-Identifier: BUSL-1.1
33

4-
package fs
4+
package mountedfs
55

66
import (
77
"os"
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Mondoo, Inc.
22
// SPDX-License-Identifier: BUSL-1.1
33

4-
package fs
4+
package mountedfs
55

66
import (
77
"errors"
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/spf13/afero"
1414
"go.mondoo.com/cnquery/v12/providers/os/connection/shared"
15+
"go.mondoo.com/cnquery/v12/providers/os/fsutil"
1516
)
1617

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

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

providers/os/resources/services/systemd_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/stretchr/testify/require"
1111
"go.mondoo.com/cnquery/v12/providers-sdk/v1/inventory"
1212
"go.mondoo.com/cnquery/v12/providers/os/connection/mock"
13-
"go.mondoo.com/cnquery/v12/providers/os/fs"
13+
"go.mondoo.com/cnquery/v12/providers/os/mountedfs"
1414
)
1515

1616
func TestSystemDExtractDescription(t *testing.T) {
@@ -112,7 +112,7 @@ func TestParseServiceSystemDUnitFilesPhoton(t *testing.T) {
112112

113113
func TestSystemdFS(t *testing.T) {
114114
s := SystemdFSServiceManager{
115-
Fs: fs.NewMountedFs("testdata/systemd"),
115+
Fs: mountedfs.NewMountedFs("testdata/systemd"),
116116
}
117117

118118
services, err := s.List()

0 commit comments

Comments
 (0)