{"action":"created","issue":{"url":"https://api.github.com/repos/aws/aws-sdk-php/issues/619","labels_url":"https://api.github.com/repos/aws/aws-sdk-php/issues/619/labels{/name}","comments_url":"https://api.github.com/repos/aws/aws-sdk-php/issues/619/comments","events_url":"https://api.github.com/repos/aws/aws-sdk-php/issues/619/events","html_url":"https://github.com/aws/aws-sdk-php/issues/619","id":86617389,"number":619,"title":"Surprising is_dir() behaviour in S3 StreamWrapper","user":{"login":"UlrichEckhardt","id":8566055,"avatar_url":"https://avatars.githubusercontent.com/u/8566055?v=3","gravatar_id":"","url":"https://api.github.com/users/UlrichEckhardt","html_url":"https://github.com/UlrichEckhardt","followers_url":"https://api.github.com/users/UlrichEckhardt/followers","following_url":"https://api.github.com/users/UlrichEckhardt/following{/other_user}","gists_url":"https://api.github.com/users/UlrichEckhardt/gists{/gist_id}","starred_url":"https://api.github.com/users/UlrichEckhardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UlrichEckhardt/subscriptions","organizations_url":"https://api.github.com/users/UlrichEckhardt/orgs","repos_url":"https://api.github.com/users/UlrichEckhardt/repos","events_url":"https://api.github.com/users/UlrichEckhardt/events{/privacy}","received_events_url":"https://api.github.com/users/UlrichEckhardt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-09T14:26:15Z","updated_at":"2015-06-12T20:40:00Z","closed_at":null,"body":"We're currently migrating a file-based storage to one based on S3. For ease of use and flexibility, we are using the StreamWrapper class to access S3. During the migration, we have found an issue concerning the handling of directories. Testing various directories using PHP's `is_dir()` function, we got these results:\r\n```\r\ns3://my-bucket exists\r\ns3://my-bucket is a directory\r\ns3://my-bucket/ exists\r\ns3://my-bucket/ is a directory:\r\ns3://my-bucket/test doesn't exist\r\ns3://my-bucket/test is NOT a directory\r\ns3://my-bucket/test/ exists\r\ns3://my-bucket/test/ is a directory:\r\ns3://my-bucket/var doesn't exist\r\ns3://my-bucket/var is NOT a directory\r\ns3://my-bucket/var/ exists\r\ns3://my-bucket/var/ is a directory:\r\ns3://my-bucket/var/test exists\r\ns3://my-bucket/var/test is a directory:\r\ns3://my-bucket/var/test/ exists\r\ns3://my-bucket/var/test/ is a directory:\r\n```\r\nThe issue is the different treatment of `s3://my-bucket/test` and `s3://my-bucket/test/`, i.e. with and without trailing backslash. In my eyes, the trailing slash should be ignored, like it is both for the bucket itself (e.g. `s3://my-bucket/`) and for subdirectories (`s3://my-bucket/var/test/`).\r\n\r\nNotes:\r\n * I haven't even tried nasty stuff like `s3://my-bucket/var/test/.`, `s3://my-bucket/var//test` or `s3://my-bucket/../some-other-bucket/secret-stuff`.\r\n * We initially used a commandline utility to sync some directories, which created `s3://my-bucket/var/foo` and `s3://my-bucket/var/bar`, but without the empty object `s3://my-bucket/var` that seems to be required to recognize this as directory at all. Needless to say that this added to our frustration with our new toy. However, I don't want to call this an issue with the SDK, because it might as well have been our fault or the commandline utility's. Still, if you see any way to handle this case more gracefully, I would appreciate it.\r\n * In general, I wonder which permissions are required to create a directory with `mkdir()`? I would expect it to only require `s3:putObject`, but that didn't work. This might be related to what the `StreamWrapper` tries to do but I can't tell because I don't understand enough what's going on.\r\n * There is also surprising behaviour concerning the function `file_get_contents()` (see also https://github.com/aws/aws-sdk-php/issues/609), in that its result differs between `s3://my-bucket/test/` (empty string and no warning or error from PHP) and `s3://my-bucket/test` (error message \"The specified key does not exist.\" as return value, like in issue #609). On other dirs but the root dir, it always returns the error string, only on the root dirs it depends on the trailing slash.\r\n * Another interesting thing is the `scandir()` behaviour, which in turn completely ignores the trailing slash on a directory. However, it ignores when the object in question is not a directory, in which case it returns an empty array instead of the expected `false`."},"comment":{"url":"https://api.github.com/repos/aws/aws-sdk-php/issues/comments/111608130","html_url":"https://github.com/aws/aws-sdk-php/issues/619#issuecomment-111608130","issue_url":"https://api.github.com/repos/aws/aws-sdk-php/issues/619","id":111608130,"user":{"login":"jeremeamia","id":107867,"avatar_url":"https://avatars.githubusercontent.com/u/107867?v=3","gravatar_id":"","url":"https://api.github.com/users/jeremeamia","html_url":"https://github.com/jeremeamia","followers_url":"https://api.github.com/users/jeremeamia/followers","following_url":"https://api.github.com/users/jeremeamia/following{/other_user}","gists_url":"https://api.github.com/users/jeremeamia/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremeamia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremeamia/subscriptions","organizations_url":"https://api.github.com/users/jeremeamia/orgs","repos_url":"https://api.github.com/users/jeremeamia/repos","events_url":"https://api.github.com/users/jeremeamia/events{/privacy}","received_events_url":"https://api.github.com/users/jeremeamia/received_events","type":"User","site_admin":false},"created_at":"2015-06-12T20:40:00Z","updated_at":"2015-06-12T20:40:00Z","body":"Thanks for bringing this up. We are working on a response."}}