pycdlib icon indicating copy to clipboard operation
pycdlib copied to clipboard

function add_file does not work with ISO file ubuntu-20.04.1-desktop-amd64.iso

Open ZouYuhua opened this issue 1 year ago • 2 comments

function "add_file" does not work with some kind of ISO file such as ubuntu-20.04.1-desktop-amd64.iso and ubuntu-20.04.5-desktop-amd64.iso (Rock Ridge ISO)

1. I write a python script to modify ISO using package pycdlib. Following the debug info, I find "add_file" does not work for the ISO ubuntu-20.04.1-desktop-amd64.iso and ubuntu-20.04.5-desktop-amd64.iso. The function "add_file" does not throw exception.

Piece of code as follows:

def iso_add_file(module, opened_iso, iso_type, src_file, dest_file):
    dest_file = dest_file.strip()
    if dest_file[0] != "/":
        dest_file = "/%s" % dest_file

    file_local = src_file.strip()

    file_dir = os.path.dirname(dest_file).strip()
    file_name = os.path.basename(dest_file)
    if '.' not in file_name:
        file_in_iso_path = dest_file.upper() + '.;1'
    else:
        file_in_iso_path = dest_file.upper() + ';1'

    if file_dir and file_dir != "/":
        iso_add_dirs(module, opened_iso, iso_type, file_dir)

    try:
        if iso_type == "iso9660":
            opened_iso.add_file(file_local, iso_path=file_in_iso_path)
        elif iso_type == "rr":
            # For ISO with Rock Ridge 1.09 / 1.10, it won't overwrite the existing file
            # So we take workaround here: delete the existing file and then add file
            if iso_check_file_exists(opened_iso, dest_file):
                opened_iso.rm_file(iso_path=file_in_iso_path)
            opened_iso.add_file(file_local, iso_path=file_in_iso_path, rr_name=file_name)      -------> add_file does not work
        elif iso_type == "joliet":
            opened_iso.add_file(file_local, iso_path=file_in_iso_path, joliet_path=dest_file)
        elif iso_type == "udf":
            # For ISO with UDF, it won't always succeed to overwrite the existing file
            # So we take workaround here: delete the existing file and then add file
            if iso_check_file_exists(opened_iso, dest_file):
                opened_iso.rm_file(udf_path=dest_file)
            opened_iso.add_file(file_local, iso_path=file_in_iso_path, udf_path=dest_file)
    except Exception as err:
        msg = "Failed to add local file %s to ISO with error: %s" % (file_local, to_native(err))
        module.fail_json(msg=msg)

2. I use the tools pycdlib-explorer to add a file to ISO ubuntu-20.04.1-desktop-amd64.iso and it does not work too. zouy@zouy-a02 ~ % /usr/local/bin/pycdlib-explorer Usage: /usr/local/bin/pycdlib-explorer zouy@zouy-a02 ~ % zouy@zouy-a02 ~ % /usr/local/bin/pycdlib-explorer ~/Documents/ubuntu-20.04.1-desktop-amd64.iso (pycdlib) add_file /TEST01.CFG;1 /Users/zouy/Documents/test01.cfg rr_name=test01.cfg (pycdlib) write /Users/zouy/Documents/ubuntu-20.04.1-desktop-amd64-new.iso (pycdlib) exit

Env: zouy@zouy-a02 ~ % pip3 list pycdlib Package Version pip 22.2.2 pycdlib 1.13.0 PyYAML 6.0 setuptools 63.4.3 six 1.16.0 wheel 0.37.1 zouy@zouy-a02 ~ % python3 --version Python 3.10.6

Would some one please help me with it ? Thanks very much.

ZouYuhua avatar Sep 30 '22 11:09 ZouYuhua

So I just tried out number 2 here, where you used pycdlib-explorer to add a file and then write out the ISO. It worked totally fine for me here; it added the file, it wrote it out, and then I could see the file in the resulting ISO.

When you say "it doesn't work", what does that mean? How did you check whether the file existed?

clalancette avatar Oct 01 '22 04:10 clalancette

So I just tried out number 2 here, where you used pycdlib-explorer to add a file and then write out the ISO. It worked totally fine for me here; it added the file, it wrote it out, and then I could see the file in the resulting ISO.

When you say "it doesn't work", what does that mean? How did you check whether the file existed?

Sorry for the delayed reply due to Chinese National holidays.

Try number 2 in my Mac: zouy@zouy-a02 ~ % /usr/local/bin/pycdlib-explorer ~/Documents/ubuntu-20.04.5-desktop-amd64.iso (pycdlib) add_file /TEST01.CFG;1 /Users/zouy/Documents/test01.cfg rr_name=test01.cfg (pycdlib) add_file /GRUB.CFG;1 /Users/zouy/Documents/grub.cfg rr_name=grub.cfg (pycdlib) write /Users/zouy/Documents/ubuntu-20.04.5-desktop-amd64-new.iso (pycdlib) exit

when extract /Users/zouy/Documents/ubuntu-20.04.5-desktop-amd64-new.iso, The files test01.cfg and grub.cfg are not found. I suspect API "add_file" does not work for some kind of ISO files or in some python version.

extract_iso

zouy@zouy-a02 ~ % ls -al /Users/zouy/Documents/ total 20562064 drwx------+ 26 zouy staff 832 Oct 13 10:11 . drwxr-xr-x+ 25 zouy staff 800 Oct 13 10:11 .. -rw-r--r--@ 1 zouy staff 8196 Oct 13 10:09 .DS_Store drwxr-xr-x@ 6 zouy staff 192 Oct 13 09:35 .beacon -rw-r--r-- 1 zouy staff 0 Sep 28 14:15 .localized -rw-r--r--@ 1 zouy staff 961 Sep 29 17:56 grub.cfg -rw-r--r-- 1 zouy staff 4 Sep 30 11:00 test01.cfg -rwx---rw-@ 1 zouy staff 2785017856 Aug 10 2020 ubuntu-20.04.1-desktop-amd64.iso -rw-r--r-- 1 zouy staff 3867139584 Oct 13 10:11 ubuntu-20.04.5-desktop-amd64-new.iso -rwx---rw-@ 1 zouy staff 3864182784 Sep 2 11:25 ubuntu-20.04.5-desktop-amd64.iso -rw-rw-rw-@ 1 zouy staff 2136 Jul 18 20:18 ubuntu.seed

Env: zouy@zouy-a02 ~ % pip3 list pycdlib Package Version pip 22.2.2 pycdlib 1.13.0 PyYAML 6.0 setuptools 63.4.3 six 1.16.0 wheel 0.37.1 zouy@zouy-a02 ~ % python3 --version Python 3.10.6

Best regards Yuhua Zou

ZouYuhua avatar Oct 13 '22 02:10 ZouYuhua