Example #1
0
 public function testRecursive()
 {
     $dir = \OC::$SERVERROOT . '/tests/data';
     $this->instance = $this->getNew();
     $this->instance->addRecursive('/dir', $dir);
     $this->assertTrue($this->instance->fileExists('/dir/lorem.txt'));
     $this->assertTrue($this->instance->fileExists('/dir/data.zip'));
     $this->assertTrue($this->instance->fileExists('/dir/data.tar.gz'));
 }
Example #2
0
 /**
  * @param array $data
  * @return array
  * @throws \Exception
  */
 public static function downloadApp($data = array())
 {
     $l = \OC::$server->getL10N('lib');
     if (!isset($data['source'])) {
         throw new \Exception($l->t("No source specified when installing app"));
     }
     //download the file if necessary
     if ($data['source'] == 'http') {
         $pathInfo = pathinfo($data['href']);
         $extension = isset($pathInfo['extension']) ? '.' . $pathInfo['extension'] : '';
         $path = \OC::$server->getTempManager()->getTemporaryFile($extension);
         if (!isset($data['href'])) {
             throw new \Exception($l->t("No href specified when installing app from http"));
         }
         $client = \OC::$server->getHTTPClientService()->newClient();
         $client->get($data['href'], ['save_to' => $path]);
     } else {
         if (!isset($data['path'])) {
             throw new \Exception($l->t("No path specified when installing app from local file"));
         }
         $path = $data['path'];
     }
     //detect the archive type
     $mime = \OC::$server->getMimeTypeDetector()->detect($path);
     if ($mime !== 'application/zip' && $mime !== 'application/x-gzip' && $mime !== 'application/x-bzip2') {
         throw new \Exception($l->t("Archives of type %s are not supported", array($mime)));
     }
     //extract the archive in a temporary folder
     $extractDir = \OC::$server->getTempManager()->getTemporaryFolder();
     OC_Helper::rmdirr($extractDir);
     mkdir($extractDir);
     if ($archive = \OC\Archive\Archive::open($path)) {
         $archive->extract($extractDir);
     } else {
         OC_Helper::rmdirr($extractDir);
         if ($data['source'] == 'http') {
             unlink($path);
         }
         throw new \Exception($l->t("Failed to open archive when installing app"));
     }
     return array($extractDir, $path);
 }