function downloadFile($url, $installFile, $archivedFile) { $tmpFile = $installFile . '.tmp'; if (!file_exists($archivedFile) || filesize($archivedFile) == 0) { if (file_exists($installFile)) { unlink($archivedFile); } if (file_exists($tmpFile)) { unlink($tmpFile); } $ch = curl_init($url); $fp = fopen($tmpFile, "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); rename($tmpFile, $archivedFile); } if (file_exists($installFile)) { unlink($installFile); } link($archivedFile, $installFile); kdebug('link(' . $archivedFile . ', ' . $installFile . ')'); }
public static function setUpBeforeClass() { if ('\\' === DIRECTORY_SEPARATOR) { self::$linkOnWindows = true; $originFile = tempnam(sys_get_temp_dir(), 'li'); $targetFile = tempnam(sys_get_temp_dir(), 'li'); if (true !== @link($originFile, $targetFile)) { $report = error_get_last(); if (is_array($report) && false !== strpos($report['message'], 'error code(1314)')) { self::$linkOnWindows = false; } } else { @unlink($targetFile); } self::$symlinkOnWindows = true; $originDir = tempnam(sys_get_temp_dir(), 'sl'); $targetDir = tempnam(sys_get_temp_dir(), 'sl'); if (true !== @symlink($originDir, $targetDir)) { $report = error_get_last(); if (is_array($report) && false !== strpos($report['message'], 'error code(1314)')) { self::$symlinkOnWindows = false; } } else { @unlink($targetDir); } } }
function build() { $webappFile = null; $tomcatDir = "/var/lib/tomcat6/webapps"; if (!is_dir($tomcatDir)) { echo "Starting......: " . date("H:i:s") . " C.A.S server failed `{$tomcatDir}` no such directory...\n"; return; } $unix = new unix(); $dirfiles = $unix->DirFiles("/usr/share/cas-server/modules", "cas-server-webapp-.*?\\.war"); echo "Starting......: " . date("H:i:s") . " C.A.S server checking libraries...\n"; echo "Starting......: " . date("H:i:s") . " C.A.S server TomCat webapps `{$tomcatDir}`\n"; while (list($num, $line) = each($dirfiles)) { $webappFile = "/usr/share/cas-server/modules/{$num}"; } if ($webappFile == null) { echo "Starting......: " . date("H:i:s") . " C.A.S server failed to retrive cas-server-webapp war file\n"; return; } if (is_file("{$tomcatDir}/cas.war")) { @unlink("{$tomcatDir}/cas.war"); } echo "Starting......: " . date("H:i:s") . " C.A.S server installing {$webappFile} into {$tomcatDir}..\n"; @link($webappFile, "{$tomcatDir}/cas.war"); writesettings(); maven2(); tomcat_config(); log4jxml(); if (is_file("/etc/init.d/tomcat6")) { echo "Starting......: " . date("H:i:s") . " C.A.S server restarting tomcat server...\n"; shell_exec("/etc/init.d/tomcat6 restart >/dev/null 2>&1"); } WEB_INF_deployerConfigContext(); log4jxml(); }
/** * @param string $realFrom * @param string $realTo * @param string $type * * @throws Exception */ function systemlink_createLink($realFrom, $realTo, $type = 'symlink') { if (IS_WINDOWS) { // Windows doesn't play nice with paths containing UNIX path separators $realTo = TranslateWinPath($realTo); $realFrom = TranslateWinPath($realFrom); // Windows doesn't play nice with relative paths in symlinks $realFrom = realpath($realFrom); } if (is_file($realTo) || is_dir($realTo) || is_link($realTo) || file_exists($realTo)) { if (IS_WINDOWS && is_dir($realTo)) { // Windows can't unlink() directory symlinks; it needs rmdir() to be used instead $res = @rmdir($realTo); } else { $res = @unlink($realTo); } if (!$res) { echo "FAILED UNLINK : {$realTo}\n"; } } if ($type == 'symlink') { $res = @symlink($realFrom, $realTo); } elseif ($type == 'link') { $res = @link($realFrom, $realTo); } if (!$res) { if ($type == 'symlink') { echo "FAILED SYMLINK : {$realTo}\n"; } elseif ($type == 'link') { echo "FAILED LINK : {$realTo}\n"; } } }
protected function _link_file($path, $target, $link_directory) { $this->_check_dir($link_directory); if (!file_exists($link_directory . '/' . $target) && !link(dirname(__FILE__) . '/' . $path . '/' . $target, $link_directory . '/' . $target)) { $this->fail("Failed to create link " . $link_directory . '/' . $target); } }
public static function link($from, $to) { if (is_dir($from) && PHP_OS == "WINNT") { exec("mklink /J {$to} {$from}"); return; } link($from, $to); }
function cross_symlink($sourcePath, $targetPath) { if (PHP_OS == "WINNT") { return link($sourcePath, $targetPath); } else { return symlink($sourcePath, $targetPath); } }
public static function link($source, $dest) { if (self::isProduction()) { return link($source, $dest); } else { return copy($source, $dest); } }
function hardlink_file($from, $to) { if (defined('AKEEBA_RELINK_WINDOWS')) { $cmd = 'mklink /H "' . $to . '" "' . $from . '"'; exec($cmd); } else { @link($from, $to); } }
/** * @param string $original * @param string $alias * @return bool * @throws Exceptions\FileSystemException */ public static function hardSymLink($original, $alias) { if (!file_exists($original)) { throw new \Sonrisa\Component\FileSystem\Exceptions\FileSystemException("Cannot link {$original} because it does not exist."); } if (file_exists($alias)) { throw new \Sonrisa\Component\FileSystem\Exceptions\FileSystemException("Cannot create link {$alias} because a file, directory or link with this name already exists."); } return link($original, $alias); }
function duplicate($dir, $writable, $files, $verb = false) { $base = '../' . $dir; $id = preg_replace('/^\\D+/', '', $dir); if (!empty($id)) { $id = intval($id); } if (!is_dir($base)) { mkdir($base); } $base .= '/'; foreach (find_file() as $name) { if ($verb) { echo " dup: {$name}\n"; } if (is_dir($name)) { if (!@mkdir($base . $name)) { echo "mkdir error: {$name}\n"; } } elseif (!@link($name, $base . $name)) { echo "link error: {$name}\n"; } } foreach ($writable as $i) { $f = $base . $i; if ($verb) { echo " writable: {$f}\n"; } if (is_dir($f)) { chmod($f, 0777); } else { chmod($f, 0666); } } foreach ($files as $file => $dest) { $newfile = $base . preg_replace('/{prefix}/', $dir, $dest); $body = file_get_contents($file); if (preg_match('/\\.sql$/', $file)) { if ($verb) { echo " {$file} -> {$newfile}\n"; } $body = preg_replace('/\\s' . preg_quote(ORIGIN_NAME) . '([\\s_])/', " {$dir}\$1", $body); } elseif (preg_match('/\\.html$/', $file)) { $body = preg_replace('/' . preg_quote(ORIGIN_NAME) . '_/', $dir . "_", $body); if ($verb) { echo " {$file} -> {$newfile}\n"; } } file_put_contents($newfile, $body); } }
public function reload($rootPath = null) { global $neardBs, $neardConfig, $neardLang; $this->name = $neardLang->getValue(Lang::FILEZILLA); $this->version = $neardConfig->getRaw(self::ROOT_CFG_VERSION); $this->launchStartup = $neardConfig->getRaw(self::ROOT_CFG_LAUNCH_STARTUP) == Config::ENABLED; $this->rootPath = $rootPath == null ? $this->rootPath : $rootPath; $this->currentPath = $this->rootPath . '/filezilla' . $this->version; $this->neardConf = $this->currentPath . '/neard.conf'; $this->logsPath = $this->currentPath . '/Logs'; $this->log = $neardBs->getLogsPath() . '/filezilla.log'; if (!is_dir($this->currentPath)) { Util::logError(sprintf($neardLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath)); } if (!is_file($this->neardConf)) { Util::logError(sprintf($neardLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->neardConf)); } // Create log hard link $log = $this->logsPath . '/FileZilla Server.log'; if (!file_exists($this->log) && file_exists($log)) { @link($log, $this->log); } $this->neardConfRaw = parse_ini_file($this->neardConf); if ($this->neardConfRaw !== false) { $this->exe = $this->currentPath . '/' . $this->neardConfRaw[self::LOCAL_CFG_EXE]; $this->conf = $this->currentPath . '/' . $this->neardConfRaw[self::LOCAL_CFG_CONF]; $this->port = $this->neardConfRaw[self::LOCAL_CFG_PORT]; $this->sslPort = $this->neardConfRaw[self::LOCAL_CFG_SSL_PORT]; } if (!is_file($this->exe)) { Util::logError(sprintf($neardLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exe)); } if (!is_file($this->conf)) { Util::logError(sprintf($neardLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->conf)); } if (!is_numeric($this->port) || $this->port <= 0) { Util::logError(sprintf($neardLang->getValue(Lang::ERROR_INVALID_PARAMETER), self::LOCAL_CFG_PORT, $this->port)); } if (!is_numeric($this->sslPort) || $this->sslPort <= 0) { Util::logError(sprintf($neardLang->getValue(Lang::ERROR_INVALID_PARAMETER), self::LOCAL_CFG_SSL_PORT, $this->sslPort)); } $this->service = new Win32Service(self::SERVICE_NAME); $this->service->setDisplayName(APP_TITLE . ' ' . $this->getName() . ' ' . $this->version); $this->service->setBinPath($this->exe); $this->service->setStartType(Win32Service::SERVICE_DEMAND_START); $this->service->setErrorControl(Win32Service::SERVER_ERROR_NORMAL); }
public function run($overwrite = true) { foreach ($this->_links as $key => $link) { if (file_exists($link['to'])) { if ($overwrite) { unlink($link['to']); link($link['fr'], $link['to']); $this->_links[$key]['message'] = 'sucess (removed old file)'; } else { $this->_links[$key]['message'] = 'file exists'; } } else { link($link['fr'], $link['to']); $this->_links[$key]['message'] = 'success'; } } }
function hardlink_file($from, $to) { if (file_exists($to)) { if (defined('AKEEBA_RELINK_WINDOWS')) { $cmd = 'del /f /q "' . $to . '"'; } else { $cmd = 'rm -f "' . $to . '"'; } exec($cmd); } if (defined('AKEEBA_RELINK_WINDOWS')) { $cmd = 'mklink /H "' . $to . '" "' . $from . '"'; exec($cmd); } else { @link($from, $to); } }
public function testDelete() { // Initialization $_SESSION['id'] = 1; $phpunit = array('isTest' => true); include dirname(__FILE__) . '/../index.php'; //Test delete photo from one album $db->query('INSERT INTO images (ownerId, name, filename, extension, created, description) VALUES ("1", "", "flamingo","jpg", CURRENT_TIMESTAMP(),"")'); $newImageId = mysql_insert_id(); $db->query('INSERT INTO imagesToAlbums (albumId, imageId, positionInAlbum) VALUES ("1", "' . $newImageId . '", "1")'); $target = dirname(__FILE__) . '/data/uploadTest/flamingos.jpg'; // Ceci est le fichier qui existe actuellement $link = dirname(__FILE__) . '/../data/images/' . $newImageId . '.jpg'; // Ceci sera le nom du fichier que vous voulez lier @link($target, $link); $_GET = array('id' => $newImageId); $_POST = array('Delete' => true, 'album' => array(1)); include dirname(__FILE__) . '/../pages/view/photoDelete.php'; $results = mysql_num_rows($db->query('SELECT * FROM images')); $this->assertEquals('1', $results); //Test delete photo from one album but existing in two $db->query('INSERT INTO images (ownerId, name, filename, extension, created, description) VALUES ("1", "", "flamingo","jpg", CURRENT_TIMESTAMP(),"")'); $newImageId = mysql_insert_id(); $db->query('INSERT INTO imagesToAlbums (albumId, imageId, positionInAlbum) VALUES ("1", "' . $newImageId . '", "1")'); $db->query('INSERT INTO imagesToAlbums (albumId, imageId, positionInAlbum) VALUES ("3", "' . $newImageId . '", "1")'); $target = dirname(__FILE__) . '/data/uploadTest/flamingos.jpg'; // Ceci est le fichier qui existe actuellement $link = dirname(__FILE__) . '/../data/images/' . $newImageId . '.jpg'; // Ceci sera le nom du fichier que vous voulez lier @link($target, $link); $_GET = array('id' => $newImageId); $_POST = array('Delete' => true, 'album' => array(1)); include dirname(__FILE__) . '/../pages/view/photoDelete.php'; $results = mysql_num_rows($db->query('SELECT * FROM images')); $this->assertEquals('2', $results); //Test delete photo from two album, photo in only two albums $db->query('INSERT INTO imagesToAlbums (albumId, imageId, positionInAlbum) VALUES ("1", "' . $newImageId . '", "1")'); $_GET = array('id' => $newImageId); $_POST = array('Delete' => true, 'album' => array(1, 3)); include dirname(__FILE__) . '/../pages/view/photoDelete.php'; $results = mysql_num_rows($db->query('SELECT * FROM images')); $this->assertEquals('1', $results); }
public function createLink($media_file, $media_id, $proto = '') { $this->user->checkHome(); preg_match("/([\\S\\s]+)\\.(" . $this->media_ext_str . ")\$/i", $media_file, $arr); $ext = $arr[2]; $from = KARAOKE_STORAGE_DIR . '/' . $media_file; $to = NFS_HOME_PATH . $this->user->getMac() . '/' . $media_id . '.' . $ext; if ($proto == 'http') { $link_result = @symlink($from, $to); } else { $link_result = @link($from, $to); } if (!$link_result) { throw new IOException('Could not create link ' . $from . ' to ' . $to . ' on ' . $this->storage_name); } if (!is_readable($to)) { throw new IOException('File ' . $to . ' is not readable on ' . $this->storage_name); } return true; }
protected function execute(InputInterface $input, OutputInterface $output) { $serverGlobal = $input->getOption('server-global'); if ($serverGlobal) { $_SERVER = json_decode($serverGlobal, true); } $this->requireFixtureFiles($input); $this->setIncludePathAsInTestBootstrap(); $host = Url::getHost(); if (empty($host)) { $host = 'localhost'; Url::setHost('localhost'); } $configDomainToSave = $input->getOption('save-config'); if (!empty($configDomainToSave)) { $pathToDomainConfig = PIWIK_INCLUDE_PATH . '/config/' . $host . '.config.ini.php'; if (!file_exists($pathToDomainConfig)) { link(PIWIK_INCLUDE_PATH . '/config/config.ini.php', $pathToDomainConfig); } } $fixture = $this->createFixture($input); $this->setupDatabaseOverrides($input, $fixture); // perform setup and/or teardown if ($input->getOption('teardown')) { $fixture->getTestEnvironment()->save(); $fixture->performTearDown(); } else { $fixture->performSetUp(); } if ($input->getOption('set-phantomjs-symlinks')) { $this->createSymbolicLinksForUITests(); } $this->writeSuccessMessage($output, array("Fixture successfully setup!")); $sqlDumpPath = $input->getOption('sqldump'); if ($sqlDumpPath) { $this->createSqlDump($sqlDumpPath, $output); } if (!empty($configDomainToSave)) { Config::getInstance()->forceSave(); } }
function test_link($linkedfile, $toLinkTo, $tounlink, $softlink) { if ($softlink == true) { symlink($toLinkTo, $linkedfile); $msg = "soft link"; } else { link($toLinkTo, $linkedfile); $msg = "hard link"; } echo "-- unlinking {$msg} {$tounlink} --\n"; $res = unlink($tounlink); if ($res === true) { if (file_exists($tounlink) === false) { echo "file unlinked\n"; } else { echo "FAILED: file not unlinked\n"; } } else { unlink($linkedfile); } }
function test_link($linkedDir, $toLinkTo, $tounlink, $softlink) { if ($softlink == true) { symlink($toLinkTo, $linkedDir); $msg = "soft link"; } else { link($toLinkTo, $linkedDir); $msg = "hard link"; } echo "-- unlinking {$msg} {$tounlink} --\n"; $res = unlink($tounlink); if ($res === true) { if (is_link($tounlink) === false) { echo "directory unlinked\n"; } else { echo "FAILED: directory not unlinked\n"; } } else { unlink($linkedDir); } }
public function combineAssets(\Twig_Environment $twig, $combinedresultName, array $assetPaths, array $attributes, $foreReload = false) { $this->registerWidgetTemplates($twig); if ($this->debug) { $assetManager = $this->assetManager; $assetPaths = array_map(function ($assetPath) use($assetManager) { if (@file_get_contents($assetPath)) { return $assetPath; } foreach ($assetManager->importFolders as $namespace => $importFolder) { if (file_exists($importFolder . $assetPath)) { $importFolderAccessible = strpos($importFolder, $assetManager->webroot) === 0; if ($importFolderAccessible) { $importPath = substr($importFolder, strlen($assetManager->webroot)); return $importPath; } // Symlink the otherwise inaccessible assets, and present their new path $namespacedLocation = $assetManager->webroot . 'vendor/' . $namespace . '/'; $namespacedPath = 'vendor/' . $namespace . '/'; if (!file_exists($namespacedLocation . $assetPath)) { if (!(file_exists($namespacedLocation) && is_dir($namespacedLocation))) { mkdir($namespacedLocation, 0777, true); } link($importFolder . $assetPath, $assetManager->webroot . 'vendor/' . $namespace . '/' . $assetPath); } return $namespacedPath . $assetPath; } } if (strpos($assetPath, $assetManager->exportPath) == false) { return $assetManager->exportPath . $assetPath; } return $assetPath; }, $assetPaths); return $twig->render('@assetwidgets/combineAssetsList.twig', ['attributes' => $attributes, 'jsPaths' => $assetPaths]); } else { $combinedresult = $this->assetManager->combineLibsFromPaths($assetPaths, $combinedresultName, $foreReload); return $twig->render('@assetwidgets/combineAssets.twig', ['attributes' => $attributes, 'jsPath' => $combinedresult]); } }
/** * Moves everything in Maildir/new/* to Maildir/cur/ * * @access private * @return */ private function moveNewToCur() { $newdirname = MAILDIR_BASE . "/" . $this->store . "/" . MAILDIR_SUBDIR . "/new"; $newdir = opendir($newdirname); while ($newentry = readdir($newdir)) { if ($newentry[0] == ".") { continue; } // link/unlink == move. This is the way to move the message according to cr.yp.to link($newdirname . "/" . $newentry, $this->getPath() . "/" . $newentry . ":2,"); unlink($newdirname . "/" . $newentry); } }
<?php /* Prototype: int fileperms ( string $filename ) * Description: Returns the group ID of the file, or FALSE in case of an error. */ /* Creating soft and hard links to a file and applying fileperms() on links */ $file_path = dirname(__FILE__); fclose(fopen($file_path . "/fileperms_variation1.tmp", "w")); echo "*** Testing fileperms() with links ***\n"; /* With symlink */ symlink($file_path . "/fileperms_variation1.tmp", $file_path . "/fileperms_variation1_symlink.tmp"); var_dump(fileperms($file_path . "/fileperms_variation1_symlink.tmp")); //expected true clearstatcache(); /* With hardlink */ link($file_path . "/fileperms_variation1.tmp", $file_path . "/fileperms_variation1_link.tmp"); var_dump(fileperms($file_path . "/fileperms_variation1_link.tmp")); // expected: true clearstatcache(); echo "\n*** Done ***"; $file_path = dirname(__FILE__); unlink($file_path . "/fileperms_variation1_symlink.tmp"); unlink($file_path . "/fileperms_variation1_link.tmp"); unlink($file_path . "/fileperms_variation1.tmp");
public function linkToCacheFile($alias) { if ($alias === null) { $this->log("Ignore creating alias."); return $this; } if (is_readable($alias)) { unlink($alias); } $res = link($this->cacheFileName, $alias); if ($res) { $this->log("Created an alias as: {$alias}"); } else { $this->log("Failed to create the alias: {$alias}"); } return $this; }
/** * Create hard link $file in stb home directory * * @param string $media_file * @param int $media_id * @param string $proto * @return boolean */ public function createLink($media_file, $media_id, $proto = '') { $this->user->checkHome(); preg_match("/([\\S\\s]+)\\.(" . $this->media_ext_str . ")\$/i", $media_file, $arr); $ext = $arr[2]; $from = VIDEO_STORAGE_DIR . $media_file; $path = dirname($from); $file = basename($from); $movie_base = substr($file, 0, strrpos($file, '.')); $file_list = scandir($path); if ($file_list === false) { throw new IOException('Could not scan dir' . $path . ' on ' . $this->storage_name); } $subtitles = array_filter($file_list, function ($file) { return in_array(substr($file, strrpos($file, '.') + 1), array('srt', 'sub', 'ass')); }); $movie_subtitles = array_filter($subtitles, function ($subtitle_file) use($movie_base) { return strpos($subtitle_file, $movie_base) === 0; }); if (!empty($movie_subtitles)) { foreach ($movie_subtitles as $subtitle) { $from_sub = $path . '/' . $subtitle; $to_sub = NFS_HOME_PATH . $this->user->getMac() . '/' . $subtitle; if ($proto == 'http') { $link_result = @symlink($from_sub, $to_sub); } else { $link_result = @link($from_sub, $to_sub); } if (!$link_result) { throw new IOException('Could not create link ' . $from_sub . ' to ' . $to_sub . ' on ' . $this->storage_name); } } } $to = NFS_HOME_PATH . $this->user->getMac() . '/' . $media_id . '.' . $ext; if ($proto == 'http') { $link_result = @symlink($from, $to); } else { $link_result = @link($from, $to); } if (!$link_result) { throw new IOException('Could not create link ' . $from . ' to ' . $to . ' on ' . $this->storage_name); } if (!is_readable($to)) { throw new IOException('File ' . $to . ' is not readable on ' . $this->storage_name); } return true; }
static function link( $sourceFilename, $destinationFilename ) { if ( !file_exists( $sourceFilename ) and !is_link( $sourceFilename ) ) { eZDebug::writeError( "Cannot link to file $sourceFilename, it does not exist", __METHOD__ ); return false; } $isDir = false; if ( is_dir( $destinationFilename ) ) { $isDir = true; $dirPosition = strrpos( $sourceFilename, '/' ); $filePosition = 0; if ( $dirPosition !== false ) $filePosition = $dirPosition + 1; if ( strlen( $destinationFilename ) > 0 and $destinationFilename[strlen( $destinationFilename ) - 1] == '/' ) $destinationFilename .= substr( $sourceFilename, $filePosition ); else $destinationFilename .= '/' . substr( $sourceFilename, $filePosition ); } $destinationFilename = preg_replace( "#/+#", '/', $destinationFilename ); if ( file_exists( $destinationFilename ) and !is_dir( $destinationFilename ) ) { if ( !@unlink( $destinationFilename ) ) { eZDebug::writeError( "Cannot link to file $sourceFilename on destination $destinationFilename, destination file cannot be removed", __METHOD__ ); return false; } } if ( link( $sourceFilename, $destinationFilename ) ) { return true; } eZDebug::writeError( "Failed to link to $sourceFilename on destination $destinationFilename", __METHOD__ ); return false; }
/** * copy an existing message * * @param int $id number of message * @param string|Zend_Mail_Storage_Folder $folder name or instance of targer folder * @return null * @throws Zend_Mail_Storage_Exception */ public function copyMessage($id, $folder) { if ($this->_quota && $this->checkQuota()) { /** * @see Zend_Mail_Storage_Exception */ require_once 'Zend/Mail/Storage/Exception.php'; throw new Zend_Mail_Storage_Exception('storage is over quota!'); } if (!$folder instanceof Zend_Mail_Storage_Folder) { $folder = $this->getFolders($folder); } $filedata = $this->_getFileData($id); $old_file = $filedata['filename']; $flags = $filedata['flags']; // copied message can't be recent while (($key = array_search(Zend_Mail_Storage::FLAG_RECENT, $flags)) !== false) { unset($flags[$key]); } $info = $this->_getInfoString($flags); // we're creating the copy as temp file before moving to cur/ $temp_file = $this->_createTmpFile($folder->getGlobalName()); // we don't write directly to the file fclose($temp_file['handle']); // we're adding the size to the filename for maildir++ $size = filesize($old_file); if ($size !== false) { $info = ',S=' . $size . $info; } // TODO: support MDA with recent flag -> move to new $new_file = $temp_file['dirname'] . DIRECTORY_SEPARATOR . 'cur' . DIRECTORY_SEPARATOR . $temp_file['uniq'] . $info; // we're throwing any exception after removing our temp file and saving it to this variable instead $exception = null; if (!copy($old_file, $temp_file['filename'])) { /** * @see Zend_Mail_Storage_Exception */ require_once 'Zend/Mail/Storage/Exception.php'; $exception = new Zend_Mail_Storage_Exception('cannot copy message file'); } else { if (!link($temp_file['filename'], $new_file)) { /** * @see Zend_Mail_Storage_Exception */ require_once 'Zend/Mail/Storage/Exception.php'; $exception = new Zend_Mail_Storage_Exception('cannot link message file to final dir'); } } @unlink($temp_file['filename']); if ($exception) { throw $exception; } if ($folder->getGlobalName() == $this->_currentFolder || $this->_currentFolder == 'INBOX' && $folder->getGlobalName() == '/') { $this->_files[] = array('uniq' => $temp_file['uniq'], 'flags' => $flags, 'filename' => $new_file); } if ($this->_quota) { $this->_addQuotaEntry((int) $size, 1); } }
and dirs having limited access */ echo "*** Testing copy() function: copying links across different directories ***\n"; $file_path = dirname(__FILE__); $base_dir = $file_path . "/copy_variation8"; mkdir($base_dir); $sub_dir = $base_dir . "/copy_variation8_sub"; mkdir($sub_dir); $dirname_with_blank = $sub_dir . "/copy variation6"; mkdir($dirname_with_blank); $file = $file_path . "/copy_variation8.tmp"; fclose(fopen($file, "w")); $symlink = $file_path . "/copy_variation8_symlink.tmp"; $hardlink = $file_path . "/copy_variation8_hardlink.tmp"; symlink($file, $symlink); //creating symlink link($file, $hardlink); //creating hardlink $dests = array($base_dir . "/copy_copy_variation8.tmp", $base_dir . "/copy_variation8_sub/copy_copy_variation8.tmp", "{$sub_dir}/copy_copy_variation8.tmp", "{$sub_dir}/../copy_copy_variation8.tmp", "{$sub_dir}/../copy_variation8_sub/copy_copy_variation8.tmp", "{$sub_dir}/..///../copy_copy_variation8.tmp", "{$sub_dir}/..///../*", "{$dirname_with_blank}/copy_copy_variation8.tmp"); $count = 1; foreach ($dests as $dest) { echo "\n-- Iteration {$count} --\n"; echo "- With symlink -\n"; var_dump(copy($symlink, $dest)); var_dump(file_exists($dest)); var_dump(is_link($dest)); //expected: bool(false) var_dump(is_file($dest)); //expected: bool(true) clearstatcache(); unlink("{$dest}"); echo "- With hardlink -\n";
/** * copy an existing message * * @param int $id number of message * @param string|\Zend\Mail\Storage\Folder $folder name or instance of targer folder * @throws \Zend\Mail\Storage\Exception\RuntimeException */ public function copyMessage($id, $folder) { if ($this->quota && $this->checkQuota()) { throw new StorageException\RuntimeException('storage is over quota!'); } if (!$folder instanceof Folder) { $folder = $this->getFolders($folder); } $filedata = $this->_getFileData($id); $oldFile = $filedata['filename']; $flags = $filedata['flags']; // copied message can't be recent while (($key = array_search(Storage::FLAG_RECENT, $flags)) !== false) { unset($flags[$key]); } $info = $this->_getInfoString($flags); // we're creating the copy as temp file before moving to cur/ $tempFile = $this->_createTmpFile($folder->getGlobalName()); // we don't write directly to the file fclose($tempFile['handle']); // we're adding the size to the filename for maildir++ $size = filesize($oldFile); if ($size !== false) { $info = ',S=' . $size . $info; } $newFile = $tempFile['dirname'] . DIRECTORY_SEPARATOR . 'cur' . DIRECTORY_SEPARATOR . $tempFile['uniq'] . $info; // we're throwing any exception after removing our temp file and saving it to this variable instead $exception = null; if (!copy($oldFile, $tempFile['filename'])) { $exception = new StorageException\RuntimeException('cannot copy message file'); } elseif (!link($tempFile['filename'], $newFile)) { $exception = new StorageException\RuntimeException('cannot link message file to final dir'); } ErrorHandler::start(E_WARNING); unlink($tempFile['filename']); ErrorHandler::stop(); if ($exception) { throw $exception; } if ($folder->getGlobalName() == $this->currentFolder || $this->currentFolder == 'INBOX' && $folder->getGlobalName() == '/') { $this->files[] = array('uniq' => $tempFile['uniq'], 'flags' => $flags, 'filename' => $newFile); } if ($this->quota) { $this->_addQuotaEntry((int) $size, 1); } }
function makeexception($id, $date) { global $conn; # First read the non-exception records $event = mysql_query("SELECT * FROM calevent WHERE id={$id}", $conn) or die('Looking up event, ' . mysql_error()); $daily = mysql_query("SELECT * FROM caldaily WHERE id={$id} AND eventdate=\"{$date}\"", $conn) or die('Looking up daily, ' . mysql_error()); if (mysql_num_rows($event) != 1 || mysql_num_rows($daily) != 1) { die('Trouble making the exception record. Drat!'); } $event = mysql_fetch_array($event); $daily = mysql_fetch_array($daily); # Copy the event record, so it has a new $id. Initially, the only # change is that the "dates" field will be the one exceptional date. $sql = 'INSERT INTO calevent ('; $values = 'VALUES ('; $sql .= 'name, '; $values .= "\"{$event[name]}\","; $sql .= 'email, '; $values .= "\"{$event[email]}\","; $sql .= 'hideemail, '; $values .= "{$event[hideemail]},"; $sql .= 'emailforum, '; $values .= "{$event[emailforum]},"; $sql .= 'printemail, '; $values .= "{$event[printemail]},"; $sql .= 'phone, '; $values .= "\"{$event[phone]}\","; $sql .= 'hidephone, '; $values .= "{$event[hidephone]},"; $sql .= 'printphone, '; $values .= "{$event[printphone]},"; $sql .= 'weburl, '; $values .= "\"{$event[weburl]}\","; $sql .= 'webname, '; $values .= '"' . maybeaddslashes($event['webname']) . '",'; $sql .= 'printweburl, '; $values .= "{$event[printweburl]},"; $sql .= 'contact, '; $values .= "\"{$event[contact]}\","; $sql .= 'hidecontact, '; $values .= "{$event[hidecontact]},"; $sql .= 'printcontact, '; $values .= "{$event[printcontact]},"; $sql .= 'title, '; $values .= '"' . maybeaddslashes($event['title']) . '",'; $sql .= 'tinytitle, '; $values .= '"' . maybeaddslashes($event['tinytitle']) . '",'; $sql .= 'audience, '; $values .= "\"{$event[audience]}\","; $sql .= 'descr, '; $values .= '"' . maybeaddslashes($event['descr']) . '",'; $sql .= 'printdescr, '; $values .= '"' . maybeaddslashes($event['printdescr']) . '",'; $sql .= 'image, '; $values .= "\"{$event[image]}\","; $sql .= 'imagewidth, '; $values .= "{$event[imagewidth]},"; $sql .= 'imageheight, '; $values .= "{$event[imageheight]},"; $sql .= 'dates, '; $values .= '"' . date('l, F j', strtotime($date)) . '",'; $sql .= 'datestype,'; $values .= "\"O\","; $sql .= 'eventtime, '; $values .= "\"{$event[eventtime]}\","; $sql .= 'eventduration, '; $values .= "\"{$event[eventduration]}\","; $sql .= 'timedetails, '; $values .= "\"{$event[timedetails]}\","; $sql .= 'locname, '; $values .= '"' . maybeaddslashes($event['locname']) . '",'; $sql .= 'address, '; $values .= "\"{$event[address]}\","; $sql .= 'addressverified, '; $values .= "\"{$event[addressverified]}\","; $sql .= 'locdetails, '; $values .= '"' . maybeaddslashes($event['locdetails']) . '",'; $sql .= 'area, '; $values .= "\"{$event[area]}\","; $sql .= 'external) '; $values .= "\"{$event[external]}\")"; $sql = $sql . $values; mysql_query($sql, $conn) or die('Adding exceptional event, ' . mysql_error()); $exceptionid = mysql_insert_id($conn) or die('Retrieving the ID, ' . mysql_error()); # Copy the daily record, making it be the exception $sql = 'INSERT INTO caldaily ('; $values = ' VALUES ('; $sql .= 'id,'; $values .= "{$exceptionid},"; $sql .= 'newsflash,'; $values .= "\"{$daily[newsflash]}\","; $sql .= 'eventdate,'; $values .= "\"{$date}\","; $sql .= 'eventstatus,'; $values .= "\"A\","; $sql .= 'exceptionid)'; $values .= "0)"; $sql = $sql . $values; mysql_query($sql, $conn) or die('Adding exceptional date, ' . mysql_error()); # If it has an image, copy the image if ($event['image']) { $t = pathinfo($event['image']); $ext = $t['extension']; link("eventimages/{$id}.{$ext}", "eventimages/{$exceptionid}.{$ext}"); } # Return the exceptionid return $exceptionid; }