protected function _processFile($entry)
{
$pathName = $entry['path'] . '/' . $entry['name'];
switch (true) {
// file/directory removal task
case $entry['flags'] & self::FILE_ACTION_REMOVE:
if (!file_exists($pathName)) {
$this->_logInfo('File/folder to be removed does already not exist: :file', self::LOG_SUCCESS, array('file' => $pathName));
break;
}
if (is_dir($pathName)) {
$this->_recursivelyRemoveDirectory($pathName);
clearstatcache();
is_dir($pathName) ? $this->_logInfo('Removal of directory :directory', self::LOG_SUCCESS, array('directory' => $pathName)) : $this->_logInfo('Unable to remove the directory: :directory', self::LOG_ERROR, array('directory' => $pathName));
} else {
@unlink($pathName) ? $this->_logInfo('Removal of single file: :file', self::LOG_SUCCESS, array('file' => $pathName)) : $this->_logInfo('Unable to remove the file: :file', self::LOG_ERROR, array('file' => $pathName));
}
break;
// default case - file create/rewrite task
// default case - file create/rewrite task
case $entry['flags'] & self::FILE_ACTION_CREATE:
if (file_exists($pathName)) {
if (!$this->_forceMode) {
if ($entry['flags'] & self::FILE_FORMAT_TEXT) {
if (self::EMPTY_FILE_HASH != $entry['hash']) {
$content = @file_get_contents($pathName);
if (false === $content) {
$this->_logInfo('Unable to get contents of the file to calculate the checksum: :file. Skipped', self::LOG_ERROR, array('file' => $pathName));
return;
}
if (!$this->_checkTokenValidity($content, $entry['hash'])) {
$this->_logInfo('The checksum is not equal: :file (seems modified). Skipped', self::LOG_ERROR, array('file' => $pathName));
return;
}
}
}
}
}
$folder = dirname($pathName);
if (!is_dir($folder)) {
$umask = umask(0);
@mkdir($folder, self::PERMISSIONS_FULL_ACCESS, true);
umask($umask);
// because of mkdir with recursive param set to true does always return false
if (!is_dir($folder)) {
$this->_logInfo('Could not create a directory :directory to write the file: :file', self::LOG_ALERT, array('directory' => $folder, 'file' => $pathName));
}
}
is_writable($folder) ? $this->_writeFile($pathName, $entry['contents'], $entry['flags'] & self::FILE_FORMAT_BINARY) : $this->_logInfo('File is non-writable: :file. Skipped', self::LOG_ERROR, array('file' => $pathName));
}
}