Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use exec() instead of shell_exec(), use result code #264

Merged
merged 23 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4f603b2
Altering utility execution function so to use exec(), and more.
gudmdharalds Mar 28, 2022
7c46e07
Update usage of vipgoci_runtime_measure_exec_with_retry()
gudmdharalds Mar 28, 2022
2a7b743
Update usage of vipgoci_runtime_measure_exec_with_retry()
gudmdharalds Mar 28, 2022
b2687b1
Update usage of vipgoci_runtime_measure_exec_with_retry()
gudmdharalds Mar 28, 2022
131c7b2
Update usage of vipgoci_runtime_measure_exec_with_retry()
gudmdharalds Mar 28, 2022
6b0865f
Update usage of vipgoci_runtime_measure_exec_with_retry()
gudmdharalds Mar 28, 2022
c08fcb7
Update usage of vipgoci_runtime_measure_exec_with_retry()
gudmdharalds Mar 28, 2022
e45f06d
Update usage of vipgoci_runtime_measure_exec_with_retry()
gudmdharalds Mar 28, 2022
160b9a8
Fix spacing.
gudmdharalds Mar 28, 2022
d46b7c1
Merge branch 'main' into update-exec-function
gudmdharalds Mar 28, 2022
c13983e
Renaming variable.
gudmdharalds Mar 28, 2022
e3970c8
Renaming variables.
gudmdharalds Mar 28, 2022
3d1e3f0
Renaming variable.
gudmdharalds Mar 28, 2022
d34f507
Renaming variables.
gudmdharalds Mar 28, 2022
aa341e1
Renaming variables.
gudmdharalds Mar 28, 2022
f82f789
Renaming class to fit new name of function.
gudmdharalds Mar 29, 2022
bbbadb6
Test for command returning empty output; test for command that always…
gudmdharalds Mar 29, 2022
23d03e1
Provide output even if command status code is unexpected.
gudmdharalds Mar 29, 2022
69adabe
Redefine variable type.
gudmdharalds Mar 29, 2022
dc5ec1d
Update comment; test getting standard error output.
gudmdharalds Mar 29, 2022
afb8702
Add helper script.
gudmdharalds Mar 29, 2022
f296f48
Merge branch 'main' into update-exec-function
gudmdharalds Mar 30, 2022
50b73d4
Merge branch 'main' into update-exec-function
gudmdharalds Mar 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions file-validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,18 @@ function vipgoci_is_number_of_lines_valid( string $temp_file_name, string $file_
* if it is > than the default limit (defined at defined)
* the bot won't scan it
*/
$cmd = sprintf( 'wc -l %s | awk \'{print $1;}\' 2>&1', escapeshellcmd( $temp_file_name ) );
$cmd = sprintf( 'wc -l %s | awk \'{print $1;}\'', escapeshellcmd( $temp_file_name ) );

$output_2 = '';
$output_res_code = -255;

$output = vipgoci_runtime_measure_shell_exec_with_retry(
$output = vipgoci_runtime_measure_exec_with_retry(
$cmd,
'file_validation'
array( 0 ),
$output_2,
$output_res_code,
'file_validation',
true
);

vipgoci_log(
Expand Down
140 changes: 106 additions & 34 deletions git-repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function vipgoci_git_version(): ?string {
}

$git_version_cmd = sprintf(
'%s %s 2>&1',
'%s %s',
escapeshellcmd( 'git' ),
escapeshellarg( '--version' )
);
Expand All @@ -24,10 +24,19 @@ function vipgoci_git_version(): ?string {
)
);

/* Actually execute */
$git_version_results = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute
*/
$git_output = '';
$git_result_code = -255;

$git_version_results = vipgoci_runtime_measure_exec_with_retry(
$git_version_cmd,
'git_cli'
array( 0 ),
$git_output,
$git_result_code,
'git_cli',
false
);

if ( null === $git_version_results ) {
Expand Down Expand Up @@ -120,17 +129,26 @@ function vipgoci_gitrepo_get_head( $local_git_repo ) {
*/

$cmd = sprintf(
'%s -C %s log -n %s --pretty=format:"%s" 2>&1',
'%s -C %s log -n %s --pretty=format:"%s"',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
escapeshellarg( 1 ),
escapeshellarg( '%H' )
);

/* Actually execute */
$result = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute
*/
$result_output = '';
$result_code = -255;

$result = vipgoci_runtime_measure_exec_with_retry(
$cmd,
'git_cli'
array( 0 ),
$result_output,
$result_code,
'git_cli',
false
);

if ( null === $result ) {
Expand Down Expand Up @@ -167,15 +185,24 @@ function vipgoci_gitrepo_get_head( $local_git_repo ) {

function vipgoci_gitrepo_branch_current_get( $local_git_repo ) {
$cmd = sprintf(
'%s -C %s branch 2>&1',
'%s -C %s branch',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
);

/* Actually execute */
$results = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute
*/
$results_output = '';
$results_result_code = -255;

$results = vipgoci_runtime_measure_exec_with_retry(
$cmd,
'git_cli'
array( 0 ),
$results_output,
$results_result_code,
'git_cli',
true
);

if ( null === $results ) {
Expand Down Expand Up @@ -400,16 +427,25 @@ function vipgoci_gitrepo_blame_for_file(
*/

$cmd = sprintf(
'%s -C %s blame --line-porcelain %s 2>&1',
'%s -C %s blame --line-porcelain %s',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
escapeshellarg( $file_name )
);

/* Actually execute */
$result = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute
*/
$result_output = '';
$result_code = -255;

$result = vipgoci_runtime_measure_exec_with_retry(
$cmd,
'git_cli'
array( 0 ),
$result_output,
$result_code,
'git_cli',
true
);

if ( null === $result ) {
Expand Down Expand Up @@ -587,17 +623,26 @@ function vipgoci_gitrepo_get_file_at_commit(
*/

$cmd = sprintf(
'%s -C %s show %s:%s 2>&1',
'%s -C %s show %s:%s',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
escapeshellarg( $commit_id ),
escapeshellarg( $file_name )
);

/* Actually execute */
$result = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute
*/
$result_output = '';
$result_code = -255;

$result = vipgoci_runtime_measure_exec_with_retry(
$cmd,
'git_cli'
array( 0, 128 ),
$result_output,
$result_code,
'git_cli',
true
);

if ( null === $result ) {
Expand All @@ -618,8 +663,8 @@ function vipgoci_gitrepo_get_file_at_commit(
* this revision, return null.
*/
if ( strpos(
$result,
'fatal: Path '
strtolower( $result ),
'fatal: path '
) === 0 ) {
return null;
}
Expand All @@ -632,17 +677,26 @@ function vipgoci_gitrepo_get_file_at_commit(
*/
function vipgoci_gitrepo_submodules_setup( $local_git_repo ) {
$cmd = sprintf(
'%s -C %s submodule init && %s -C %s submodule update 2>&1',
'%s -C %s submodule init && %s -C %s submodule update',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo )
);

/* Actually execute */
$result = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute
*/
$result_output = '';
$result_code = -255;

$result = vipgoci_runtime_measure_exec_with_retry(
$cmd,
'git_cli'
array( 0 ),
$result_output,
$result_code,
'git_cli',
true
);

if ( null === $result ) {
Expand Down Expand Up @@ -681,15 +735,24 @@ function vipgoci_gitrepo_submodules_list( $local_git_repo ) {
*/

$cmd = sprintf(
'%s -C %s submodule 2>&1',
'%s -C %s submodule',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
);

/* Actually execute */
$result = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute
*/
$result_output = '';
$result_code = -255;

$result = vipgoci_runtime_measure_exec_with_retry(
$cmd,
'git_cli'
array( 0 ),
$result_output,
$result_code,
'git_cli',
true
);

if ( null === $result ) {
Expand Down Expand Up @@ -920,7 +983,7 @@ function vipgoci_gitrepo_diffs_fetch_unfiltered(
* as that is what GitHub uses: https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-comparing-branches-in-pull-requests#three-dot-and-two-dot-git-diff-comparisons
*/
$git_diff_cmd = sprintf(
'%s -C %s diff %s 2>&1',
'%s -C %s diff %s',
escapeshellcmd( 'git' ),
escapeshellarg( $local_git_repo ),
escapeshellarg( $commit_id_a . '...'. $commit_id_b )
Expand All @@ -933,10 +996,19 @@ function vipgoci_gitrepo_diffs_fetch_unfiltered(
)
);

/* Actually execute */
$git_diff_results = vipgoci_runtime_measure_shell_exec_with_retry(
/*
* Actually execute.
*/
$git_diff_results_output = '';
$git_diff_results_code = -255;

$git_diff_results = vipgoci_runtime_measure_exec_with_retry(
$git_diff_cmd,
'git_cli'
array( 0 ),
$git_diff_results_output,
$git_diff_results_code,
'git_cli',
true
);

if ( null === $git_diff_results ) {
Expand Down
12 changes: 9 additions & 3 deletions lint-scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function vipgoci_lint_do_scan_file(
*/

$cmd = sprintf(
'( %s -d %s -d %s -d %s -l %s 2>&1 )',
'%s -d %s -d %s -d %s -l %s',
escapeshellcmd( $php_path ),
escapeshellarg( 'error_reporting=24575' ),
escapeshellarg( 'error_log=null' ),
Expand All @@ -45,10 +45,16 @@ function vipgoci_lint_do_scan_file(
* Execute linter, grab issues in array,
* measure how long time it took.
*/
$tmp_output = '';
$tmp_result_code = -255;

$file_issues_str = vipgoci_runtime_measure_shell_exec_with_retry(
$file_issues_str = vipgoci_runtime_measure_exec_with_retry(
$cmd,
'php_lint_cli'
array( 0, 255 ),
$tmp_output,
$tmp_result_code,
'php_lint_cli',
true
);

/*
Expand Down
13 changes: 10 additions & 3 deletions other-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@ function vipgoci_util_php_interpreter_get_version(
}

$php_cmd = sprintf(
'( %s %s 2>&1 )',
'%s %s',
escapeshellcmd( $php_path ),
escapeshellarg( '-v' )
);

$php_output = vipgoci_runtime_measure_shell_exec_with_retry(
$php_output_2 = '';
$php_result_code = -255;

$php_output = vipgoci_runtime_measure_exec_with_retry(
$php_cmd,
'php_cli'
array( 0 ),
$php_output_2,
$php_result_code,
'php_cli',
false
);

if ( null === $php_output ) {
Expand Down
Loading