2019-01-03, 23:57
OK, I think I've figured this out. Just documenting my findings for anyone else that is stuck on this.
zip and rar files will (currently) not copy contents with the 'archive://' vfs url. They will copy if you use the 'zip://' or the 'rar://' url
7z/bz2/gzip/xz/etc (all the formats that libarchive supports) will copy if you use the 'archive://' url
The contents of an rar/zip/7z etc will correctly be listed using xbmcvfs.listdir using 'archive://' regardless of the format. The builtin xbmc.extract does not work with 'archive://', only 'zip://' and 'rar://'
@spiff
I'm not sure if this is the expected behavior? I'd think extraction/copying would work on zip/rar files with libarchive since it also supports zip and rar.
Edit: One thing I still cannot get to work is extracting / copying data a folder or file in a folder in a libarchive supported file. xbmcvfs.copy will generate a file for a folder, but it's an invalid file. Is there a valid method for extracting all files/folders within a libarchive supported file?
Test code:
zip and rar files will (currently) not copy contents with the 'archive://' vfs url. They will copy if you use the 'zip://' or the 'rar://' url
7z/bz2/gzip/xz/etc (all the formats that libarchive supports) will copy if you use the 'archive://' url
The contents of an rar/zip/7z etc will correctly be listed using xbmcvfs.listdir using 'archive://' regardless of the format. The builtin xbmc.extract does not work with 'archive://', only 'zip://' and 'rar://'
@spiff
I'm not sure if this is the expected behavior? I'd think extraction/copying would work on zip/rar files with libarchive since it also supports zip and rar.
Edit: One thing I still cannot get to work is extracting / copying data a folder or file in a folder in a libarchive supported file. xbmcvfs.copy will generate a file for a folder, but it's an invalid file. Is there a valid method for extracting all files/folders within a libarchive supported file?
Test code:
Returns:python:
print('libarchive test')
import os
from urllib import quote_plus as url_quote
from kodi_six import xbmc, xbmcaddon, xbmcplugin, xbmcgui, xbmcvfs
directory_from = '/Users/xxx/Downloads/1941.zip'
directory_to = '/Users/xxx/Downloads/test/'
path = url_quote(directory_from)
print('Archive file test')
(dirs, files) = xbmcvfs.listdir('archive://%s' % (path))
print('Dirs and files')
print(dirs)
print(files)
src = os.path.join('archive://%s' % (path),files[0])
print(xbmcvfs.exists(src))
dest = os.path.join(directory_to,files[0])
print('Test copy from archive %s to %s' %(src, dest))
success = xbmcvfs.copy(src, dest)
print(success)
print('Copied file exists test from archive')
print(xbmcvfs.exists(dest))
print('Zip file test')
(dirs, files) = xbmcvfs.listdir('zip://%s' % (path))
print('Dirs and files')
print(dirs)
print(files)
src = os.path.join('zip://%s' % (path),files[0])
print(xbmcvfs.exists(src))
dest = os.path.join(directory_to,files[0])
print('Test copy from zip %s to %s' %(src, dest))
success = xbmcvfs.copy(src, dest)
print(success)
print('Copied file exists test from zip')
print(xbmcvfs.exists(dest))
print('Done.')
xml:
13:42:32.338 T:123145461903360 DEBUG: libarchive test
13:42:32.419 T:123145461903360 DEBUG: Archive file test
13:42:32.428 T:123145461903360 DEBUG: Dirs and files
13:42:32.428 T:123145461903360 DEBUG:
13:42:32.429 T:123145461903360 DEBUG: ['41_09.rom', '41_18.rom', '41_19.rom', '41_32.rom', '41_gfx1.rom', '41_gfx3.rom', '41_gfx5.rom', '41_gfx7.rom', '41e_30.rom', '41e_31.rom', '41e_35.rom', '41e_36.rom']
13:42:32.429 T:123145461903360 DEBUG: 0
13:42:32.429 T:123145461903360 DEBUG: Test copy from archive archive://%2FUsers%2Fxxx%2FDownloads%2F1941.zip/41_09.rom to /Users/xxx/Downloads/test/41_09.rom
13:42:32.430 T:123145461903360 DEBUG: 0
13:42:32.430 T:123145461903360 DEBUG: Copied file exists test from archive
13:42:32.430 T:123145461903360 DEBUG: 0
13:42:32.430 T:123145461903360 DEBUG: Zip file test
13:42:32.432 T:123145461903360 DEBUG: Dirs and files
13:42:32.433 T:123145461903360 DEBUG:
13:42:32.433 T:123145461903360 DEBUG: ['41_09.rom', '41_18.rom', '41_19.rom', '41_32.rom', '41_gfx1.rom', '41_gfx3.rom', '41_gfx5.rom', '41_gfx7.rom', '41e_30.rom', '41e_31.rom', '41e_35.rom', '41e_36.rom']
13:42:32.433 T:123145461903360 DEBUG: 1
13:42:32.434 T:123145461903360 DEBUG: Test copy from zip zip://%2FUsers%2Fxxx%2FDownloads%2F1941.zip/41_09.rom to /Users/xxx/Downloads/test/41_09.rom
13:42:32.437 T:123145461903360 DEBUG: 1
13:42:32.438 T:123145461903360 DEBUG: Copied file exists test from zip
13:42:32.438 T:123145461903360 DEBUG: 1
13:42:32.438 T:123145461903360 DEBUG: Done.