adamhathcock/sharpcompress

ArchiveEntry.Key is dependent on the archivetype

evpxregu opened this issue · 4 comments

Hi,

When I run the following code the directory seperator in the IArchiveEntry.Key is different for different archive types.

var _archive = new ArchiveFactory.Open(file, options);
foreach (var entry in _archive.Entries)
{
    Console.WriteLine(entry.Key);
}

Output for a .rar file:

subfolder\folder in subfolder\test fiel in sub-sub-subfolder.txt
subfolder\test fiel in sub-subfolder.txt
subfolder\folder in subfolder

output for a .zip file

subfolder/folder in subfolder/test fiel in sub-sub-subfolder.txt
subfolder/test fiel in sub-subfolder.txt
subfolder/folder in subfolder 0

Is this by design or a bug? Both archives are created on the same computer.

It seems likely there's a bug in creating where I hardcoded the path separator. I'm not sure I should use he OS's separator or always pick one.

The archive specs may have one specifically. I'll have to look it up.

#114

You've got a hardcoded path separator issue in your RAR extractor
https://github.com/adamhathcock/sharpcompress/blob/master/src/SharpCompress/Common/Rar/Headers/FileHeader.cs#L168

Dumping the switch statement in favour of this ought to fix it:

if (Path.DirectorySeparatorChar == '/')
{
	return path.Replace('\\', '/');
}
else if (Path.DirectorySeparatorChar == '\\')
{
	return path.Replace('/', '\\');
}

RAR always wants a \ as it's path separator.
Note:
Haven't tested this on create, hence why I'm not running up a pull request, but I don't see any reason for it to fail.

I'll look into this soon. I was thinking archive formats want something specific and SharpCompress will have to adjust it one top of the formats like you're saying.

Finally made a PR for this #238