Skip to content

listdir() should return a list of directories and files #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dorianamouroux opened this issue Jul 3, 2016 · 2 comments
Open

listdir() should return a list of directories and files #7

dorianamouroux opened this issue Jul 3, 2016 · 2 comments

Comments

@dorianamouroux
Copy link
Contributor

Hi,

The method listdir() should return a list of directories and files according to the Django documentation.
You just return an empty list for directories and a list of all files (with the name of directory(ies) in the name).
I understand the idea behind it, we can get the full list of files inside a blob with only one API call. We can then manage file with the full path.

I think that doesn't really matter how much API calls we do, because Azure has no limit regarding API calls, and we don't need performance for a such action. We mostly need storage for static file and media file management, and media file management doesn't call listdir as far as I know. collectstatic --clear does but we don't need performance for this. The storage should better be Django compliant to be sure we don't have any compatibility issues on future Django releases.

The solution would be to check all names we got from list_blobs. If it contains a slash, it's a directory, we cut off everything after it and add it to the directory list. If there is no slash, it's a file, we can add it to the file list.

I can do it and submit a PR if you want.

Cheers !

@kevin-brown
Copy link
Contributor

Is this behaviour causing any issues at the moment?


Part of the issue here is that Windows Azure doesn't actually have a concept of "directories". The files stored in Azure include the slashes and other "directory" indicators, but it is not possible to create a directory that contains no files.

The list of directories is used by collectstatic to clear the directory of all files, and to make sure it's cleared, which should be fine. Again, Azure automatically "deletes" the directory if there are no files in it and the storage backend should report that the directory doesn't exist.

You can read more at the following Stack Overflow question: Windows Azure: How to create sub directory in a blob container


Next week I'll get in contact with the Django team to confirm that this matches their expected behaviour for file systems without a strong concept of directories.

@dorianamouroux
Copy link
Contributor Author

I didn't encounter any issues from this.
The concept of directories is something abstracted by Azure, you can create a file named a/b/c/d/test.txt even if those directories (a, b, c and d) don't exist indeed.
I think that's a good thing for a storage backend in Django because the base storage class doesn't implement any method to create or remove repositories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants