kdomanski / iso9660

A go library for reading and creating ISO9660 images
BSD 2-Clause "Simplified" License
265 stars 43 forks source link

invalid argument error when trying to extract ISO to directory #47

Open smahm006 opened 1 year ago

smahm006 commented 1 year ago

I am trying to extract a ubuntu iso image (from https://releases.ubuntu.com/22.04/) to a temporary folder. Below is the code I am using

func ExtractISO() error {
    temp, err := os.MkdirTemp("temp", "ubuntu-")
    if err != nil {
        return fmt.Errorf("creating temp dir: %s", err)
    }
    iso_file, err := os.Open("ubuntu-22.04.3-live-server-amd64.iso")
    if err != nil {
        return fmt.Errorf("opening iso file: %s", err)
    }
    defer iso_file.Close()
    if err = util.ExtractImageToDirectory(iso_file, temp); err != nil {
        return fmt.Errorf("extracting image: %s", err)
    }
    return nil
}

I am getting hit with an error extracting image: open temp/ubuntu-4020240902/boot/grub/i386-pc/zstd.mod: invalid argument

I am not sure what the reason is, maybe the - in i386-pc?

EDIT: I just realized this might also be a permissions issue

FNDenisovna commented 3 months ago

i have analogous problem :(

boot/grub/i386-efi/xnu.mod: invalid argument

smahm006 commented 3 months ago

I just ended up using os.Exec to call xorriso

func extractISOToDirectory(filename string, source string, destination string) error {
    xorriso_args := fmt.Sprintf("-osirrox on -indev %s/%s -extract / %s", source, filename, destination)
    cmd := exec.Command("xorriso", strings.Split(xorriso_args, " ")...)
    err := cmd.Run()
    if err != nil {
        return fmt.Errorf("xorriso error: %s", err)
    }
    err = filepath.Walk(destination, func(path string, info os.FileInfo, err error) error {
        if err != nil {
            return err
        }
        return os.Chmod(path, os.FileMode(0755))
    })
    if err != nil {
        return fmt.Errorf("setting directory permissions: %s", err)
    }
    return nil
}
FNDenisovna commented 3 months ago

thank you! i was just thinking this way :)