function testlocking() { $this->assertFalse(PEAR::isError(File::write('test.txt', 'abc', FILE_MODE_APPEND, true))); $this->assertTrue(PEAR::isError(File::write('test.txt', 'def', FILE_MODE_WRITE, true))); $this->assertFalse(PEAR::isError(File::unlock('test.txt', FILE_MODE_APPEND))); $this->assertFalse(PEAR::isError(File::unlock('test.txt', FILE_MODE_WRITE))); }
private function generate_cache_file() { try { $cache_file = new File($this->cache_file_path); $cache_file->open(File::WRITE); $cache_file->lock(); $cache_file->write($this->get_parsed_content()); $cache_file->unlock(); $cache_file->close(); $cache_file->change_chmod(0666); } catch (IOException $ex) { throw new TemplateLoadingException('The template file cache couldn\'t been written due to this problem: ' . $ex->getMessage()); } }
<?php $MODULE = array('getFiles' => function () { $path = post('path'); $FOLDER = new Folder($path); return array('files' => $FOLDER->getFiles(function ($file) use($FOLDER) { return $file->path != $FOLDER->path; }, function ($file) { return $file->toArray(); }), 'info' => $FOLDER->toFileArray()); }, 'newFile' => function () { $path = post('path'); return array('error' => File::create($path)); }, 'newFolder' => function () { $path = post('path'); return array('error' => Folder::create($path)); }, 'delete' => function () { $path = post('path'); $err = _is_dir($path) ? Folder::delete($path) : File::delete($path); return array('error' => $err); }, 'unlock' => function () { $path = post('path'); return array('error' => File::unlock($path)); });
private function generate_cache_file() { $real_file_content = @file_get_contents($this->real_filepath); if ($real_file_content === false) { throw new FileTemplateLoadingException($this->filepath, $this->real_filepath); } $parser = new TemplateSyntaxParser(); $result = $parser->parse($real_file_content); try { $cache_file = new File($this->cache_filepath); $cache_file->open(File::WRITE); $cache_file->lock(); $cache_file->write($result); $cache_file->unlock(); $cache_file->close(); $cache_file->change_chmod(0666); } catch (IOException $ex) { throw new TemplateLoadingException('The template file cache couldn\'t been written due to this problem :' . $ex->getMessage()); } }
// We are trying to affect an other author's work // ... which is only suitable for admins. if (!pieIsSuperuser($GLOBALS['pie']['user'])) { pieError("AuthorDiffers", array('action' => "{$context}history")); } } // Ask user for acknowledgement to delete the page. pieError("AskApproval"); } // Delete the resource: if (!$object->delete($target)) { pieError("DeleteError"); } if ($context == "page") { // Do what is to be done with pages. if ($object->meta['type'] != "alias") { // Delete the cache, if available. $cache = new Cache(); $cid = $cache->key('page', array('page' => $target)); if ($cache->exists($cid)) { $cache->delete($cid); } if ($cache->exists($cache->key('latest', array()))) { $cache->delete($cache->key('latest', array())); } } $object->unlock($GLOBALS['pie']['user']); } pieLog("alter"); pieNotice("DeleteSuccessful"); pieTail();
/** * Exports optimized content to a file. */ public function export_to_file($location) { if (!empty($this->files) || !empty($this->scripts)) { $file = new File($location); $file->delete(); $file->open(File::WRITE); $file->lock(); $file->write($this->content); $file->unlock(); $file->close(); $file->change_chmod(0666); } }
function write($module_name, &$cache_string) { $file_path = PATH_TO_ROOT . '/cache/' . $module_name . '.php'; import('io/filesystem/file'); $cache_file = new File($file_path, WRITE); $cache_file->delete(); $cache_file->open(); $cache_file->lock(); $cache_file->write("<?php\n" . $cache_string . "\n?>"); $cache_file->unlock(); $cache_file->close(); $cache_file->change_chmod(0666); if (!file_exists($file_path) && filesize($file_path) == 0) { $Errorh->handler('Cache -> La génération du fichier de cache <strong>' . $file . '</strong> a échoué!', E_USER_ERROR, __LINE__, __FILE__); } }
function _save($file_cache_path) { import('io/filesystem/file'); $file = new File($file_cache_path); $file->open(WRITE); $file->lock(); $file->write($this->template); $file->unlock(); $file->close(); $file->change_chmod(0666); }