pengutronix / genimage

tool to generate multiple filesystem and flash images from a tree
GNU General Public License v2.0
298 stars 107 forks source link

Temporary images cause tmppath to remain #237

Closed detly closed 4 months ago

detly commented 5 months ago

Given this config:

image usb.img {
    hdimage {
        partition-table-type = gpt
    }
    partition root {
        image = "root.img"
    }
}

image root.img {
    size = "64M"
    temporary = true
    vfat {
        files = {
            "readme.md"
        }
    }
}

...if I run genimage --config usb.cfg then the following files are generated:

images/usb.img
root/ # empty
tmp/root.img
tmp/root/ # empty

If I then try to run genimage a second time, I get this output:

$ genimage --config usb.cfg
ERROR: tmppath '/home/jason/Code/[project paths]/tmp' exists and is not empty

I can understand the competing goals to (a) leave temporary artefacts around for debugging after running, but also (b) not delete stuff that might be important by default at startup. But it makes it annoying to integrate with other tools if there's this extra cleanup logic that's only needed sometimes. So if it is deliberate and not just an oversight, I'd suggest a flag to control this eg. --cleanup or its opposite --leave-tmp, or something like that.

michaelolbrich commented 5 months ago

I cannot reproduce this here. genimage should delete the content of .../tmp at the end.

What's the output of the first genimage run? It should end with something like this:

INFO: cmd: "rm -rf "/home/jason/Code/[project paths]/tmp"/*" (stderr):
detly commented 5 months ago

Here's the full output from a more minimal project:

genimage-test ⚬ genimage --config usb.cfg 
INFO: cmd: "mkdir -p "/home/jason/Code/genimage-test/tmp"" (stderr):
INFO: cmd: "rm -rf "/home/jason/Code/genimage-test/tmp"/*" (stderr):
INFO: cmd: "mkdir -p "/home/jason/Code/genimage-test/tmp"" (stderr):
INFO: cmd: "cp -a "/home/jason/Code/genimage-test/root" "/home/jason/Code/genimage-test/tmp/root"" (stderr):
INFO: cmd: "mkdir -p "/home/jason/Code/genimage-test/images"" (stderr):
INFO: vfat(root.img): cmd: "mkdosfs   '/home/jason/Code/genimage-test/tmp/root.img'" (stderr):
INFO: vfat(root.img): adding file 'readme.md' as 'readme.md' ...
INFO: vfat(root.img): cmd: "MTOOLS_SKIP_CHECK=1 mcopy -sp -i '/home/jason/Code/genimage-test/tmp/root.img' '/home/jason/Code/genimage-test/input/readme.md' '::'" (stderr):
INFO: hdimage(usb.img): adding partition 'root' (in MBR) from 'root.img' ...
INFO: hdimage(usb.img): adding partition '[MBR]' ...
INFO: hdimage(usb.img): adding partition '[GPT header]' ...
INFO: hdimage(usb.img): adding partition '[GPT array]' ...
INFO: hdimage(usb.img): adding partition '[GPT backup]' ...
INFO: hdimage(usb.img): writing GPT
INFO: hdimage(usb.img): writing protective MBR
INFO: hdimage(usb.img): writing MBR
genimage-test ⚬ ls -sR
.:
total 20
4 images  4 input  4 root  4 tmp  4 usb.cfg

./images:
total 188
188 usb.img

./input:
total 0
0 readme.md

./root:
total 0

./tmp:
total 152
  4 root  148 root.img

./tmp/root:
total 0
genimage-test ⚬ genimage --config usb.cfg
ERROR: tmppath '/home/jason/Code/genimage-test/tmp' exists and is not empty
michaelolbrich commented 5 months ago

Ah, in my test, tmppath already existed and in that case, the content was removed as expected. Try #239, that should fix this.

detly commented 4 months ago

Yep, that works!