Skip to content
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

trailing slashes for "leaf" directories, usage of '\\' #31

Closed
h5rdly opened this issue Dec 31, 2016 · 4 comments
Closed

trailing slashes for "leaf" directories, usage of '\\' #31

h5rdly opened this issue Dec 31, 2016 · 4 comments

Comments

@h5rdly
Copy link

h5rdly commented Dec 31, 2016

Hi,

I Wanted to ask regarding some parsing issues I'm having.

On Windows, Zipfile listings look like this:
'Folder/Folder2/FILE'
'Folder/Folder2/EmptyFolder/'

With Rarfile it's:
u'Folder\\Folder2\\FILE'
u'Folder\\Folder2\\EmptyFolder'

This causes obstacles -

  1. With the lack of trailing slashes, I need extra info to know if FILE a file or a folder.
  2. I would need to parse windows and linux rars differently, as well as rarfiles and zipfiles, gzipfiles etc.

Would it be possible to add trailing slashes to last-in-line folders, and/or use Python's generic platform agnostic '/' instead of '\\'? That would be awesome, as it would allow to utilize a single generic archive parsing.

Thanks.

@XenHat
Copy link

XenHat commented Jan 3, 2017

The option to use a different path separator already exists. Did you take a look at the documentation linked in the README file?
The option you are looking for is called PATH_SEP, see https://rarfile.readthedocs.io/en/latest/api.html#rarfile.PATH_SEP

Edit: about 1.; You can use os.path.isdir in Python. See https://docs.python.org/3/library/os.path.html#os.path.isdir for documentation, replace /3/ with /2/ in the URL for python 2.x

@markokr
Copy link
Owner

markokr commented Jan 3, 2017

Actually in rarfile 3.0 the default path_sep is '/' now.

But rarfile does not have any special handling for dirs, you are supposed to check mode.

Seems ZIP format stores final '/' in archive, while RAR does not. Should rarfile append '/' to dirs?

@h5rdly
Copy link
Author

h5rdly commented Jan 3, 2017

@XenHat
I was not aware of rarfile.PATH_SEP = '/', thanks for the reference.

is_dir() isn't much use for traversing the archive, like in a file manager. One can get the dir info either way, but it's an extra check on every "leaf" folder, might add up on vast archives so it's a bit of a shame. Also not compatible with the Zipfile style.

@markokr
I'm obviously biased, but it would make parsing smooth, as it would just need the pathname to figure dirs from files.
Even looking at a listing, it's sometimes hard to tell if something like "THIS" or "notes" is a file or a directory.
The question is really, why not? :)

@XenHat
Copy link

XenHat commented Jan 6, 2017

Seems ZIP format stores final '/' in archive, while RAR does not. Should rarfile append '/' to dirs?

Since the RARFile information says it tries to behave as closely to zipfile as possible, I would say yes.

Footnote: I wonder if the lack of trailing slash would cause my odd problem with some archives (#29 )since it tends to happen with archives with multiple subfolder levels (the most common example I have is libboost, which is huge, tree-wise)?

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

3 participants