/**
  * This test is our selection test that compared the file with the destfile.
  *
  * @param PhingFile $srcfile the source file
  * @param PhingFile $destfile the destination file
  * @return bool true if the files are different
  *
  * @throws BuildException
  */
 protected function selectionTest(PhingFile $srcfile, PhingFile $destfile)
 {
     try {
         // if either of them is missing, they are different
         if ($srcfile->exists() !== $destfile->exists()) {
             return true;
         }
         if ($srcfile->length() !== $destfile->length()) {
             // different size => different files
             return true;
         }
         if (!$this->ignoreFileTimes) {
             // different dates => different files
             if ($destfile->lastModified() !== $srcfile->lastModified()) {
                 return true;
             }
         }
         if (!$this->ignoreContents) {
             //here do a bulk comparison
             $fu = new FileUtils();
             return !$fu->contentEquals($srcfile, $destfile);
         }
     } catch (IOException $e) {
         throw new BuildException("while comparing {$srcfile} and {$destfile}", $e);
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * The main entry point method.
  */
 public function main()
 {
     $project = $this->getProject();
     require_once 'Net/FTP.php';
     $ftp = new Net_FTP($this->host, $this->port);
     if ($this->ssl) {
         $ret = $ftp->setSsl();
         if (@PEAR::isError($ret)) {
             throw new BuildException('SSL connection not supported by php' . ': ' . $ret->getMessage());
         } else {
             $this->log('Use SSL connection', $this->logLevel);
         }
     }
     $ret = $ftp->connect();
     if (@PEAR::isError($ret)) {
         throw new BuildException('Could not connect to FTP server ' . $this->host . ' on port ' . $this->port . ': ' . $ret->getMessage());
     } else {
         $this->log('Connected to FTP server ' . $this->host . ' on port ' . $this->port, $this->logLevel);
     }
     $ret = $ftp->login($this->username, $this->password);
     if (@PEAR::isError($ret)) {
         throw new BuildException('Could not login to FTP server ' . $this->host . ' on port ' . $this->port . ' with username ' . $this->username . ': ' . $ret->getMessage());
     } else {
         $this->log('Logged in to FTP server with username ' . $this->username, $this->logLevel);
     }
     if ($this->passive) {
         $this->log('Setting passive mode', $this->logLevel);
         $ret = $ftp->setPassive();
         if (@PEAR::isError($ret)) {
             $ftp->disconnect();
             throw new BuildException('Could not set PASSIVE mode: ' . $ret->getMessage());
         }
     }
     // append '/' to the end if necessary
     $dir = substr($this->dir, -1) == '/' ? $this->dir : $this->dir . '/';
     if ($this->clearFirst) {
         // TODO change to a loop through all files and directories within current directory
         $this->log('Clearing directory ' . $dir, $this->logLevel);
         $ftp->rm($dir, true);
     }
     // Create directory just in case
     $ret = $ftp->mkdir($dir, true);
     if (@PEAR::isError($ret)) {
         $ftp->disconnect();
         throw new BuildException('Could not create directory ' . $dir . ': ' . $ret->getMessage());
     }
     $ret = $ftp->cd($dir);
     if (@PEAR::isError($ret)) {
         $ftp->disconnect();
         throw new BuildException('Could not change to directory ' . $dir . ': ' . $ret->getMessage());
     } else {
         $this->log('Changed directory ' . $dir, $this->logLevel);
     }
     $fs = FileSystem::getFileSystem();
     $convert = $fs->getSeparator() == '\\';
     foreach ($this->filesets as $fs) {
         // Array for holding directory content informations
         $remoteFileInformations = array();
         $ds = $fs->getDirectoryScanner($project);
         $fromDir = $fs->getDir($project);
         $srcFiles = $ds->getIncludedFiles();
         $srcDirs = $ds->getIncludedDirectories();
         foreach ($srcDirs as $dirname) {
             if ($convert) {
                 $dirname = str_replace('\\', '/', $dirname);
             }
             // Read directory informations, if file exists, else create the directory
             if (!$this->_directoryInformations($ftp, $remoteFileInformations, $dirname)) {
                 $this->log('Will create directory ' . $dirname, $this->logLevel);
                 $ret = $ftp->mkdir($dirname, true);
                 if (@PEAR::isError($ret)) {
                     $ftp->disconnect();
                     throw new BuildException('Could not create directory ' . $dirname . ': ' . $ret->getMessage());
                 }
             }
             if ($this->dirmode) {
                 if ($this->dirmode == 'inherit') {
                     $mode = fileperms($dirname);
                 } else {
                     $mode = $this->dirmode;
                 }
                 // Because Net_FTP does not support a chmod call we call ftp_chmod directly
                 ftp_chmod($ftp->_handle, $mode, $dirname);
             }
         }
         foreach ($srcFiles as $filename) {
             $file = new PhingFile($fromDir->getAbsolutePath(), $filename);
             if ($convert) {
                 $filename = str_replace('\\', '/', $filename);
             }
             $local_filemtime = filemtime($file->getCanonicalPath());
             if (isset($remoteFileInformations[$filename]['stamp'])) {
                 $remoteFileModificationTime = $remoteFileInformations[$filename]['stamp'];
             } else {
                 $remoteFileModificationTime = 0;
             }
             if (!$this->depends || $local_filemtime > $remoteFileModificationTime) {
                 if ($this->skipOnSameSize === true && $file->length() === $ftp->size($filename)) {
                     $this->log('Skipped ' . $file->getCanonicalPath(), $this->logLevel);
                     continue;
                 }
                 $this->log('Will copy ' . $file->getCanonicalPath() . ' to ' . $filename, $this->logLevel);
                 $ret = $ftp->put($file->getCanonicalPath(), $filename, true, $this->mode);
                 if (@PEAR::isError($ret)) {
                     $ftp->disconnect();
                     throw new BuildException('Could not deploy file ' . $filename . ': ' . $ret->getMessage());
                 }
             }
             if ($this->filemode) {
                 if ($this->filemode == 'inherit') {
                     $mode = fileperms($filename);
                 } else {
                     $mode = $this->filemode;
                 }
                 // Because Net_FTP does not support a chmod call we call ftp_chmod directly
                 ftp_chmod($ftp->_handle, $mode, $filename);
             }
         }
     }
     $ftp->disconnect();
     $this->log('Disconnected from FTP server', $this->logLevel);
 }
 /**
  * The heart of the matter. This is where the selector gets to decide
  * on the inclusion of a file in a particular fileset.
  *
  * {@inheritdoc}
  *
  * @param PhingFile $basedir  A PhingFile object for the base directory
  * @param string    $filename The name of the file to check
  * @param PhingFile $file     A PhingFile object for this filename
  *
  * @return bool whether the file should be selected or not
  */
 public function isSelected(PhingFile $basedir, $filename, PhingFile $file)
 {
     $this->validate();
     // Directory size never selected for
     if ($file->isDirectory()) {
         return true;
     }
     if ($this->cmp === 0) {
         return $file->length() < $this->sizelimit;
     } elseif ($this->cmp === 1) {
         return $file->length() > $this->sizelimit;
     } else {
         return $file->length() === $this->sizelimit;
     }
 }
Exemplo n.º 4
0
 /**
  * Validates attributes coming in from XML.
  *
  * @param  void
  * @return void
  * @throws BuildException
  * @access protected
  */
 protected function _validateAttributes()
 {
     if (null === $this->_resource) {
         throw new BuildException('You must specify a file to load.');
     }
     if (null === $this->_destFile && empty($this->_filesets)) {
         throw new BuildException('Specify at least one source - a file or a fileset.');
     }
     if (null !== $this->_destFile && !empty($this->_filesets)) {
         throw new BuildException('Only one of destination file and fileset may be set.');
     }
     if ($this->_resource->exists()) {
         if ($this->_resource->isDirectory()) {
             throw new BuildException('Cannot load a directory as a file.');
         }
         try {
             if (0 === $this->_resource->length()) {
                 $this->log('The file ' . $this->_resource . ' is empty!', $this->getVerbose());
             }
         } catch (IOException $e) {
             throw new BuildException($e->getMessage(), $e->getLocation());
         }
     } else {
         throw new BuildException($this->_resource . ' does not exist!');
     }
 }