public function testCompressFolder() { $files = array('releases-noNewPatch.xml', 'releases-patchsOnly.xml', 'releases.xml', 'folder/', 'folder/emptyFile', 'emptyFolder/'); $dest = dirname(__FILE__) . '/backup/test.zip'; $src = dirname(__FILE__) . '/sample'; taoUpdate_helpers_Zip::compressFolder($src, $dest); $this->assertTrue(is_file($dest)); $zip = new ZipArchive(); $zip->open($dest); foreach ($files as $file) { $this->assertFalse($zip->locateName($file) === false, $file . ' not found'); } $this->assertFalse($zip->locateName('.svn')); helpers_File::remove($dest); $dest = dirname(__FILE__) . '/backup/test2.zip'; taoUpdate_helpers_Zip::compressFolder($src, $dest, true); $files = array('sample/releases-noNewPatch.xml', 'sample/releases-patchsOnly.xml', 'sample/releases.xml', 'sample/folder/', 'sample/folder/emptyFile', 'sample/emptyFolder/'); $this->assertTrue(is_file($dest)); $zip = new ZipArchive(); $zip->open($dest); for ($i = 0; $i < $zip->numFiles; $i++) { $stat = $zip->statIndex($i); //cehck no .svn added in zip $this->assertFalse(strpos($stat['name'], '.svn') > 0); } foreach ($files as $file) { $this->assertFalse($zip->locateName($file) === false); } helpers_File::remove($dest); }
public function tearDown() { if (!is_null($this->fileSource)) { $this->fileSource->delete(); } else { throw new common_Exception('should not be null, something wrong happen during test'); } helpers_File::remove($this->fsPath); }
public function tearDown() { parent::tearDown(); helpers_File::remove($this->getBasePath()); //unregister all $ids = array_keys(array_diff_key($this->getClientLibRegistryMap(), $this->initialMapping)); foreach ($ids as $id) { ClientLibRegistry::getRegistry()->remove($id); } }
protected function tearDown() { helpers_File::remove($this->directory); if ($this->repository != null) { $directory = $this->repository->getPath(); $this->repository->delete(); parent::tearDown(); } else { throw new common_Exception('Repository should never be null'); } }
/** * * @access * * @author "Lionel Lecaque, <*****@*****.**>" * @throws taoUpdate_models_classes_UpdateException * @return string */ public function createDeployFolder() { $path = ROOT_PATH . self::DEPLOY_FOLDER; if (is_dir($path)) { common_Logger::i('Folder already exist remove it ' . $path); helpers_File::remove($path); } if (!mkdir($path, 0755, true)) { throw new taoUpdate_models_classes_UpdateException('fail to create deploy folder'); } return $path; }
public function testRemoveFile() { $basedir = $this->mkdir(sys_get_temp_dir()); $this->assertTrue(is_dir($basedir)); $file01 = tempnam($basedir, 'testdir'); $file02 = tempnam($basedir, 'testdir'); $subDir1 = $this->mkdir($basedir); $subDir2 = $this->mkdir($basedir); $file21 = tempnam($subDir2, 'testdir'); $subDir21 = $this->mkdir($subDir2); $file211 = tempnam($subDir21, 'testdir'); $subDir22 = $this->mkdir($subDir2); $this->assertTrue(helpers_File::remove($basedir)); $this->assertFalse(is_dir($basedir)); }
/** * * @access * @author "Lionel Lecaque, <*****@*****.**>" * @param unknown $folder * @throws taoUpdate_models_classes_UpdateException */ public function storeDatabase($folder) { $dbBackupHelper = new taoUpdate_helpers_DbBackup(); $fileContent = $dbBackupHelper->backup(); $filepath = $folder . DIRECTORY_SEPARATOR . self::DB_BACKUP_FILE_PREFFIX . TAO_VERSION . self::DB_BACKUP_FILE_SUFFIX; if (!file_put_contents($filepath, $fileContent)) { throw new taoUpdate_models_classes_UpdateException('fail to create SQL file'); } if (is_file($filepath)) { taoUpdate_helpers_Zip::compressFile($filepath, $filepath . '.zip'); if (is_file($filepath . '.zip')) { helpers_File::remove($filepath); } } }
/** * @author "Sam Sipasseuth, <*****@*****.**>" */ protected function clear() { if (file_exists($this->file)) { helpers_File::remove($this->file); } if (file_exists($this->counterFile)) { helpers_File::remove($this->counterFile); } if (file_exists($this->sentFolder)) { helpers_File::remove($this->sentFolder); } }
/** * Short description of method delete * * @access public * @author Joel Bout, <*****@*****.**> * @param File resource * @param string path * @return boolean * @see core_kernel_versioning_File::delete() */ public function delete(core_kernel_file_File $resource, $path) { $returnValue = (bool) false; common_Logger::i(__FUNCTION__ . ' called on local directory', 'LOCALVCS'); $returnValue = helpers_File::remove($path); return (bool) $returnValue; }
public function tearDown() { helpers_File::remove($this->folder); }
public function testDelployRelease() { $release = '10.10.88'; $path = $this->service->downloadRelease($release); $result = $this->service->deploy($release); $this->assertTrue(is_dir($result . 'TAO_10.10.88_build')); helpers_File::remove($path); }
/** * Remove a file. If the recursive parameter is set to true, the target file * can be a directory that contains data. * * @author Lionel Lecaque, <*****@*****.**> * @param string path The path to the file you want to remove. * @param boolean recursive (optional, default is false) Remove file content recursively (only if the path points to a directory). * @return boolean Return true if the file is correctly removed, false otherwise. */ public static function remove($path, $recursive = false) { $returnValue = (bool) false; if ($recursive) { $returnValue = helpers_File::remove($path); } elseif (is_file($path)) { $returnValue = @unlink($path); } // else fail silently return (bool) $returnValue; }
/** * @access * @author "Lionel Lecaque, <*****@*****.**>" */ public function testDownloadRelease() { $this->service->setReleaseManifestUrl(BASE_URL . '/test/sample/releases10.xml'); $updateSites = $this->service->getUpdateSites(); //replace fake url with the one that will work for test case $updateSite = str_replace('$BASE_URL', BASE_URL, $updateSites['default']); $updateSites['default'] = $updateSite; $availableUpdates = $this->service->getAvailableUpdates(); $releaseFile = $availableUpdates['10.10.99']['file']; $localFolder = dirname(__FILE__) . '/download/'; $tmpFolder = dirname(__FILE__) . '/tmp/'; try { $dlPath = $this->service->downloadRelease($releaseFile, $updateSites['default'], $localFolder); $this->assertTrue(is_file($dlPath)); $zip = new ZipArchive(); $zip->open($dlPath); $zip->extractTo($tmpFolder); $this->assertFalse($zip->locateName('TAO_10.10.99_build/version') === false); $this->assertTrue(is_file($tmpFolder . 'TAO_10.10.99_build/version')); $versionFileContent = @file_get_contents($tmpFolder . 'TAO_10.10.99_build/version'); $this->assertEqual($versionFileContent, '10.10.99'); } catch (taoUpdate_models_classes_UpdateException $e) { $this->fail('Exception raised ' . $e->getMessage()); } try { $dlPath = $this->service->downloadRelease('10.10.98', $updateSites['default'], $localFolder); } catch (Exception $e) { $this->assertIsA($e, 'taoUpdate_models_classes_UpdateException'); } try { $dlPath = $this->service->downloadRelease('10.10.99', 'http://localhost/badlnk', $localFolder); } catch (Exception $e) { $this->assertIsA($e, 'taoUpdate_models_classes_UpdateException'); } try { helpers_File::remove($localFolder . $releaseFile); helpers_File::remove($tmpFolder . 'TAO_10.10.99_build/version'); } catch (common_Exception $e) { $this->fail('Exception raised ' . $e->getMessage()); } }
/** * * @access public * @author "Lionel Lecaque, <*****@*****.**>" * @param string $releaseName * @param string $updateSite * @param string $localFolder * @throws taoUpdate_models_classes_UpdateException * @return string */ public function downloadRelease($releaseFileName, $updateSite, $localFolder) { //file is only 18M but default php value is 128M but some packaging (ie MAMP) are set to 8MB if ($updateSite == 'local') { throw new taoUpdate_models_classes_LocalReleaseException('Update site is local package, no download available'); } $curl = curl_init(); $distantRelease = $updateSite . $releaseFileName; if (!($fp = @fopen($localFolder . $releaseFileName, 'w'))) { throw new taoUpdate_models_classes_UpdateException('Fail to open stream check permission on ' . $localFolder . $releaseFileName); } curl_setopt($curl, CURLOPT_URL, $distantRelease); curl_setopt($curl, CURLOPT_FILE, $fp); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); try { ini_set('memory_limit', '128M'); $contents = curl_exec($curl); } catch (Exception $e) { throw new taoUpdate_models_classes_UpdateException('Exception catched ' . $e->getMessage()); } $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ($httpCode == 200) { fwrite($fp, $contents); } else { if (is_file($localFolder . $releaseFileName)) { helpers_File::remove($localFolder . $releaseFileName); } throw new taoUpdate_models_classes_ReleaseDownloadException($httpCode, $releaseFileName, $updateSite); } return $localFolder . $releaseFileName; }