Skip to content

Commit

Permalink
prevent fsConn from overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
slntopp committed Feb 12, 2025
1 parent a97eb61 commit 15dd698
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions providers/os/connection/device/device_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func NewDeviceConnection(connId uint32, conf *inventory.Config, asset *inventory

if fsConn, err := tryDetectAsset(connId, block, conf, asset); err != nil {
log.Error().Err(err).Msg("partition did not return an asset, continuing")
} else {
} else if fsConn != nil {
res.FileSystemConnection = fsConn
}
}
Expand Down Expand Up @@ -248,13 +248,6 @@ func tryDetectAsset(connId uint32, partition *snapshot.PartitionInfo, conf *inve
return nil, errors.New("device connection> no platform detected")
}

// volumes and partitions without a system on them would return an "unknown" platform
// we don't want to overwrite the platform if a "proper" one was detected already
// as well as we want to always have some platform to the asset
if asset.Platform == nil || !slices.Contains([]string{"", "unknown"}, p.Name) {
asset.Platform = p
}

if asset.Name == "" && fingerprint != nil {
asset.Name = fingerprint.Name
}
Expand All @@ -266,5 +259,13 @@ func tryDetectAsset(connId uint32, partition *snapshot.PartitionInfo, conf *inve

asset.Id = conf.Type

return fsConn, nil
// volumes and partitions without a system on them would return an "unknown" platform
// we don't want to overwrite the platform if a "proper" one was detected already
// as well as we want to always have some platform to the asset
if asset.Platform == nil || !slices.Contains([]string{"", "unknown"}, p.Name) {
asset.Platform = p
return fsConn, nil
}

return nil, nil
}

0 comments on commit 15dd698

Please sign in to comment.