fsspec / fsspec/s3fs

Empty files with trailing slash are sometimes treated as directories and sometimes treated as regular files

Open
#439 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1k
Forks
305
Avg merge
22h 37m
Merged PRs (30d)
4

Description

import boto3
from s3fs import S3FileSystem
from pprint  import pprint
TEST_AWS_S3_PORT = 5555
TEST_AWS_ENDPOINT_URL = f'http://127.0.0.1:{TEST_AWS_S3_PORT}/'

boto_client = boto3.client('s3', endpoint_url=TEST_AWS_ENDPOINT_URL)
fs = S3FileSystem(client_kwargs={'endpoint_url': TEST_AWS_ENDPOINT_URL})

boto_client.create_bucket(Bucket='test-bucket')
boto_client.put_object(
    Bucket='test-bucket', Key='empty-dir/', Body='',
)

pprint(fs.ls('test-bucket', detail=True))
pprint(fs.info('test-bucket/empty-dir/'))
print(fs.isdir('test-bucket/empty-dir/'))
print(fs.ls('test-bucket/empty-dir/'))

The code above first creates an empty file using that ends with a trailing slash. Then it tries to run s3fs's ls on the parent directory, which identifies that file as a directory;

[{'Key': 'test-bucket/empty-dir',
  'Size': 0,
  'StorageClass': 'DIRECTORY',
  'name': 'test-bucket/empty-dir',
  'size': 0,
  'type': 'directory'}]

Also the second and the third calls (info() and isdir()) claims it is a directory;

{'Key': 'test-bucket/empty-dir',
 'Size': 0,
 'StorageClass': 'DIRECTORY',
 'name': 'test-bucket/empty-dir',
 'size': 0,
 'type': 'directory'}
True

though when we try to do ls/walk etc it behaves like a file. The following is the result of .ls('bucket/empty-dir/');

['test-bucket/empty-dir/']

instead I would have expected it to return an empty list

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided boto3 and S3FileSystem reproduction against the configured S3 endpoint, then trace the implementations behind ls(), info(), and isdir() for a zero-byte key ending in '/'. Done means the key is classified consistently across parent listing, info, isdir, and ls, with ls('test-bucket/empty-dir/') returning the expected empty list.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.