Example #1
1
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $remoteFilename = 'http://get.insight.sensiolabs.com/insight.phar';
     $localFilename = $_SERVER['argv'][0];
     $tempFilename = basename($localFilename, '.phar') . '-temp.phar';
     try {
         copy($remoteFilename, $tempFilename);
         if (md5_file($localFilename) == md5_file($tempFilename)) {
             $output->writeln('<info>insight is already up to date.</info>');
             unlink($tempFilename);
             return;
         }
         chmod($tempFilename, 0777 & ~umask());
         // test the phar validity
         $phar = new \Phar($tempFilename);
         // free the variable to unlock the file
         unset($phar);
         rename($tempFilename, $localFilename);
         $output->writeln('<info>insight updated.</info>');
     } catch (\Exception $e) {
         if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
             throw $e;
         }
         unlink($tempFilename);
         $output->writeln('<error>The download is corrupt (' . $e->getMessage() . ').</error>');
         $output->writeln('<error>Please re-run the self-update command to try again.</error>');
     }
 }
Example #2
0
 public static function getDateCatalogTree($sPath, $data = false, $czyWyswietlacBledy = false)
 {
     $data = $data ? substr($data, 0, 10) : date('Y-m-d');
     $data = explode('-', $data);
     $oldUmask = umask(0);
     if (!file_exists($sPath . $data[0] . '/')) {
         if ($czyWyswietlacBledy) {
             mkdir($sPath . $data[0] . '/', 0770);
         } else {
             @mkdir($sPath . $data[0] . '/', 0770);
         }
     }
     if (!file_exists($sPath . $data[0] . '/' . $data[1] . '/')) {
         if ($czyWyswietlacBledy) {
             mkdir($sPath . $data[0] . '/' . $data[1] . '/', 0770);
         } else {
             @mkdir($sPath . $data[0] . '/' . $data[1] . '/', 0770);
         }
     }
     if (!file_exists($sPath . $data[0] . '/' . $data[1] . '/' . $data[2] . '/')) {
         if ($czyWyswietlacBledy) {
             mkdir($sPath . $data[0] . '/' . $data[1] . '/' . $data[2] . '/', 0770);
         } else {
             @mkdir($sPath . $data[0] . '/' . $data[1] . '/' . $data[2] . '/', 0770);
         }
     }
     umask($oldUmask);
     return $sPath . $data[0] . '/' . $data[1] . '/' . $data[2] . '/';
 }
Example #3
0
 /**
  * @see Console\Command\Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $module = $input->getArgument('module');
     $modules = $this->moduleManager->getModules();
     $path = "{$this->modulesDir}/{$module}-module";
     if (isset($modules[$module])) {
         $output->writeln("<error>Module '{$module}' already exists.</error>");
         return;
     }
     if (file_exists($path)) {
         $output->writeln("<error>Path '" . $path . "' exists.</error>");
         return;
     }
     if (!is_writable(dirname($path))) {
         $output->writeln("<error>Path '" . dirname($path) . "' is not writable.</error>");
         return;
     }
     umask(00);
     mkdir($path, 0777, TRUE);
     file_put_contents($path . '/Module.php', $this->getModuleFile($module));
     file_put_contents($path . '/composer.json', $this->getComposerFile($module));
     file_put_contents($path . '/readme.md', $this->getReadmeFile($module));
     mkdir($path . '/Resources/config', 0777, TRUE);
     mkdir($path . '/Resources/public', 0777, TRUE);
     mkdir($path . '/Resources/translations', 0777, TRUE);
     mkdir($path . '/Resources/layouts', 0777, TRUE);
     mkdir($path . '/' . ucfirst($module) . 'Module', 0777, TRUE);
 }
 public function up()
 {
     $old = umask(0);
     mkdir(Config::get('upload_dir'), 0777);
     umask($old);
     symlink(Config::get('upload_dir'), Config::get('public_dir') . '/upload');
 }
 /**
  * Writes file in a save way to disk
  *
  * @param  string  $_filepath complete filepath
  * @param  string  $_contents file content
  * @return boolean true
  */
 public static function writeFile($_filepath, $_contents, $smarty)
 {
     $old_umask = umask(0);
     $_dirpath = dirname($_filepath);
     // if subdirs, create dir structure
     if ($_dirpath !== '.' && !file_exists($_dirpath)) {
         mkdir($_dirpath, $smarty->_dir_perms, true);
     }
     // write to tmp file, then move to overt file lock race condition
     $_tmp_file = tempnam($_dirpath, 'wrt');
     if (!($fd = @fopen($_tmp_file, 'wb'))) {
         $_tmp_file = $_dirpath . DS . uniqid('wrt');
         if (!($fd = @fopen($_tmp_file, 'wb'))) {
             throw new SmartyException("unable to write file {$_tmp_file}");
             return false;
         }
     }
     fwrite($fd, $_contents);
     fclose($fd);
     // remove original file
     if (file_exists($_filepath)) {
         @unlink($_filepath);
     }
     // rename tmp file
     rename($_tmp_file, $_filepath);
     // set file permissions
     chmod($_filepath, $smarty->_file_perms);
     umask($old_umask);
     return true;
 }
Example #6
0
/**
 *	log a message to file
 *
 *	@param string $level can be error, warn, info or debug
 *	@param string $msg message
 *	@return bool true if successful, false if not
 */
function log_msg($level, $msg)
{
    global $logfile;
    global $loglevels;
    global $request_id;
    // open logfile
    if ($logfile === false) {
        $m = umask(0111);
        // having two processes appending to the same file should
        // work fine (at least on Linux)
        $logfile = @fopen(LOG_FILE, 'ab');
        umask($m);
    }
    if ($logfile === false) {
        return false;
    }
    foreach ($loglevels as $ll) {
        if ($ll == $level) {
            fwrite($logfile, date('Y-m-d H:i:s') . tab() . pad($_SERVER['REMOTE_ADDR'], 15) . tab() . sprintf('%05u', $request_id) . tab() . $level . tab() . $msg . nl());
            fflush($logfile);
            break;
        }
        if ($ll == LOG_LEVEL) {
            break;
        }
    }
    return true;
}
Example #7
0
 function __construct($name)
 {
     global $TMP_PATH;
     global $SETUP;
     $dir = $TMP_PATH . "/locks";
     if (!is_dir($dir)) {
         if (!@mkdir($dir, 0777, true)) {
             throw new ADEIException(translate("It is not possible to create lock directory \"{$dir}\""));
         }
         # When creating from apache, the 0777 mode is ignored for unknown reason
         @chmod($dir, 0777);
     }
     if ($SETUP) {
         $fname = $dir . "/{$SETUP}__{$name}.lock";
     } else {
         $fname = $dir . "/ADEI__{$name}.lock";
     }
     $umask = @umask(0);
     $this->lockf = @fopen($fname, "a+");
     if (!$this->lockf) {
         @umask($umask);
         throw new ADEIException(translate("It is not possible to create lock file \"{$fname}\""));
     }
     $fname = $dir . "/{$name}.lock";
     $this->rlock = @fopen($fname, "a+");
     if (!$this->rlock) {
         fclose($this->lockf);
         @umask($umask);
         throw new ADEIException(translate("It is not possible to create lock file \"{$fname}\""));
     }
     @umask($umask);
 }
 /**
  * {@inheritdoc}
  */
 protected function writeCacheFile($file, $content)
 {
     $dir = dirname($file);
     $currentUmask = umask(00);
     if (!is_dir($dir)) {
         if (false === @mkdir($dir, 0777, true) && !is_dir($dir)) {
             throw new RuntimeException(sprintf("Unable to create the cache directory (%s).", $dir));
         }
     } elseif (!is_writable($dir)) {
         throw new RuntimeException(sprintf("Unable to write in the cache directory (%s).", $dir));
     }
     $success = false;
     $tmpFile = tempnam(dirname($file), basename($file));
     if (false !== @file_put_contents($tmpFile, $content)) {
         if (false === ($success = @rename($tmpFile, $file))) {
             $success = copy($tmpFile, $file);
             $success = unlink($tmpFile) && $success;
         }
     }
     if ($success) {
         chmod($file, 0666);
     }
     umask($currentUmask);
     if (!$success) {
         throw new RuntimeException(sprintf('Failed to write cache file "%s".', $file));
     }
 }
Example #9
0
/**
 * Creates directory
 *
 * @param  string  $path Path to create
 * @param  integer $mode Optional permissions
 * @return boolean Success
 */
function _mkdir($path, $mode = 0777)
{
    $old = umask(0);
    $res = @mkdir($path, $mode);
    umask($old);
    return $res;
}
Example #10
0
 /**
  * handle request and build XML
  * @access protected
  *
  */
 protected function buildXml()
 {
     $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
     if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_CREATE)) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
     }
     $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
     $sNewFolderName = isset($_GET["NewFolderName"]) ? $_GET["NewFolderName"] : "";
     $sNewFolderName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($sNewFolderName);
     if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sNewFolderName) || $_resourceTypeConfig->checkIsHiddenFolder($sNewFolderName)) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME);
     }
     $sServerDir = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $sNewFolderName);
     if (!is_writeable($this->_currentFolder->getServerPath())) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
     }
     $bCreated = false;
     if (file_exists($sServerDir)) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST);
     }
     if ($perms = $_config->getChmodFolders()) {
         $oldUmask = umask(0);
         $bCreated = @mkdir($sServerDir, $perms);
         umask($oldUmask);
     } else {
         $bCreated = @mkdir($sServerDir);
     }
     if (!$bCreated) {
         $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
     } else {
         $oNewFolderNode = new Ckfinder_Connector_Utils_XmlNode("NewFolder");
         $this->_connectorNode->addChild($oNewFolderNode);
         $oNewFolderNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($sNewFolderName));
     }
 }
Example #11
0
 /**
  * @param ImageInterface $image
  * @param $namespace
  * @param $image_hash
  * @param $image_thumb
  * @return File
  */
 public function createFromImagine(ImageInterface $image, $namespace, $image_hash, $image_thumb)
 {
     umask(00);
     $dest = $this->createDestinationPath($namespace, $image_hash, $image_thumb);
     $image->save($dest);
     return new File($dest);
 }
 /**
  * Initialize the Mage environment.
  * @constructor
  */
 public function __construct($config)
 {
     umask(0);
     chdir($config['path']);
     require_once $config['path'] . '/app/Mage.php';
     \Mage::app($config['store']);
 }
Example #13
0
 private function make_child_dir($path)
 {
     // No need to continue if the directory already exists
     if (is_dir($path)) {
         return true;
     }
     // Make sure parent exists
     $parent = dirname($path);
     if (!is_dir($parent)) {
         $this->make_child_dir($parent);
     }
     $created = false;
     $old = umask(0);
     // Try to create new directory with parent directory's permissions
     $permissions = substr(sprintf('%o', fileperms($parent)), -4);
     if (is_dir($path) || mkdir($path, octdec($permissions), true)) {
         $created = true;
     } else {
         if ($permissions == '0755' && chmod($parent, 0777) && mkdir($path, 0777, true)) {
             $created = true;
         }
     }
     umask($old);
     return $created;
 }
 protected function loadMagento($_languageCode = 'en')
 {
     if (file_exists($this->__config->get('pathToMagentoApp'))) {
         include_once $this->__config->get('pathToMagentoApp');
     } else {
         if (file_exists(ROOT_DIR . $this->__config->get('pathToMagentoApp'))) {
             include_once ROOT_DIR . $this->__config->get('pathToMagentoApp');
         } else {
             throw new \Exception('Mage NOT Found at ' . $this->__config->get('pathToMagentoApp'));
         }
     }
     umask(0);
     \Mage::app();
     \Mage::app()->loadArea(\Mage_Core_Model_App_Area::AREA_FRONTEND);
     $baseUrlMedia = \Mage::getBaseUrl(\Mage_Core_Model_Store::URL_TYPE_MEDIA);
     $_stores = \Mage::app()->getStores(false, true);
     if (isset($_stores[$_languageCode]) && $_stores[$_languageCode]->getIsActive()) {
         $_storeID = $_stores[$_languageCode]->getId();
     } else {
         $_storeID = 0;
         // default store for no language match
     }
     $this->set('languagecode', $_languageCode);
     $this->set('storeid', $_storeID);
     $this->set('baseurlmedia', $baseUrlMedia);
 }
Example #15
0
 public function __construct()
 {
     $args = func_get_args();
     $path = STORAGE_PATH;
     // $path = isAke(get_defined_constants(), 'STORAGE_PATH', false);
     if (0 == count($args)) {
         return;
     } elseif (2 == count($args)) {
         list($db, $table) = $args;
     } elseif (3 == count($args)) {
         list($db, $table, $path) = $args;
     }
     if (false === $path) {
         throw new Exception("You must provide a path in third argument of this method.");
     }
     if (!is_dir($path . DS . 'dbjson')) {
         umask(00);
         File::mkdir($path . DS . 'dbjson', 0777, true);
     }
     $this->dir = $path . DS . 'dbjson' . DS . Inflector::lower($db) . DS . Inflector::lower($table);
     if (!is_dir($path . DS . 'dbjson' . DS . Inflector::lower($db))) {
         umask(00);
         File::mkdir($path . DS . 'dbjson' . DS . Inflector::lower($db), 0777, true);
     }
     if (!is_dir($path . DS . 'dbjson' . DS . Inflector::lower($db) . DS . Inflector::lower($table))) {
         umask(00);
         File::mkdir($path . DS . 'dbjson' . DS . Inflector::lower($db) . DS . Inflector::lower($table), 0777, true);
     }
     $changeFile = $this->dir . DS . 'change';
     if (!File::exists($changeFile)) {
         File::put($changeFile, '');
     }
     $this->db = $db;
     $this->table = $table;
 }
Example #16
0
 function onSubmit($vals)
 {
     $vals['name'] = strtolower($vals['name']);
     //make sure that file doesnt exit
     if (file_exists('inc/html/' . $vals['set_name'] . '/' . $vals['name'] . '.css')) {
         echo '<p>' . intl_get('A file with that name already exists. Choose a different file name.') . '</p>';
         echo '<p>' . intl_get('Go <a href=javascript:history.back()>back</a> to choose a different file name.') . '</p>';
     }
     if (preg_match('/\\.css$/i', $vals['name'])) {
         $ext = '';
     } else {
         $ext = '.css';
     }
     if (!file_overwrite('inc/html/' . $vals['set_name'] . '/' . $vals['name'] . $ext, $vals['body'])) {
         page_title(intl_get('An Error Occurred'));
         echo '<p>' . intl_get('The file was unable to be saved.  Please verify your server settings before trying again.') . '</p>';
         return;
     }
     umask(00);
     chmod('inc/html/' . $vals['set_name'] . '/' . $vals['name'] . $ext, 0777);
     list($set, $tpl) = explode('/', $vals['path']);
     echo $set . ' ' . $tpl;
     page_title('File Saved');
     echo '<p><a href="' . site_prefix() . '/index/sitetemplate-templateselect-action?set_name=' . $vals['set_name'] . '">' . intl_get('Return to template set') . '</a></p>';
 }
Example #17
0
 function write($log_file_data, $string)
 {
     $log_dir = $log_file_data[0];
     $log_name = $log_file_data[1];
     $file_name = $log_dir . $log_name;
     if (!is_dir($log_dir)) {
         fs::mkdir($log_dir, 0775, true);
     }
     $oldumask = @umask(0);
     $file_existed = @file_exists($file_name);
     $log_file = @fopen($file_name, 'a');
     if ($log_file) {
         $time = strftime("%b %d %Y %H:%M:%S", strtotime('now'));
         $notice = '[ ' . $time . " ]\n";
         $user =& user::instance();
         if (($user_id = $user->get_id()) != DEFAULT_USER_ID) {
             $notice .= '[ ' . $user_id . ' ] [ ' . $user->get_login() . ' ] [ ' . $user->get_email() . ' ] ';
         }
         $notice .= '[' . sys::client_ip() . '] [' . (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '') . "]\n" . $string . "\n\n";
         @fwrite($log_file, $notice);
         @fclose($log_file);
         if (!$file_existed) {
             @chmod($file_name, 0664);
         }
         @umask($oldumask);
         $result = true;
     } else {
         @umask($oldumask);
         $result = false;
         debug::write_error("Cannot open log file '{$file_name}' for writing\n" . "The web server must be allowed to modify the file.\n" . "File logging for '{$file_name}' is disabled.", __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, false);
     }
     return $result;
 }
Example #18
0
 public function __construct(Silex\Application $app, $packageRepo = null)
 {
     // Needed (for now) to log errors to the bolt_log table.
     $this->app = $app;
     $this->basedir = $app['resources']->getPath('extensions');
     $this->packageRepo = $packageRepo;
     $this->packageFile = $app['resources']->getPath('root') . '/extensions/composer.json';
     umask(00);
     putenv("COMPOSER_HOME=" . $app['resources']->getPath('cache') . '/composer');
     $this->wrapper = \evidev\composer\Wrapper::create();
     if (!is_file($this->packageFile)) {
         $this->execute('init');
     }
     if (is_file($this->packageFile) && !is_writable($this->packageFile)) {
         $this->messages[] = sprintf("The file '%s' is not writable. You will not be able to use this feature without changing the permissions.", $this->packageFile);
     }
     $this->execute('config repositories.bolt composer ' . $app['extend.site'] . 'satis/');
     $json = json_decode(file_get_contents($this->packageFile));
     $json->repositories->packagist = false;
     $basePackage = "bolt/bolt";
     $json->provide = new \stdClass();
     $json->provide->{$basePackage} = $app['bolt_version'];
     $json->scripts = array('post-package-install' => "Bolt\\Composer\\ScriptHandler::extensions", 'post-package-update' => "Bolt\\Composer\\ScriptHandler::extensions");
     $pathToWeb = $app['resources']->findRelativePath($this->app['resources']->getPath('extensions'), $this->app['resources']->getPath('web'));
     $json->extra = array('bolt-web-path' => $pathToWeb);
     file_put_contents($this->packageFile, json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
     try {
         $json = json_decode(file_get_contents($this->packageRepo));
         $this->available = $json->packages;
     } catch (\Exception $e) {
         $this->messages[] = sprintf($app['translator']->trans("The Bolt extensions Repo at %s is currently unavailable. Check your connection and try again shortly."), $this->packageRepo);
         $this->available = array();
     }
 }
Example #19
0
 public static function minimalBootstrap()
 {
     if (!defined('VENDOR_PATH')) {
         define('VENDOR_PATH', 'vendor');
     }
     if (VENDOR_PATH == '../vendor') {
         $kwfPath = '..';
     } else {
         $kwfPath = VENDOR_PATH . '/koala-framework/koala-framework';
     }
     if (!defined('KWF_PATH')) {
         define('KWF_PATH', $kwfPath);
     }
     //reset include path, don't use anything from php.ini
     set_include_path('.' . PATH_SEPARATOR . $kwfPath . PATH_SEPARATOR . self::_getZendPath());
     require_once $kwfPath . '/Kwf/Loader.php';
     Kwf_Loader::registerAutoload();
     Zend_Registry::setClassName('Kwf_Registry');
     $configSection = call_user_func(array(Kwf_Setup::$configClass, 'getDefaultConfigSection'));
     Kwf_Setup::$configSection = $configSection;
     error_reporting(E_ALL ^ E_STRICT);
     class_exists('Kwf_Trl');
     //trigger autoload
     umask(00);
     //nicht 002 weil wwwrun und kwcms in unterschiedlichen gruppen
 }
Example #20
0
 private function createUsersFolder($uid)
 {
     $userFolder = md5($uid);
     $oldUmask = umask(0);
     mkdir('data/users/' . $userFolder, 0777, true);
     umask($oldUmask);
     $oldUmask = umask(0);
     mkdir('data/users/' . $userFolder . '/avatar', 0777, true);
     umask($oldUmask);
     $oldUmask = umask(0);
     mkdir('data/users/' . $userFolder . '/album', 0777, true);
     umask($oldUmask);
     $oldUmask = umask(0);
     mkdir('data/users/' . $userFolder . '/event', 0777, true);
     umask($oldUmask);
     $oldUmask = umask(0);
     mkdir('data/users/' . $userFolder . '/home', 0777, true);
     umask($oldUmask);
     copy('public/templates/default/images/avatar.jpg', 'data/users/' . $userFolder . '/avatar/avatar.jpg');
     chmod('data/users/' . $this->user['md5'] . '/avatar.jpg', 0755);
     copy('public/templates/default/images/friend.jpg', 'data/users/' . $userFolder . '/avatar/friend.jpg');
     chmod('data/users/' . $this->user['md5'] . '/friend.jpg', 0755);
     copy('public/templates/default/images/thumbnail.jpg', 'data/users/' . $userFolder . '/avatar/thumbnail.jpg');
     chmod('data/users/' . $this->user['md5'] . '/thumbnail.jpg', 0755);
 }
Example #21
0
 public function getResources()
 {
     $umask = umask(0);
     $src = $this->prepareResources();
     umask($umask);
     return $src;
 }
Example #22
0
File: io.php Project: LFSF/oras
function CreateServerFolder($folderPath)
{
    $sParent = GetParentFolder($folderPath);
    // Check if the parent exists, or create it.
    if (!file_exists($sParent)) {
        $sErrorMsg = CreateServerFolder($sParent);
        if ($sErrorMsg != '') {
            return $sErrorMsg;
        }
    }
    if (!file_exists($folderPath)) {
        // Turn off all error reporting.
        error_reporting(0);
        // Enable error tracking to catch the error.
        ini_set('track_errors', '1');
        // To create the folder with 0777 permissions, we need to set umask to zero.
        $oldumask = umask(0);
        mkdir($folderPath, 0777);
        umask($oldumask);
        $sErrorMsg = $php_errormsg;
        // Restore the configurations.
        ini_restore('track_errors');
        ini_restore('error_reporting');
        return $sErrorMsg;
    } else {
        return '';
    }
}
Example #23
0
/**
 *  Create folder recursively
 */
function createRDir($folder)
{
    $reval = false;
    if (!file_exists($folder)) {
        @umask(0);
        preg_match_all('/([^\\/]*)\\/?/i', $folder, $atmp);
        $base = $atmp[0][0] == '/' ? '/' : '';
        foreach ($atmp[1] as $val) {
            if ('' != $val) {
                $base .= $val;
                if ('..' == $val || '.' == $val) {
                    $base .= '/';
                    continue;
                }
            } else {
                continue;
            }
            $base .= '/';
            if (!file_exists($base)) {
                if (mkdir($base, 0777)) {
                    chmod($base, 0777);
                    $reval = true;
                }
            }
        }
    } else {
        $reval = is_dir($folder);
    }
    clearstatcache();
    return $reval;
}
 public function moveUploadedFile(UploadedFile $file, $uploadBasePath, $relativePath, $fileName)
 {
     $originalName = $file->getFilename();
     // use filemtime() to have a more determenistic way to determine the subpath, otherwise its hard to test.
     // $relativePath = date('Y-m', filemtime($file->getPath()));
     $targetFileName = $relativePath . DIRECTORY_SEPARATOR . $originalName;
     $targetFilePath = $uploadBasePath . DIRECTORY_SEPARATOR . $targetFileName;
     $ext = $file->getExtension();
     $i = 1;
     while (file_exists($targetFilePath) && md5_file($file->getPath()) != md5_file($targetFilePath)) {
         if ($ext) {
             $prev = $i == 1 ? "" : $i;
             $targetFilePath = $targetFilePath . str_replace($prev . $ext, $i++ . $ext, $targetFilePath);
         } else {
             $targetFilePath = $targetFilePath . $i++;
         }
     }
     $targetDir = $uploadBasePath . DIRECTORY_SEPARATOR . $relativePath;
     if (!is_dir($targetDir)) {
         $ret = mkdir($targetDir, umask(), true);
         if (!$ret) {
             throw new \RuntimeException("Could not create target directory to move temporary file into.");
         }
     }
     //$file->move($targetDir, basename($targetFilePath));
     //$file->move($targetDir, basename($fileName.'.'.$ext));
     $file->move($targetDir, basename($fileName));
     return str_replace($uploadBasePath . DIRECTORY_SEPARATOR, "", $targetFilePath);
 }
Example #25
0
 /**
  * {@inheritdoc}
  */
 public function write($key, $content)
 {
     $dir = dirname($key);
     if (!is_dir($dir)) {
         if (false === @mkdir($dir, 0777, true)) {
             clearstatcache(false, $dir);
             if (!is_dir($dir)) {
                 throw new RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir));
             }
         }
     } elseif (!is_writable($dir)) {
         throw new RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir));
     }
     $tmpFile = tempnam($dir, basename($key));
     if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $key)) {
         @chmod($key, 0666 & ~umask());
         if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
             // Compile cached file into bytecode cache
             if (function_exists('opcache_invalidate')) {
                 opcache_invalidate($key, true);
             } elseif (function_exists('apc_compile_file')) {
                 apc_compile_file($key);
             }
         }
         return;
     }
     throw new RuntimeException(sprintf('Failed to write cache file "%s".', $key));
 }
 public static function createRequiredFiles(Event $event)
 {
     $fs = new Filesystem();
     $root = static::getDrupalRoot(getcwd());
     $dirs = ['modules', 'profiles', 'themes'];
     // Required for unit testing
     foreach ($dirs as $dir) {
         if (!$fs->exists($root . '/' . $dir)) {
             $fs->mkdir($root . '/' . $dir);
             $fs->touch($root . '/' . $dir . '/.gitkeep');
         }
     }
     // Prepare the settings file for installation
     if (!$fs->exists($root . '/sites/default/settings.php')) {
         $fs->copy($root . '/sites/default/default.settings.php', $root . '/sites/default/settings.php');
         $fs->chmod($root . '/sites/default/settings.php', 0666);
         $event->getIO()->write("Create a sites/default/settings.php file with chmod 0666");
     }
     // Prepare the services file for installation
     if (!$fs->exists($root . '/sites/default/services.yml')) {
         $fs->copy($root . '/sites/default/default.services.yml', $root . '/sites/default/services.yml');
         $fs->chmod($root . '/sites/default/services.yml', 0666);
         $event->getIO()->write("Create a sites/default/services.yml file with chmod 0666");
     }
     // Create the files directory with chmod 0777
     if (!$fs->exists($root . '/sites/default/files')) {
         $oldmask = umask(0);
         $fs->mkdir($root . '/sites/default/files', 0777);
         umask($oldmask);
         $event->getIO()->write("Create a sites/default/files directory with chmod 0777");
     }
 }
Example #27
0
function chmod_recursive($path, $mode)
{
    umask(00);
    if (!is_dir($path)) {
        return chmod($path, $mode);
    }
    $dh = opendir($path);
    while ($file = readdir($dh)) {
        if ($file != '.' && $file != '..') {
            $fullpath = $path . '/' . $file;
            if (!is_dir($fullpath)) {
                if (!chmod($fullpath, $mode)) {
                    return false;
                } else {
                    if (!chmod_recursive($fullpath, $mode)) {
                        return false;
                    }
                }
            }
        }
    }
    closedir($dh);
    if (chmod($path, $mode)) {
        return true;
    }
    return false;
}
Example #28
0
 function nofate_mkdir($dir)
 {
     $u = umask(0);
     $r = mkdir($dir, $this->mode);
     umask($u);
     return $r;
 }
Example #29
0
public function __construct ($configs)
{
	parent::__construct($configs);

	if (!coren::depend('_path_normalizer_0'))
		throw new exception("Tool '_path_normalizer_0' missed.");

	if(isset($configs['lock_relax'])) $this->lock_relax = $configs['lock_relax'];
	if(isset($configs['lock_count'])) $this->lock_count = $configs['lock_count'];
	if(isset($configs['lock_sleep'])) $this->lock_sleep = $configs['lock_sleep'];

	if(isset($configs['chunk_size'])) $this->chunk_size = $configs['chunk_size'];
	$this->chink_size = (integer) $this->chunk_size;
	if ($this->chunk_size <= 0) $this->chunk_size = 1024;

	if(isset($configs['dir_path'    ])) $this->dir_path     = $configs['dir_path'    ];
	if(isset($configs['dir_absolute'])) $this->dir_absolute = $configs['dir_absolute'];
	if(isset($configs['dir_required'])) $this->dir_required = $configs['dir_required'];
	if(isset($configs['dir_automake'])) $this->dir_automake = $configs['dir_automake'];
	if(isset($configs['dir_umask'   ])) $this->dir_umask    = $configs['dir_umask'   ];
	$this->dir = _path_normalizer_0::normalize_dir($this->dir_path, $this->dir_absolute ? null : SITEPATH);
	if ($this->dir_automake && !file_exists($this->dir))
	{
		$old_umask = umask(octdec($this->dir_umask));
		mkdir($this->dir, 0777, true);
		umask($old_umask);
	}
	if ($this->dir_required && !is_dir($this->dir))
	{
		throw new exception("Required directory '{$this->dir}' does not exist.");
	}
}
Example #30
0
 /**
  * Moves the file to a new location.
  *
  * @param string $dir  The destination folder
  * @param string $name The new file name
  *
  * @return File A File object representing the new file
  * @throws \RuntimeException if the target file could not be created
  */
 public function move($dir, $name = null)
 {
     $target = $this->getTargetFile($dir, $name);
     rename($this->getPathname(), $target);
     chmod($target, 0666 & ~umask());
     return $target;
 }