예제 #1
0
 /**
  * Copies a file.
  *
  * This method only copies the file if the origin file is newer than the target file.
  *
  * By default, if the target already exists, it is not overridden.
  *
  * @param string $originFile The original filename
  * @param string $targetFile The target filename
  * @param bool   $override   Whether to override an existing file or not
  *
  * @throws FileNotFoundException When originFile doesn't exist
  *
  * @return exit code
  */
 public function copy($originFile, $targetFile, $override = false)
 {
     if (!$this->isFileExist($originFile)) {
         throw new FileNotFoundException(sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
     }
     $this->sshExec->exec(strtr('mkdir -p %targetDir% && cp -R %override% %originFile% %targetFile%', ['%originFile%' => $originFile, '%targetDir%' => dirname($targetFile), '%targetFile%' => $targetFile, '%override%' => $override ? '' : '-n']));
     if ($this->sshExec->getLastReturnStatus() !== 0) {
         !$this->logger ?: $this->logger->error(sprintf('Error copy %s to %s', $originFile, $targetFile));
     }
     return $this->sshExec->getLastReturnStatus();
 }
예제 #2
0
 /**
  * Return last return status of the last Unix command has been executed
  *
  * @return int
  */
 public function getLastReturnStatus()
 {
     return $this->sshExec->getLastReturnStatus();
 }