Skip to content

Commit

Permalink
Added missing 'quiet' verbosity checks for warnings. Also, now fails if
Browse files Browse the repository at this point in the history
settings.txt could not be written.
  • Loading branch information
amekkawi committed Aug 2, 2012
1 parent a13b220 commit d904ef3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
22 changes: 17 additions & 5 deletions scripts/inc/process.class.php
Expand Up @@ -26,7 +26,8 @@
define('PROCESS_FAIL_INVALID_CHARACTERS', 6);
define('PROCESS_FAIL_UNEXPECTED_HEADER', 7);
define('PROCESS_FAIL_REPORTDIR_PARENT', 8);
define('PROCESS_FAIL_UNSUPPORTED_LIST_VERSION', 9);
define('PROCESS_FAIL_UNSUPPORTED_LIST_VERSION', 9);
define('PROCESS_FAIL_SETTINGS_WRITEFAIL', 10);

// Informational Codes.
define('PROCESS_INFO_PROCESSING_FILELIST', 0);
Expand Down Expand Up @@ -268,7 +269,10 @@ function _readLines() {

$this->_checkDirStack();
$this->_saveDirTree();
$this->_saveSettings();

if (!$this->_saveSettings()) {
return PROCESS_FAIL_SETTINGS_WRITEFAIL;
}

if ($this->_verboseLevel >= PROCESS_VERBOSE_NORMAL) {
if ($this->_bytesReadMax < $this->_bytesRead) $this->_bytesReadMax = null;
Expand Down Expand Up @@ -489,27 +493,31 @@ function _validateLine($line, $lineNum) {
$ret = FALSE;

if (strlen($line) > $this->_maxLineLength) {
if ($this->_verboseLevel > PROCESS_VERBOSE_QUIET)
$this->_raiseEvent(PROCESS_WARN_TOOLONG, $lineNum, $line);

array_push($this->_errors, array('invalidline', 'maxlinelength', $line));
}

// Validate the line up to the path column.
elseif (!preg_match($this->_lineRegEx, $line)) {
if ($this->_verboseLevel > PROCESS_VERBOSE_QUIET)
$this->_raiseEvent(PROCESS_WARN_BADMATCH, $lineNum, $line);

array_push($this->_errors, array('invalidline', 'regex', $line));
}

// Split the line and validate its length.
elseif (count($split = explode($this->_delim, $line, $this->_colCount)) != $this->_colCount) {
if ($this->_verboseLevel > PROCESS_VERBOSE_QUIET)
$this->_raiseEvent(PROCESS_WARN_COLCOUNT, $lineNum, $line);

array_push($this->_errors, array('invalidline', 'columncount', $split));
}

// Make sure the path is at least one character long.
elseif (strlen($split[$this->_col_path]) == 0) {
if ($this->_verboseLevel > PROCESS_VERBOSE_QUIET)
$this->_raiseEvent(PROCESS_WARN_EMPTYPATH, $lineNum, $line);

array_push($this->_errors, array('invalidline', 'column', 'path', $this->_col_path, $split));
Expand Down Expand Up @@ -630,7 +638,8 @@ function _checkDirStack($dirname = NULL) {

// Save the directory data.
if (($bytes = file_put_contents($this->_reportDir . DIRECTORY_SEPARATOR . md5($path) . $this->_suffix, json_encode($pop))) === FALSE) {
$this->_raiseEvent(PROCESS_WARN_WRITEFAIL, $this->_reportDir . DIRECTORY_SEPARATOR . md5($path), $path);
if ($this->_verboseLevel > PROCESS_VERBOSE_QUIET)
$this->_raiseEvent(PROCESS_WARN_WRITEFAIL, $this->_reportDir . DIRECTORY_SEPARATOR . md5($path), $path);
array_push($errors, array('writefail', $path, md5($path)));
}

Expand All @@ -650,7 +659,8 @@ function _saveDirTree() {

// Save the directory list.
if (($bytes = file_put_contents($this->_reportDir . DIRECTORY_SEPARATOR . 'directories' . $this->_suffix, json_encode($this->_dirLookup))) === FALSE) {
$this->_raiseEvent(PROCESS_WARN_WRITEFAIL, $this->_reportDir . DIRECTORY_SEPARATOR . 'directories');
if ($this->_verboseLevel > PROCESS_VERBOSE_QUIET)
$this->_raiseEvent(PROCESS_WARN_WRITEFAIL, $this->_reportDir . DIRECTORY_SEPARATOR . 'directories');
array_push($this->_errors, array('writefail', 'directories', 'directories'));
}

Expand Down Expand Up @@ -683,11 +693,13 @@ function _saveSettings() {

// Save the settings file.
if (($bytes = file_put_contents($this->_reportDir . DIRECTORY_SEPARATOR . 'settings' . $this->_suffix, json_encode($settings))) === FALSE) {
$this->_raiseEvent(PROCESS_WARN_WRITEFAIL, $this->_reportDir . DIRECTORY_SEPARATOR . 'settings');
return false;
}

$this->_bytesWritten += $bytes;
$this->_filesWritten++;

return true;
}

function _processDirectory($path, $basename) {
Expand Down
9 changes: 7 additions & 2 deletions scripts/process.php
Expand Up @@ -354,7 +354,7 @@ function EventHandler() {

$infoPrefix = ' ';
$warnPrefix = '> ';

switch ($eventCode) {
case PROCESS_INFO_PROCESSING_FILELIST:
echo $infoPrefix . "Processing filelist...\n";
Expand Down Expand Up @@ -422,8 +422,10 @@ function EventHandler() {
$processor->setEventCallback('EventHandler');

$ret = $processor->run();

$processor->dumpProfiles();
if ($ret != PROCESS_OK) {

if ($ret != PROCESS_OK && $processor->getVerboseLevel() > PROCESS_VERBOSE_QUIET) {
$details = $processor->getFailDetails();

switch ($ret) {
Expand Down Expand Up @@ -451,6 +453,9 @@ function EventHandler() {
case PROCESS_FAIL_UNSUPPORTED_LIST_VERSION:
echo "FAIL: <filelist> uses a version that does script does not support:\n" . $processor->getFailLine() . "\n";
break;
case PROCESS_FAIL_SETTINGS_WRITEFAIL:
echo "FAIL: Failed to write settings file.\n";
break;
}
}

Expand Down

0 comments on commit d904ef3

Please sign in to comment.