Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add KeepFiles config #2115

Open
Winterhuman opened this issue Dec 1, 2023 · 4 comments
Open

Add KeepFiles config #2115

Winterhuman opened this issue Dec 1, 2023 · 4 comments
Labels

Comments

@Winterhuman
Copy link
Contributor

Winterhuman commented Dec 1, 2023

Host OS: Arch Linux
uname: Linux 6.6.3-arch1-1 SMP PREEMPT_DYNAMIC x86_64 GNU/Linux
mkosi: v19

Description

Similar to the KernelModules{Include,Exclude} config options, where "Include" overrides "Exclude", it'd be super useful to have a KeepFiles counterpart to RemoveFiles.

Right now, my mkosi.prepare & mkosi.finalize scripts are mostly taken up by functions similar to the following:

rm_charmaps() {
	printf "Removing unused character encodings...\n"	# Trims ~2.7MiB.
	mkdir /usr/share/i18n/charmaps.tmp
	cp /usr/share/i18n/charmaps/UTF-8.gz /usr/share/i18n/charmaps.tmp/

	rm -r /usr/share/i18n/charmaps
	mv /usr/share/i18n/charmaps.tmp -T /usr/share/i18n/charmaps
}

However, it would save a lot of scripting if I could instead do this in my config:

RemoveFiles = /usr/share/i18n/charmaps
KeepFiles = /usr/share/i18n/charmaps/UTF-8.*
@DaanDeMeyer DaanDeMeyer changed the title RFE: Add KeepFiles config Add KeepFiles config Dec 1, 2023
@DaanDeMeyer DaanDeMeyer added the RFE label Dec 1, 2023
@DaanDeMeyer
Copy link
Contributor

I agree this would be useful but I'm not sure if we can implement this efficiently without introducing quite a bit of complexity. I don't see us adding this unless there's a more beefed up version of rm (what we currently use) that supports include/exclude behavior natively.

@Winterhuman
Copy link
Contributor Author

Winterhuman commented Dec 1, 2023

Would using a similar method to the cp2tmp -> rm -> mv as used in that script snippet help? It's the most efficient way I found of doing it, but I don't know how well it'd scale in mkosi.

Another option is rm !(file1.ext|file2.ext|file3.ext) with shopt -s extglob set, though I guess that depends on if bash is used internally by mkosi already. Or, as a probably terrible idea, using chattr -i on the files to keep and then removing the attribute afterwards.

@septatrix
Copy link
Contributor

find supports a -not specifier to invert selections though I am not sure how quick that is. Doing it in pure Python could also be sufficient depending on the complexity of the image/pattern

@Winterhuman
Copy link
Contributor Author

Winterhuman commented Mar 29, 2024

Could taking advantage of snapshots avoid some of the complexity? e.g.

  1. Before RemoveFiles= is applied, take a snapshot of root A as root B.
  2. Apply RemoveFiles= to root A as it does now.
  3. Then, apply KeepFiles= by copying the specified files from root B to root A (and their parents where applicable), and finally, remove root B.

One issue is that this will be slower on hosts without snapshotting, however, that seems to already be the case with mkosi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants