munki / munki-pkg

Repo for the munkipkg tool and example projects
Other
344 stars 72 forks source link

munkipkg --sync error with empty payload directory #57

Open ProjectTermina opened 2 years ago

ProjectTermina commented 2 years ago

I am trying to use the --export-bom-info and --sync workflow described in the munkipkg documentation in order to track pseudo-payload-free munkipkg projects using git. My version of munkipkg is 0.8 and my version of Mac OS is 12.0.1. I have a project with a postinstall script and an empty payload directory. My working directory is the project directory. I run "munkipkg --export-bom-info ." to build the current directory. Output:

pkgbuild: Inferring bundle components from contents of ./payload pkgbuild: Writing new component property list to /var/folders/q2/9hr7dsmj6rbbgm_b3373kxghw9630x/T/tmp3e8Gml/component.plist pkgbuild: Reading components from /var/folders/q2/9hr7dsmj6rbbgm_b3373kxghw9630x/T/tmp3e8Gml/component.plist pkgbuild: Adding top-level postinstall script pkgbuild: Wrote package to ./build/PROJECTNAME-1.0.pkg munkipkg: Extracting bom file from ./build/PROJECTNAME-1.0.pkg munkipkg: Exporting bom info to ./Bom.txt

Bom.txt contains one line:

.\t40755\t0/0\n

Then, I clone the git repo that contains this project. As expected, the cloned project is missing the payload directory. From within the cloned munkipkg project directory, I run "munkipkg --sync ." Output:

munkipkg: Creating ./payload/. with mode 0755 ERROR: [Errno 2] No such file or directory: './payload/.'

The payload directory is not recreated.

On line 392, payload_path is set to "./payload/." When that directory is found to not exist on line 403, line 417 attempts to create it by running "mkdir ./payload/.". This throws an error because the parent directory of payload/., payload, does not exist. It sounds stupid, but it is technically true. This can be fixed by adding the -p flag to the mkdir command, which causes it to create intermediate parent directories as needed. The end result is that ./payload is created, then nothing happens when ./payload/. is created. Success!

ProjectTermina commented 2 years ago

created pull request #58

gregneagle commented 2 years ago

This is interesting but I wonder why you even feel the need to run —sync when there is no payload!

ProjectTermina commented 2 years ago

This section from README.md describes my use case:

If the payload folder exists, but is empty, you'll get a "pseudo-payload-free" package. No files will be installed, but a receipt will be left. This is often the more useful option if you need to track if the package has been installed on machines you manage.

The problem is, because I am using git, which does not track empty directories, when I clone the project it doesn't have a payload directory. No big deal, here is what README.md says to do in this situation:

The solution to this problem is the Bom.txt file, which lists all the files and directories in the package, along with their mode, owner and group.

After doing a git clone or git pull operation, you can then use munkipkg --sync project_name to cause munkipkg to read the Bom.txt file and use the info within to create any missing directories and to set file and directory modes to those recorded in the bom.

I tried to go this route because it is what the readme prescribed, and because hey, it might be useful if this package ever does have a payload. Because the code as is does not do what the documentation says it does in this situation, I submitted this issue and pull request.

Running "mkdir payload" after cloning my projects is also an option. Another nice solution would be if I could specify in the build-info that the project does not have a payload, but should leave a receipt anyway.