Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Add a method to check if a drive is a network drive. Consider smb and… (
Browse files Browse the repository at this point in the history
#2440)

* Add a method to check if a drive is a network drive. Consider smbfs and afps as network drives
  • Loading branch information
Walid Nouh committed Jan 19, 2018
1 parent b35190b commit 8975faa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
24 changes: 19 additions & 5 deletions inc/formatconvert.class.php
Expand Up @@ -947,9 +947,7 @@ static function computerInventoryTransformation($array) {
break;
}
}
if (isset($a_drives['FILESYSTEM']) && $a_drives['FILESYSTEM'] == 'nfs') {
$isNetworkDriveOrFS = true;
}
$isNetworkDriveOrFS = $thisc->isANetworkDrive($a_drives);
if ($pfConfig->getValue("component_drive") == '0'
OR ($pfConfig->getValue("component_networkdrive") == '0' AND $isNetworkDriveOrFS)
OR ($pfConfig->getValue("component_removablemedia") == '0' AND $isRemovableMedia)) {
Expand Down Expand Up @@ -1426,7 +1424,8 @@ static function computerInventoryTransformation($array) {
//Try to avoid duplicate license,
//as FI agent may send several entries for the same license
foreach ($a_inventory['licenseinfo'] as $lic) {
if ($lic['fullname'] == $a_licenseinfo['FULLNAME']
if (isset($a_licenseinfo['FULLNAME'])
&& $lic['fullname'] == $a_licenseinfo['FULLNAME']
&& $lic['serial'] == $a_licenseinfo['KEY']) {
$insert = false;
}
Expand Down Expand Up @@ -2334,5 +2333,20 @@ static function getTypeDrive($data) {
return 'HardDrive';
}


/**
* Test if a drive is a local or network drive
* @since 9.2+2.0
*
* @param array $drive the drive inventory to be tested
* @return boolean true if it's a network drive, false if it's a local drive
*/
function isANetworkDrive($drive) {
$network_drives = ['nfs', 'smbfs', 'afpfs'];
if (isset($drive['FILESYSTEM'])
&& in_array(strtolower($drive['FILESYSTEM']), $network_drives)) {
return true;
} else {
return false;
}
}
}
16 changes: 15 additions & 1 deletion phpunit/1_Unit/ComputerTransformationTest.php
Expand Up @@ -2006,5 +2006,19 @@ function ComputerBiosAssettag_filled() {
$this->assertEquals($a_reference, $a_return);
}


/**
* @test
*/
function testIsANetworkDevice() {
$drive = ['FREE' => '3332501',
'TOTAL' =>'19066219',
'TYPE' => '/Volume/MyNetworkshare'
];
$pfFormatconvert = new PluginFusioninventoryFormatconvert();
foreach (['afpfs' => true, 'nfs' => true, 'smbfs' => true,
'ext4' => false, 'fat32' => false] as $fs => $result) {
$drive['FILESYSTEM'] = $fs;
$this->assertEquals($result, $pfFormatconvert->isANetworkDrive($drive));
}
}
}

0 comments on commit 8975faa

Please sign in to comment.