Opened 6 years ago

Closed 5 years ago

#7137 closed defect (wontfix)

vsizip: zip files with only one file aren't considered 'directories'.

Reported by: tveastman Owned by: warmerdam
Priority: normal Milestone: closed_because_of_github_migration
Component: default Version: unspecified
Severity: normal Keywords: vsi vsizip ReadDir ReadDirRecursive
Cc: robert.coup@…

Description

If a .zip file only contains one file, VSIStatL doesn't consider it a directory. Even though its contents can be read with ReadDir() and ReadDirRecursive.

A zip file containing two files can be listed like a directory, and VSIStatL says it's a directory:

>>> gdal.ReadDir('/vsizip//home/vagrant/host/tmp/two-files.zip')
['a-text-file.txt', 'another-text-file.txt']
>>> gdal.VSIStatL('/vsizip//home/vagrant/host/tmp/two-files.zip').IsDirectory()
1

A zip file containing one file can be listed like a directory, but VSIStatL says it's NOT a directory:

>>> gdal.ReadDir('/vsizip//home/vagrant/host/tmp/one-file.zip')
['a-text-file.txt']
>>> gdal.VSIStatL('/vsizip//home/vagrant/host/tmp/one-file.zip').IsDirectory()
0

My assumption would be that anywhere you can call ReadDir() would be IsDirectory() -> 1, but this is not the current behaviour.

Change History (4)

comment:1 by Even Rouault, 6 years ago

This is probably an arguable behaviour, but was done on purpose. If foo.zip is made of a single-file bar, then /vsizip/foo.zip is an alias of /vsizip/foo.zip/bar

comment:2 by tveastman, 6 years ago

I see now that the 'alias' behaviour you describe is documented: 'Syntactic sugar: if the .zip file contains only one file located at its root, just mentioning "/vsizip/path/to/the/file.zip" will work'

In this case, my opinion is that the behaviour of IsDirectory() should be updated.

I am using IsDirectory() to know if it's safe or sane to call ReadDir(). So what I think should happen is:

gdal.VSIStatL('/path/to/a.zip').IsDirectory() should return 0 (and does return 0)

gdal.VSIStatL('/vsizip//path/to/a.zip').IsDirectory() should return 1 (and currently does not return 1).

I propose that IsDirectory() should always return 1 on paths were you can call ReadDir() and expect to get a result.

comment:3 by Even Rouault, 6 years ago

I propose that IsDirectory() should always return 1 on paths were you can call ReadDir() and expect to get a result.

If we want to keep the syntaxic sugar, gdal.VSIStatL('/vsizippath/to/a.zip').IsDirectory() on a a.zip that contains a single file should return 0.

comment:4 by Even Rouault, 5 years ago

Milestone: closed_because_of_github_migration
Resolution: wontfix
Status: newclosed

This ticket has been automatically closed because Trac is no longer used for GDAL bug tracking, since the project has migrated to GitHub. If you believe this ticket is still valid, you may file it to https://github.com/OSGeo/gdal/issues if it is not already reported there.

Note: See TracTickets for help on using tickets.