public function listFile($pathname, $pattern = "*") { static $_listDirs = array(); $guid = md5($pathname . $pattern); if (!isset($_listDirs[$guid])) { $dir = array(); $list = glob($pathname . $pattern); foreach ($list as $i => $file) { $dir[$i]["filename"] = preg_replace("/^.+[\\\\\\/]/", "", $file); $dir[$i]["pathname"] = realpath($file); $dir[$i]["owner"] = fileowner($file); $dir[$i]["perms"] = fileperms($file); $dir[$i]["inode"] = fileinode($file); $dir[$i]["group"] = filegroup($file); $dir[$i]["path"] = dirname($file); $dir[$i]["atime"] = fileatime($file); $dir[$i]["ctime"] = filectime($file); $dir[$i]["size"] = filesize($file); $dir[$i]["type"] = filetype($file); $dir[$i]["ext"] = is_file($file) ? strtolower(substr(strrchr(basename($file), "."), 1)) : ""; $dir[$i]["mtime"] = filemtime($file); $dir[$i]["isDir"] = is_dir($file); $dir[$i]["isFile"] = is_file($file); $dir[$i]["isLink"] = is_link($file); $dir[$i]["isReadable"] = is_readable($file); $dir[$i]["isWritable"] = is_writable($file); } $cmp_func = create_function("\$a,\$b", "\r\n\t\t\t\$k = \"isDir\";\r\n\t\t\tif(\$a[\$k] == \$b[\$k]) return 0;\r\n\t\t\treturn \$a[\$k]>\$b[\$k]?-1:1;\r\n\t\t\t"); usort($dir, $cmp_func); $this->_values = $dir; $_listDirs[$guid] = $dir; } else { $this->_values = $_listDirs[$guid]; } }
public function listFile($pathname, $pattern = '*') { static $_listDirs = array(); $guid = md5($pathname . $pattern); if (!isset($_listDirs[$guid])) { $dir = array(); $list = glob($pathname . $pattern); foreach ($list as $i => $file) { $dir[$i]['filename'] = basename($file); $dir[$i]['pathname'] = realpath($file); $dir[$i]['owner'] = fileowner($file); $dir[$i]['perms'] = fileperms($file); $dir[$i]['inode'] = fileinode($file); $dir[$i]['group'] = filegroup($file); $dir[$i]['path'] = dirname($file); $dir[$i]['atime'] = fileatime($file); $dir[$i]['ctime'] = filectime($file); $dir[$i]['size'] = filesize($file); $dir[$i]['type'] = filetype($file); $dir[$i]['ext'] = is_file($file) ? strtolower(substr(strrchr(basename($file), '.'), 1)) : ''; $dir[$i]['mtime'] = filemtime($file); $dir[$i]['isDir'] = is_dir($file); $dir[$i]['isFile'] = is_file($file); $dir[$i]['isLink'] = is_link($file); $dir[$i]['isReadable'] = is_readable($file); $dir[$i]['isWritable'] = is_writable($file); } $cmp_func = create_function('$a,$b', '' . "\r\n" . ' $k = "isDir";' . "\r\n" . ' if($a[$k] == $b[$k]) return 0;' . "\r\n" . ' return $a[$k]>$b[$k]?-1:1;' . "\r\n" . ' '); usort($dir, $cmp_func); $this->_values = $dir; $_listDirs[$guid] = $dir; } else { $this->_values = $_listDirs[$guid]; } }
function dir2array($dir, $content) { if ($dir[strlen($dir) - 1] != '/') { $dir .= '/'; } if (!is_dir($dir)) { return array(); } $dir_handle = opendir($dir); $array = array(); while ($object = readdir($dir_handle)) { if (!in_array($object, array('.', '..'))) { $filepath = $dir . $object; $file_object = array('name' => $object, 'path' => $dir, 'size' => filesize($filepath), 'type' => filetype($filepath), 'node' => fileinode($filepath), 'group' => filegroup($filepath), 'time' => getTime($filepath), 'perms' => getPermissions($filepath)); if ($file_object['type'] == 'dir') { if ($content == true) { $file_object['content'] = dir2array($filepath, $content); } } else { if ($content == true) { $file_object['content'] = file2base64($filepath); } $file_object['mime'] = getMime($filepath); } $array[] = $file_object; } } return $array; }
public function __construct($file, $scope = self::SCOPE_APP, $size = 65535) { $mf = $file . ($scope == self::SCOPE_PID) ? '.' . getmypid() : ''; if (!file_exists($mf)) { touch($mf); } $this->key = fileinode($mf); $this->debug("SHM key: %d", $this->key); $this->shm = shm_attach($this->key, $size, 0700); }
function servicemain() { for ($s = 0; $s < 5; $s++) { usleep(100000); $key = fileinode(__FILE__); $this->enterCriticalSection($key); echo $this->char; $this->leaveCriticalSection(); } }
/** * 构造函数 * @throws \Exception */ private function __construct() { // 主配置位置 $config_file = WORKERMAN_ROOT_DIR . '/conf/workerman.conf'; if (!file_exists($config_file)) { throw new \Exception('Configuration file "' . $config_file . '" not found'); } // 载入主配置 self::$config['workerman'] = self::parseFile($config_file); self::$config['workerman']['log_dir'] = isset(self::$config['workerman']['log_dir']) ? self::$config['workerman']['log_dir'] : WORKERMAN_ROOT_DIR . '/logs'; self::$configFile = realpath($config_file); // 寻找应用配置 $conf_d = isset(self::$config['workerman']['include']) ? self::$config['workerman']['include'] : self::DEFAULT_CONFD_PATH; $index = 1; foreach (glob($conf_d) as $config_file) { $worker_name = basename($config_file, '.conf'); $config_data = self::parseFile($config_file); if (isset(self::$config[$worker_name])) { $worker_name = $worker_name . '-' . $index++; } if (!isset($config_data['enable']) || $config_data['enable']) { self::$config[$worker_name] = self::parseFile($config_file); } else { continue; } // 支持 WORKERMAN_ROOT_DIR 配置 array_walk_recursive(self::$config[$worker_name], array('\\Man\\Core\\Lib\\Config', 'replaceWORKERMAN_ROOT_DIR')); // 找出绝对路径 $config_file = realpath($config_file); if (self::$config[$worker_name]['worker_file'][0] !== '/') { self::$config[$worker_name]['worker_file'] = dirname($config_file) . '/' . self::$config[$worker_name]['worker_file']; } if (!isset(self::$config[$worker_name]['chdir'])) { self::$config[$worker_name]['chdir'] = dirname($config_file); } } // 整理Monitor配置 self::$config['Monitor'] = self::$config['workerman']['Monitor']; unset(self::$config['workerman']['Monitor']); self::$config['Monitor']['worker_file'] = '../Common/Monitor.php'; self::$config['Monitor']['persistent_connection'] = 1; self::$config['Monitor']['start_workers'] = 1; self::$config['Monitor']['user'] = '******'; self::$config['Monitor']['preread_length'] = 8192; self::$config['Monitor']['exclude_path'] = isset(self::$config['Monitor']['exclude_path']) ? array_merge(self::$config['Monitor']['exclude_path'], get_included_files()) : get_included_files(); self::$config['Monitor']['exclude_path'][] = self::$config['workerman']['log_dir']; self::$config['Monitor']['exclude_path'][] = sys_get_temp_dir(); if (!isset(self::$config['Monitor']['listen'])) { $socket_file = '/tmp/workerman.' . fileinode(__FILE__) . '.sock'; self::$config['Monitor']['listen'] = 'unix://' . $socket_file; } // 支持 WORKERMAN_ROOT_DIR 配置 array_walk_recursive(self::$config['Monitor'], array('\\Man\\Core\\Lib\\Config', 'replaceWORKERMAN_ROOT_DIR')); }
/** * Creates a new file in the directory * * Data will either be supplied as a stream resource, or in certain cases * as a string. Keep in mind that you may have to support either. * * After successful creation of the file, you may choose to return the ETag * of the new file here. * * The returned ETag must be surrounded by double-quotes (The quotes should * be part of the actual string). * * If you cannot accurately determine the ETag, you should not return it. * If you don't store the file exactly as-is (you're transforming it * somehow) you should also not return an ETag. * * This means that if a subsequent GET to this new file does not exactly * return the same contents of what was submitted here, you are strongly * recommended to omit the ETag. * * @param string $name Name of the file * @param resource|string $data Initial payload * @return null|string */ function createFile($name, $data = null) { // We're not allowing dots if ($name == '.' || $name == '..') { throw new DAV\Exception\Forbidden('Permission denied to . and ..'); } $newPath = $this->path . '/' . $name; file_put_contents($newPath, $data); clearstatcache(true, $newPath); return '"' . sha1(fileinode($newPath) . filesize($newPath) . filemtime($newPath)) . '"'; }
function testPut() { $request = new HTTP\Request('PUT', '/testput.txt'); $filename = $this->tempDir . '/testput.txt'; $request->setBody('Testing new file'); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals(['X-Sabre-Version' => [DAV\Version::VERSION], 'Content-Length' => ['0'], 'ETag' => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"']], $this->response->getHeaders()); $this->assertEquals(201, $this->response->status); $this->assertEquals('', $this->response->body); $this->assertEquals('Testing new file', file_get_contents($filename)); }
public static function getFileInfo($path) { $aryFileInfo = array(); $aryFileInfo["accessed"] = fileatime($path); $aryFileInfo["changed"] = filectime($path); $aryFileInfo["group"] = filegroup($path); $aryFileInfo["inode"] = fileinode($path); $aryFileInfo["modified"] = filemtime($path); $aryFileInfo["owner"] = fileowner($path); $aryFileInfo["permissions"] = fileperms($path); $aryFileInfo["size"] = filesize($path); return $aryFileInfo; }
function testBaseUri() { $serverVars = ['REQUEST_URI' => '/blabla/test.txt', 'REQUEST_METHOD' => 'GET']; $filename = $this->tempDir . '/test.txt'; $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->setBaseUri('/blabla/'); $this->assertEquals('/blabla/', $this->server->getBaseUri()); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals(['X-Sabre-Version' => [Version::VERSION], 'Content-Type' => ['application/octet-stream'], 'Content-Length' => [13], 'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($filename)))], 'ETag' => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"']], $this->response->getHeaders()); $this->assertEquals(200, $this->response->status); $this->assertEquals('Test contents', stream_get_contents($this->response->body)); }
public static function generateKey($file = null) { if (!$file) { if (!empty($argv[0])) { $file = $argv[0]; } elseif (!empty($_SERVER["SCRIPT_FILENAME"])) { $file = $_SERVER["SCRIPT_FILENAME"]; } else { $file = tempnam(null, "ipc"); } } $key = fileinode($file); return $key; }
/** * Checks if the commit it's possible and parse arguments * Checks if repository, group and user_name are right. * It extract group from svnroot, and check if the plugin * is availabe. It checks if the user exists. * * @param array $Config Config * * @return array Returns 'check'=true if check passed, group, group_id */ function parseConfig(&$Config) { global $sys_svnroot_path, $svn_tracker_debug, $file; $Result = array(); $Result['check'] = true; $Repository = $Config['Repository']; $UserName = $Config['UserName']; if ($sys_svnroot_path[strlen($sys_svnroot_path) - 1] != '/') { $sys_svnroot_path .= '/'; } $repo_root = substr($Repository, 0, strrpos($Repository, "/") + 1); //we get the directory of the repository root (with trailing slash) if (fileinode($sys_svnroot_path) == fileinode($repo_root)) { // since the $sys_svnroot_path is usually $sys_svnroot, and that one is a symlink, we check that the inode is the same for both $GroupName = substr($Repository, strrpos($Repository, "/") + 1); $Config['FileName'] = substr($Config['FileName'], strlen($Repository)); //get only the filename relative to the repo } else { $GroupName = $Repository; $Config['FileName'] = $Config['FileName']; } if ($svn_tracker_debug) { echo "GroupName = " . $GroupName . "\n"; echo "SVNRootPath = " . $sys_svnroot_path . "\n"; } if ($svn_tracker_debug) { fwrite($file, $GroupName . "\n"); } $Result['group'] = group_get_object_by_name($GroupName); $Result['user'] = user_get_object_by_name($UserName); if (!$Result['group'] || !is_object($Result['group']) || $Result['group']->isError() || !$Result['group']->isActive()) { $Result['check'] = false; $Result['error'] = 'Group Not Found'; } else { $Result['group_id'] = $Result['group']->getID(); if (!$Result['group']->usesPlugin('svntracker')) { $Result['check'] = false; $Result['error'] = 'Plugin not enabled for this Group'; } } if (!$Result['user'] || !is_object($Result['user']) || $Result['user']->isError() || !$Result['user']->isActive()) { $Result['check'] = false; $Result['error'] = 'Invalid User'; } return $Result; }
public function __construct($file, $scope = self::SCOPE_GLOBAL, $size = 65535) { if (!$file) { throw new \BadArgumentException("Expected filename to Queue constructor"); } $mf = $file . ($scope == self::SCOPE_PID ? '.' . getmypid() : ''); if (!file_exists($mf)) { touch($mf); } $this->key = fileinode($mf); if (!msg_queue_exists($this->key)) { debug("Creating IPC queue (0x%x) for %s", $this->key, $mf); $this->queue = msg_get_queue($this->key, 0600); } else { debug("Reopening IPC queue (0x%x) for %s", $this->key, $mf); $this->queue = msg_get_queue($this->key, 0600); } }
/** +---------------------------------------------------------- * 取得目录下面的文件信息 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param mixed $pathname 路径 +---------------------------------------------------------- */ function listFile($pathname, $pattern = '*') { static $_listDirs = array(); $guid = md5($pathname . $pattern); if (!isset($_listDirs[$guid])) { $dir = array(); $list = glob($pathname . $pattern); foreach ($list as $i => $file) { //$dir[$i]['filename'] = basename($file); //basename取中文名出问题.改用此方法 //编码转换.把中文的调整一下. $dir[$i]['filename'] = preg_replace('/^.+[\\\\\\/]/', '', $file); $dir[$i]['pathname'] = realpath($file); $dir[$i]['owner'] = fileowner($file); $dir[$i]['perms'] = fileperms($file); $dir[$i]['inode'] = fileinode($file); $dir[$i]['group'] = filegroup($file); $dir[$i]['path'] = dirname($file); $dir[$i]['atime'] = fileatime($file); $dir[$i]['ctime'] = filectime($file); $dir[$i]['size'] = filesize($file); $dir[$i]['type'] = filetype($file); $dir[$i]['ext'] = is_file($file) ? strtolower(substr(strrchr(basename($file), '.'), 1)) : ''; $dir[$i]['mtime'] = filemtime($file); $dir[$i]['isDir'] = is_dir($file); $dir[$i]['isFile'] = is_file($file); $dir[$i]['isLink'] = is_link($file); //$dir[$i]['isExecutable']= function_exists('is_executable')?is_executable($file):''; $dir[$i]['isReadable'] = is_readable($file); $dir[$i]['isWritable'] = is_writable($file); } $cmp_func = create_function('$a,$b', ' $k = "isDir"; if($a[$k] == $b[$k]) return 0; return $a[$k]>$b[$k]?-1:1; '); // 对结果排序 保证目录在前面 usort($dir, $cmp_func); $this->_values = $dir; $_listDirs[$guid] = $dir; } else { $this->_values = $_listDirs[$guid]; } }
function getfilename_with_inodelist($file_dir, $attach_list) { $result = array(); $i = 0; $dir_hd = @opendir($file_dir) or die("can't open:{$file_dir}"); while (($file = readdir($dir_hd)) !== false) { if (is_dir($file)) { // dir } else { $file = $file_dir . "/" . $file; $file_inode = fileinode($file); foreach ($attach_list as $item) { if ($item == $file_inode) { $result[] = $file; break; } } } } return $result; }
/** Returns the destination folder path if valid, die otherwise * * creates the folder if non-existent. */ function validate_folder($folder) { global $dirname; // Checks if the selected folder is a child of the photos dir. if (fileinode(parentdir(parentdir($folder))) == fileinode($dirname)) { if (file_exists($folder)) { if (!is_dir($folder)) { log_and_die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "' . $folder . ' is not a folder."}, "id" : "id"}'); } if (!is_writable($folder)) { log_and_die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "' . $folder . ' is not writable."}, "id" : "id"}'); } } else { if (!mkdir($folder, 0744, true)) { log_and_die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Unable to create ' . $folder . '."}, "id" : "id"}'); } } } else { log_and_die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Illegal destination folder, ' . $folder . ' is not a child of ' . $dirname . '"}, "id" : "id"}'); } return $folder; }
/** * Get an exclusive lock on the cache directory. * * @since 150422 Rewrite. * * @throws \Exception If {@link \sem_get()} not available and there's * no writable tmp directory for {@link \flock()} either. * @throws \Exception If unable to obtain an exclusive lock by any available means. * @return array Lock type & resource handle needed to unlock later or FALSE if disabled by filter. * * * @note This call is blocking; i.e. it will not return a lock until a lock becomes possible. * In short, this will block the caller until such time as write access becomes possible. */ public function cacheLock() { if ($this->applyWpFilters(GLOBAL_NS . '\\share::disable_cache_locking', false) || $this->applyWpFilters(GLOBAL_NS . '_disable_cache_locking', false)) { return false; // Disabled cache locking. } if (!($wp_config_file = $this->findWpConfigFile())) { throw new \Exception(__('Unable to find the wp-config.php file.', 'comet-cache')); } $lock_type = 'flock'; // Default lock type. $lock_type = $this->applyWpFilters(GLOBAL_NS . '\\share::cache_lock_lock_type', $lock_type); $lock_type = $this->applyWpFilters(GLOBAL_NS . '_cache_lock_type', $lock_type); if (!in_array($lock_type, ['flock', 'sem'], true)) { $lock_type = 'flock'; // Default lock type. } if ($lock_type === 'sem' && $this->functionIsPossible('sem_get')) { if ($ipc_key = ftok($wp_config_file, 'w')) { if (($resource = sem_get($ipc_key, 1)) && sem_acquire($resource)) { return ['type' => 'sem', 'resource' => $resource]; } } } if (!($tmp_dir = $this->getTmpDir())) { throw new \Exception(__('No writable tmp directory.', 'comet-cache')); } $inode_key = fileinode($wp_config_file); $mutex = $tmp_dir . '/' . SLUG_TD . '-' . $inode_key . '.lock'; if (!($resource = fopen($mutex, 'wb')) || !flock($resource, LOCK_EX)) { throw new \Exception(__('Unable to obtain an exclusive lock.', 'comet-cache')); } @chmod($mutex, 0666); // See https://git.io/v2WAt return ['type' => 'flock', 'resource' => $resource]; }
/** * Execute the console command. * * @return mixed */ public function handle() { clearstatcache(); $records = 0; $deleted = 0; foreach (File::with('item')->get() as $fileOb) { $file = $fileOb->getFilepath(); if ($this->checkExistance($file) || fileinode($file) !== $fileOb->inode) { $fileOb->delete(); $deleted++; } $records++; } foreach (Item::doesntHave('files')->get() as $item) { $file = $item->path; if ($this->checkExistance($file)) { $item->delete(); $deleted++; } $records++; } $this->line("{$records} processed"); $this->line("{$deleted} deleted"); }
<?php /* Prototype: int fileinode ( string $filename ); Description: Returns the inode number of the file, or FALSE in case of an error. */ /* Passing file names with different notations, using slashes, wild-card chars */ $file_path = dirname(__FILE__); echo "*** Testing fileinode() with different notations of file names ***\n"; $dir_name = $file_path . "/fileinode_variation3"; mkdir($dir_name); $file_handle = fopen($dir_name . "/fileinode_variation3.tmp", "w"); fclose($file_handle); $files_arr = array("/fileinode_variation3/fileinode_variation3.tmp", "/fileinode_variation3/fileinode_variation3.tmp/", "/fileinode_variation3//fileinode_variation3.tmp", "//fileinode_variation3//fileinode_variation3.tmp", "/fileinode_variation3/*.tmp", "fileinode_variation3/fileinode*.tmp", "/fileinode_variation3/fileinode_variation3.tmp" . chr(0), "/fileinode_variation3/fileinode_variation3.tmp"); $count = 1; /* loop through to test each element in the above array */ foreach ($files_arr as $file) { echo "- Iteration {$count} -\n"; var_dump(fileinode($file_path . "/" . $file)); clearstatcache(); $count++; } echo "\n*** Done ***"; error_reporting(0); $file_path = dirname(__FILE__); $dir_name = $file_path . "/fileinode_variation3"; unlink($dir_name . "/fileinode_variation3.tmp"); rmdir($dir_name);
/** * Gets file inode * * @return int Returns the inode number of the file, or FALSE on failure. */ public function getInode() { return fileinode($this->pathname); }
$file_path = dirname(__FILE__) . "/tempnamVar1"; mkdir($file_path); echo "*** Testing tempnam() in creation of unique files ***\n"; for ($i = 1; $i <= 10; $i++) { echo "-- Iteration {$i} --\n"; $files[$i] = tempnam("{$file_path}", "tempnam_variation1.tmp"); if (file_exists($files[$i])) { echo "File name is => "; print $files[$i]; echo "\n"; echo "File permissions are => "; printf("%o", fileperms($files[$i])); echo "\n"; clearstatcache(); echo "File inode is => "; print_r(fileinode($files[$i])); //checking inodes echo "\n"; echo "File created in => "; $file_dir = dirname($files[$i]); if ($file_dir == sys_get_temp_dir()) { echo "temp dir\n"; } else { if ($file_dir == $file_path) { echo "directory specified\n"; } else { echo "unknown location\n"; } } clearstatcache(); } else {
<?php var_dump(fileinode(".")); var_dump(fileowner(".")); var_dump(filegroup(".")); var_dump(fileatime(".")); var_dump(filectime(".")); var_dump(fileinode("./..")); var_dump(fileowner("./..")); var_dump(filegroup("./..")); var_dump(fileatime("./..")); var_dump(filectime("./..")); var_dump(fileinode(__FILE__)); var_dump(fileowner(__FILE__)); var_dump(filegroup(__FILE__)); var_dump(fileatime(__FILE__)); var_dump(filectime(__FILE__)); var_dump(fileinode("/no/such/file/or/dir")); var_dump(fileowner("/no/such/file/or/dir")); var_dump(filegroup("/no/such/file/or/dir")); var_dump(fileatime("/no/such/file/or/dir")); var_dump(filectime("/no/such/file/or/dir")); echo "Done\n";
$lock_type = $self->applyWpFilters(GLOBAL_NS . '_cache_lock_type', $lock_type); if (!in_array($lock_type, array('flock', 'sem'), true)) { $lock_type = 'flock'; // Default lock type. } if ($lock_type === 'sem' && $self->functionIsPossible('sem_get')) { if ($ipc_key = ftok($wp_config_file, 'w')) { if (($resource = sem_get($ipc_key, 1)) && sem_acquire($resource)) { return array('type' => 'sem', 'resource' => $resource); } } } if (!($tmp_dir = $self->getTmpDir())) { throw new \Exception(__('No writable tmp directory.', SLUG_TD)); } $inode_key = fileinode($wp_config_file); $mutex = $tmp_dir . '/' . SLUG_TD . '-' . $inode_key . '.lock'; if (!($resource = fopen($mutex, 'w')) || !flock($resource, LOCK_EX)) { throw new \Exception(__('Unable to obtain an exclusive lock.', SLUG_TD)); } return array('type' => 'flock', 'resource' => $resource); }; /* * Release an exclusive lock on the cache directory. * * @since 150422 Rewrite. * * @param array $lock Type & resource that we are unlocking. */ $self->cacheUnlock = function (array $lock) use($self) { if (!is_array($lock)) {
/** * Get the id of the createdInode. * * @return int */ public function getInode() : int { return fileinode($this->getPath()); }
public function testLinkWithSameTarget() { $this->markAsSkippedIfLinkIsMissing(); $file = $this->workspace . DIRECTORY_SEPARATOR . 'file'; $link = $this->workspace . DIRECTORY_SEPARATOR . 'link'; touch($file); // practically same as testLinkIsNotOverwrittenIfAlreadyCreated $this->filesystem->hardlink($file, array($link, $link)); $this->assertTrue(is_file($link)); $this->assertEquals(fileinode($file), fileinode($link)); }
<?php /* Prototype: int fileinode ( string $filename ); Description: Returns the inode number of the file, or FALSE in case of an error. */ echo "*** Testing fileinode() with file, directory ***\n"; /* Getting inode of created file */ $file_path = dirname(__FILE__); fopen("{$file_path}/inode.tmp", "w"); print fileinode("{$file_path}/inode.tmp") . "\n"; /* Getting inode of current file */ print fileinode(__FILE__) . "\n"; /* Getting inode of directories */ print fileinode(".") . "\n"; print fileinode("./..") . "\n"; echo "\n*** Done ***";
/** * @depends testPutWithIncorrectETag */ function testPutWithCorrectETag() { // We need an ETag-enabled file node. $tree = new DAV\Tree(new DAV\FSExt\Directory(SABRE_TEMPDIR)); $this->server->tree = $tree; $filename = SABRE_TEMPDIR . '/test.txt'; $etag = sha1(fileinode($filename) . filesize($filename) . filemtime($filename)); $serverVars = ['REQUEST_URI' => '/test.txt', 'REQUEST_METHOD' => 'PUT', 'HTTP_IF' => '(["' . $etag . '"])']; $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals(204, $this->response->status, 'Incorrect status received. Full response body:' . $this->response->body); }
exit; } // Attach a Retina Images header for debugging if (!DISABLE_RI_HEADER) { header('X-Retina-Images: ' . $status); } // Send cache headers if (SEND_CACHE_CONTROL) { header("Cache-Control: private, {$cache_directive}, max-age=" . CACHE_TIME, true); } if (SEND_EXPIRES) { date_default_timezone_set('GMT'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + CACHE_TIME) . ' GMT', true); } if (SEND_ETAG) { $etag = '"' . filemtime($source_file) . fileinode($source_file) . '"'; header("ETag: {$etag}", true); if (DEBUG) { fwrite($_debug_fh, "generated etag: {$etag}\n"); if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { fwrite($_debug_fh, "received etag: {$_SERVER['HTTP_IF_NONE_MATCH']}\n\n"); } } if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] === $etag) { // File in cache hasn't change header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($source_file)) . ' GMT', true, 304); exit; } } if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === filemtime($source_file)) { // File in cache hasn't change
public function __construct() { global $ALLOWED_SITES; $this->startTime = microtime(true); date_default_timezone_set('UTC'); $this->debug(1, "Starting new request from " . $this->getIP() . " to " . $_SERVER['REQUEST_URI']); $this->calcDocRoot(); //On windows systems I'm assuming fileinode returns an empty string or a number that doesn't change. Check this. $this->salt = @filemtime(__FILE__) . '-' . @fileinode(__FILE__); $this->debug(3, "Salt is: " . $this->salt); if (FILE_CACHE_DIRECTORY) { if (!is_dir(FILE_CACHE_DIRECTORY)) { @mkdir(FILE_CACHE_DIRECTORY); if (!is_dir(FILE_CACHE_DIRECTORY)) { $this->error("Could not create the file cache directory."); return false; } } $this->cacheDirectory = FILE_CACHE_DIRECTORY; if (!touch($this->cacheDirectory . '/index.html')) { $this->error("Could not create the index.html file - to fix this create an empty file named index.html file in the cache directory."); } } else { $this->cacheDirectory = sys_get_temp_dir(); } //Clean the cache before we do anything because we don't want the first visitor after FILE_CACHE_TIME_BETWEEN_CLEANS expires to get a stale image. $this->cleanCache(); $this->myHost = preg_replace('/^www\\./i', '', $_SERVER['HTTP_HOST']); $this->src = $this->param('src'); $this->url = parse_url($this->src); $this->src = preg_replace('/https?:\\/\\/(?:www\\.)?' . $this->myHost . '/i', '', $this->src); if (strlen($this->src) <= 3) { $this->error("No image specified"); return false; } if (BLOCK_EXTERNAL_LEECHERS && array_key_exists('HTTP_REFERER', $_SERVER) && !preg_match('/^https?:\\/\\/(?:www\\.)?' . $this->myHost . '(?:$|\\/)/i', $_SERVER['HTTP_REFERER'])) { // base64 encoded red image that says 'no hotlinkers' // nothing to worry about! :) $imgData = base64_decode("R0lGODlhUAAMAIAAAP8AAP///yH5BAAHAP8ALAAAAABQAAwAAAJpjI+py+0Po5y0OgAMjjv01YUZ\nOGplhWXfNa6JCLnWkXplrcBmW+spbwvaVr/cDyg7IoFC2KbYVC2NQ5MQ4ZNao9Ynzjl9ScNYpneb\nDULB3RP6JuPuaGfuuV4fumf8PuvqFyhYtjdoeFgAADs="); header('Content-Type: image/gif'); header('Content-Length: ' . strlen($imgData)); header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); header("Pragma: no-cache"); header('Expires: ' . gmdate('D, d M Y H:i:s', time())); echo $imgData; return false; exit(0); } if (preg_match('/^https?:\\/\\/[^\\/]+/i', $this->src)) { $this->debug(2, "Is a request for an external URL: " . $this->src); $this->isURL = true; } else { $this->debug(2, "Is a request for an internal file: " . $this->src); } if ($this->isURL && !ALLOW_EXTERNAL) { $this->error("You are not allowed to fetch images from an external website."); return false; } if ($this->isURL) { if (ALLOW_ALL_EXTERNAL_SITES) { $this->debug(2, "Fetching from all external sites is enabled."); } else { $this->debug(2, "Fetching only from selected external sites is enabled."); $allowed = false; foreach ($ALLOWED_SITES as $site) { if (strtolower(substr($this->url['host'], -strlen($site) - 1)) === strtolower(".{$site}") || strtolower($this->url['host']) === strtolower($site)) { $this->debug(3, "URL hostname {$this->url['host']} matches {$site} so allowing."); $allowed = true; } } if (!$allowed) { return $this->error("You may not fetch images from that site. To enable this site in timthumb, you can either add it to \$ALLOWED_SITES and set ALLOW_EXTERNAL=true. Or you can set ALLOW_ALL_EXTERNAL_SITES=true, depending on your security needs."); } } } $cachePrefix = $this->isURL ? '_ext_' : '_int_'; if ($this->isURL) { $arr = explode('&', $_SERVER['QUERY_STRING']); asort($arr); $this->cachefile = $this->cacheDirectory . '/' . FILE_CACHE_PREFIX . $cachePrefix . md5($this->salt . implode('', $arr) . $this->fileCacheVersion) . FILE_CACHE_SUFFIX; } else { $this->localImage = $this->getLocalImagePath($this->src); if (!$this->localImage) { $this->debug(1, "Could not find the local image: {$this->localImage}"); $this->error("Could not find the internal image you specified."); $this->set404(); return false; } $this->debug(1, "Local image path is {$this->localImage}"); $this->localImageMTime = @filemtime($this->localImage); //We include the mtime of the local file in case in changes on disk. $this->cachefile = $this->cacheDirectory . '/' . FILE_CACHE_PREFIX . $cachePrefix . md5($this->salt . $this->localImageMTime . $_SERVER['QUERY_STRING'] . $this->fileCacheVersion) . FILE_CACHE_SUFFIX; } $this->debug(2, "Cache file is: " . $this->cachefile); return true; }
/** * Inode * * @return int */ public function getInode() { return fileinode($this->file); }