public function url_stat($path, $flags)
{
// Defaults
$out = array();
$out[0] = $out['dev'] = 0;
$out[1] = $out['ino'] = 0;
$out[2] = $out['mode'] = 0;
$out[3] = $out['nlink'] = 0;
$out[4] = $out['uid'] = 0;
$out[5] = $out['gid'] = 0;
$out[6] = $out['rdev'] = 0;
$out[7] = $out['size'] = 0;
$out[8] = $out['atime'] = 0;
$out[9] = $out['mtime'] = 0;
$out[10] = $out['ctime'] = 0;
$out[11] = $out['blksize'] = 0;
$out[12] = $out['blocks'] = 0;
$this->path = $path;
list($protocol, $bucket, $object_name) = $this->parse_path($this->path);
$file = null;
$mode = 0;
if ($object_name)
{
$response = $this->client($protocol)->list_objects($bucket, array(
'prefix' => $object_name
));
if (!$response->isOK())
{
return $out;
}
// Ummm... yeah...
if (is_object($response->body))
{
$file = $response->body->Contents[0];
}
else
{
$body = simplexml_load_string($response->body);
$file = $body->Contents[0];
}
}
else
{
$response = $this->client($protocol)->list_objects($bucket);
if (!$response->isOK())
{
return $out;
}
}
/*
Type & Permission bitwise values (only those that pertain to S3).
Simulate the concept of a "directory". Nothing has an executable bit because there's no executing on S3.
Reference: http://docstore.mik.ua/orelly/webprog/pcook/ch19_13.htm
0100000 => type: regular file
0040000 => type: directory
0000400 => owner: read permission
0000200 => owner: write permission
0000040 => group: read permission
0000020 => group: write permission
0000004 => others: read permission
0000002 => others: write permission
*/
// File or directory?
// @todo: Add more detailed support for permissions. Currently only takes OWNER into account.
if (!$object_name) // Root of the bucket
{
$mode = octdec('0040777');
}
elseif ($file)
{
$mode = (str_replace('//', '/', $object_name . '/') === (string) $file->Key) ? octdec('0040777') : octdec('0100777'); // Directory, Owner R/W : Regular File, Owner R/W
}
else
{
$mode = octdec('0100777');
}
// Update stat output
$out[2] = $out['mode'] = $mode;
$out[4] = $out['uid'] = (isset($file) ? (string) $file->Owner->ID : 0);
$out[7] = $out['size'] = (isset($file) ? (string) $file->Size : 0);
$out[8] = $out['atime'] = (isset($file) ? date('U', strtotime((string) $file->LastModified)) : 0);
$out[9] = $out['mtime'] = (isset($file) ? date('U', strtotime((string) $file->LastModified)) : 0);
$out[10] = $out['ctime'] = (isset($file) ? date('U', strtotime((string) $file->LastModified)) : 0);
return $out;
}