diff --git a/providers/os/connection/device/device_connection.go b/providers/os/connection/device/device_connection.go index 0b6b91b78..c1d90e17b 100644 --- a/providers/os/connection/device/device_connection.go +++ b/providers/os/connection/device/device_connection.go @@ -25,10 +25,12 @@ import ( const PlatformIdInject = "inject-platform-ids" type DeviceConnection struct { - FsConnections []*fs.FileSystemConnection + *fs.FileSystemConnection plugin.Connection asset *inventory.Asset deviceManager DeviceManager + + MountedDirs []string } func getDeviceManager(conf *inventory.Config) (DeviceManager, error) { @@ -79,6 +81,8 @@ func NewDeviceConnection(connId uint32, conf *inventory.Config, asset *inventory } conf.Options["path"] = scanDir + res.MountedDirs = append(res.MountedDirs, scanDir) + // create and initialize fs provider fsConn, err := fs.NewConnection(connId, &inventory.Config{ Path: scanDir, @@ -92,8 +96,6 @@ func NewDeviceConnection(connId uint32, conf *inventory.Config, asset *inventory return nil, err } - res.FsConnections = append(res.FsConnections, fsConn) - // allow injecting platform ids into the device connection. we cannot always know the asset that's being scanned, e.g. // if we can scan an azure VM's disk we should be able to inject the platform ids of the VM if platformIDs, ok := conf.Options[PlatformIdInject]; ok { @@ -119,7 +121,7 @@ func NewDeviceConnection(connId uint32, conf *inventory.Config, asset *inventory } asset.Platform = p asset.IdDetector = []string{ids.IdDetector_Hostname} - fingerprint, p, err := id.IdentifyPlatform(fsConn, &plugin.ConnectReq{}, asset.Platform, asset.IdDetector) + fingerprint, p, err := id.IdentifyPlatform(res, &plugin.ConnectReq{}, asset.Platform, asset.IdDetector) if err == nil { if asset.Name == "" { asset.Name = fingerprint.Name @@ -128,6 +130,8 @@ func NewDeviceConnection(connId uint32, conf *inventory.Config, asset *inventory asset.IdDetector = fingerprint.ActiveIdDetectors asset.Platform = p asset.Id = conf.Type + + res.FileSystemConnection = fsConn } } @@ -136,6 +140,11 @@ func NewDeviceConnection(connId uint32, conf *inventory.Config, asset *inventory return nil, errors.New("failed to detect OS") } + if res.FileSystemConnection == nil { + res.Close() + return nil, errors.New("failed to create fs connection") + } + return res, nil } @@ -167,7 +176,7 @@ func (p *DeviceConnection) UpdateAsset(asset *inventory.Asset) { } func (p *DeviceConnection) Capabilities() shared.Capabilities { - return p.FsConnections[0].Capabilities() + return p.FileSystemConnection.Capabilities() } func (p *DeviceConnection) RunCommand(command string) (*shared.Command, error) { @@ -175,13 +184,13 @@ func (p *DeviceConnection) RunCommand(command string) (*shared.Command, error) { } func (p *DeviceConnection) FileSystem() afero.Fs { - return p.FsConnections[0].FileSystem() + return p.FileSystemConnection.FileSystem() } func (p *DeviceConnection) FileInfo(path string) (shared.FileInfoDetails, error) { - return p.FsConnections[0].FileInfo(path) + return p.FileSystemConnection.FileInfo(path) } func (p *DeviceConnection) Conf() *inventory.Config { - return p.FsConnections[0].Conf + return p.FileSystemConnection.Conf }