/** * Check if current PHP process has permission to change the mode * of $fileOrDirectory. * * @TODO from KWUtils, may need to be moved, but first tested * Note: If return true, the mode of the file will be MIDAS_BATCHMAKE_DEFAULT_MKDIR_MODE * On windows, return always True */ protected function isChmodable($fileOrDirectory, $processUserUid) { if (KWUtils::isWindows()) { return true; } if (!file_exists($fileOrDirectory)) { Zend_Loader::loadClass('InternationalizationComponent', BASE_PATH . '/core/controllers/components'); self::Error(InternationalizationComponent::translate(MIDAS_BATCHMAKE_FILE_OR_DIRECTORY_DOESNT_EXIST_STRING) . ' [' . $fileOrDirectory . ']'); return false; } // Get permissions of the file // TODO On CIFS filesystem, even if the function GetFilePermissions call clearstatcache(), the value returned can be wrong $current_perms = KWUtils::DEFAULT_MKDIR_MODE; if ($current_perms === false) { return false; } if (is_writable($fileOrDirectory)) { // first check on the uid of the fileOrDirectory // if that is different than the processUserUid, then chmod // will return false and add a warning, so let's prevent this beforehand $fileStat = stat($fileOrDirectory); $fileUid = $fileStat['uid']; if ($fileUid !== $processUserUid) { return false; } else { // Try to re-apply them $return = chmod($fileOrDirectory, $current_perms); } } else { $return = false; } return $return; }
/** tests prepareExecCommand function */ public function testPrepareExecCommand() { $app = 'php'; if (KWUtils::isWindows()) { $app .= '.exe'; } $returnVal = KWUtils::prepareExecCommand($app, array('blah1', 'blah2', 'blah3')); $appPath = KWUtils::findApp($app, true); $this->assertEquals($returnVal, "'" . $appPath . "' 'blah1' 'blah2' 'blah3'"); }